I am currently working on a project with xbee pro with arduino and the xbee shield, the xbee doggle with an xbee pro is also connected to the computer . I want to use it to transfer JPEG images across a mesh network. How do i go about this or any other useful idea as i am quite new to this area. Also if there is anybody with useful code, can help.
Thank you for anticipated help.
For the code below, i tried to create a wireless mesh network using Arduino devices and XBee radios. Basically, i am trying to make a more efficient routing algorithm that will allow the data to be sent at a quicker rate and eliminate confusion between the devices that are being sent…right now i am stuck with a problem that does not make any sense to me at all.
i am trying to send data from a router in API mode to a Coordinator in API mode. When i first upload this code it works automatically, and there are no problems for the coordinator to receive the RSSI transmit; however, the problem is when i try to unplug the arduino to test the RSSI transmit at a different location, and i plug the arduino back in with the XBee still attached of course. The program of the coordinator and router are still running properly, but the code no longer says success like it did before the Router was unplugged. Instead, it gives me an error message, which means that the transmitting failed. I checked the API mode before and after the Arduino with the command xbee.getResponse.getApiId() at the coordinator, and i received 0x90 when the router had just had the code uploaded to it, which of course is what it should be, and it was 0x95 when the arduino was unplugged and plugged back in. Quite honestly i don’t know if this is an anomaly or if it is the reason why the two XBee’s are not communicating. If it is possible that the settings are wrong on X-CTU, i don’t know what to fix either. I seriously need some help with this project and would be grateful for any assistance on this project. I NEEDED TO TEST THIS FIRST, BEFORE WORKING ON THE CODES TO TRANSMIT IMAGES
Here is my codes for the routers and coordinator
#include <XBee.h>
/*
This example is for Series 2 XBee
Sends a ZB TX request with the value of analogRead(pin5) and checks the status response for success
*/
// create the XBee object
XBee xbee = XBee();
byte to_radio1=0x0000; //used to store which radio we send to
byte to_radio2=0x0000;
uint8_t payload = { ‘H’, ‘i’ };
//uint8_t w_command = {‘W’,‘R’};
//uint8_t h_command = {‘D’,‘H’ };
//uint8_t l_command = { ‘D’,‘L’ };
//uint8_t h_address = { 0,0,1,3,10,2,0,0 };
//uint8_t l_address = {4,0,6,15,14,4,9,2};
// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(to_radio1,to_radio2);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
//AtCommandRequest h_atrequest=AtCommandRequest(h_command,h_address,sizeof(h_address));
//AtCommandRequest l_atrequest=AtCommandRequest(l_command,l_address,sizeof(l_address));
//AtCommandRequest writerequest=AtCommandRequest(w_command);
void setup() {
Serial.begin(115200);
xbee.setSerial(Serial);
Serial.println();
Serial.println(“Setup Finished”);
Serial.println();
}
void loop() {
//zbTx.setAddress64(addr64);
//addr64 = XBeeAddress64(to_radio1,to_radio2);
//zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
//txStatus = ZBTxStatusResponse();
// break down 10-bit reading into two bytes and place in payload
Serial.println(“”);
xbee.send(zbTx);
// flash TX indicator
Serial.println(“”);
Serial.println(“Start”);
// after sending a tx request, we expect a status response
// wait up to half second for the status response
if (xbee.readPacket(500)) {
// got a response!
// should be a znet tx status
if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
xbee.getResponse().getZBTxStatusResponse(txStatus);
// get the delivery status, the fifth byte
if (txStatus.getDeliveryStatus() == SUCCESS) {
// success. time to celebrate
Serial.println(“Success”);
} else {
// the remote XBee did not receive our packet. is it powered on?
Serial.println(“Error1”);
}
}
} else if (xbee.getResponse().isError()) {
Serial.println("Error reading packet. Error code: ");
Serial.println(xbee.getResponse().getErrorCode());
} else {
// local XBee did not provide a timely TX Status Response – should not happen
Serial.println(“Error2”);
}
Serial.println(addr64.getMsb());
Serial.println(addr64.getLsb());
delay(1000);
}
And this is the coordinator’s code that we have been using
#include <XBee.h>
// create the XBee object
XBee xbee = XBee();
int signal_strength;
byte received_rssi;
byte rss();
// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0, 0x0000FFFF);
ZBRxResponse rxStatus = ZBRxResponse();
void setup() {
Serial.begin(115200);
xbee.setSerial(Serial);
}
void loop() {
xbee.readPacket(100);
if (xbee.getResponse().isAvailable()) {
Serial.println(xbee.getResponse().getApiId());
delay(50);
if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
xbee.getResponse().getZBRxResponse(rxStatus);
}
received_rssi = rss();
Serial.print(received_rssi);
}
delay(100);
}
byte rss() {
/* returns received signal strength value for the last RF data packet */
union {byte B; char C;} atCmd[3];
AtCommandRequest atCmdReq;
AtCommandResponse atResp;
byte respLen, *resp, dBm;
strcpy(&atCmd[0].C, “DB”);
atCmdReq = AtCommandRequest(&atCmd[0].B);
atResp = AtCommandResponse();
xbee.send(atCmdReq);
if (xbee.readPacket(5000)) {
if (xbee.getResponse().getApiId() == AT_COMMAND_RESPONSE) {
xbee.getResponse().getAtCommandResponse(atResp);
if (atResp.isOk()) {
respLen = atResp.getValueLength();
if (respLen == 1) {
resp = atResp.getValue();
dBm = resp[0];
return dBm;
}
else {
Serial.println(“Unexpected response”);
}
}
else {
Serial.println(“ERROR”);
}
}
else {
Serial.println(“Unknown response”);
}
}
else {
Serial.println(“No response”);
}
}