SparkFun Forums 

Where electronics enthusiasts find answers.

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!
By Okha
#166183
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");
}
}
Last edited by Okha on Mon Dec 09, 2013 10:09 am, edited 2 times in total.
By waltr
#166204
You can transfer any 8bit data through an XBee pair but not at a very high data rate.

Start this project by connecting the arduino to the PC (using a proper RS232 level translator or Serial to USB adapter) and get code working to send data to the PC. Start with just ASCII text and a terminal program on the PC (Hyperterm or other).
Once this works correctly the project splits into two parts:
1- With the above direct connection get the code to read the camera then send it to the PC.
2- With the simple sending ASCII data, insert the XBee's between the arduino and the PC. The data should come across to the PC exactly like it did with the direct connection.
3- Once # 2 ans #1 work properly combine hardware and software to have the camera data sent to the PC over the XBees.

Read the thread on setting up XBees in the forum here (hint: the RF sub-forum would have the info) and do web search to find a few of the tutorials on setting up and using XBees in Transparent mode.
By Okha
#166282
Thank you waltr,
but i planned to manually send the image. i dont no if this is possible, like storing the image on the arduino and send a command to the router to send to the cordinator?
By waltr
#166283
Right, Start without the XBees and learn how to capture and send the image to the PC from the arduino.
I broke down the learning steps in my post above.
I believe I have seen web references to doing this with the arduino but you need to search and find these (I don't use arduino). One place to check in Adafruit and, of course SparkFun, for more info.
By stevech
#166320
XBee in transparent serial mode will of course transfer whatever it is given as serial (UART) data. At up to net yield of about 40Kbits/sec.
Sending motion video on any serial line is too difficult with humble embedded processors. Doable but hard on a pair of PCs.. usually take IP and setup the IP on serial protocol standard 'slip' on each computer.

PC to an embedded Linux system via ethernet is far simpler... like using a Raspberry Pi for one end. Or do this with a $8 WiFi adapter plugged into the RPi
By waltr
#166350
I'll need some time to dig into the Xbees docs to follow what you are doing.
In the mean time what comes to mind is that the Router did not re-join the network after being powered off. You can try just cycling power on the Router without moving it to see if this causes the problem.
Try asserting a Network Associate on the Router. This is a pin on the XBee that is taken either low or high.
Also, do an ND command from the coordinator to see if the Router is present in the network.
User avatar
By Ross Robotics
#166353
Please use code tags when posted code. It is very difficult to read.