Hi.
I am trying to build a mesh network and therefore all of my Xbee devices are in API mode (I believe that is the way it is done if I want to build a mesh network, correct me if I am wrong). For now I am just testing communication and I am using just 2 devices: a coordinator and a router (the network will have more routers and end devices later). Both Xbee's (and every Xbee I add to the network later) will be attached to an Arduino unit. The Arduino will generate some values and send them to the coordinator, so no sensors will be used because I am just trying to implement a communication protocol in the network. The Xbee.h library is used in all Arduino sketches. At this moment, I am trying to establish communication between the coordinator and the router, but without success. I am new to Xbee and Arduino and I am trying to establish a communication between them for the last few days without any success. I am not sure if my X-CTU configuration is wrong or if my code is not OK. In my current scenario (it is used only to check if communication works), the coordinator sends some data to the router and the router will print it on the serial monitor. Both of my devices are attached to my laptop via USB cabels (I am not sure if this can cause a problem). My code and configuration is the following:
Tansmitter - coordinator code
#include <XBee.h>
XBee xbee = XBee();
void setup() {
Serial.begin(9600);
xbee.setSerial(Serial);
}
void loop() {
Serial.println("\n Transmitting");
uint8_t data[] = {'H','e','l','l','o'};
XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x409BB998);
// addr64.setMsb(0x0013A200);//XXXXX -> Msb address of router/end node
// addr64.setLsb(0x409BB998);//XXXXX -> Lsb address of router/end node
ZBTxRequest zbTx = ZBTxRequest(addr64, data, sizeof(data));
xbee.send(zbTx);
delay(1000);
}
Receiver - router code
#include <XBee.h>
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();
void setup() {
Serial.begin(9600);
xbee.begin(Serial);
}
void loop() {
Serial.println("receiving");
String sample;
xbee.readPacket();
if (xbee.getResponse().isAvailable()) {
Serial.println(xbee.getResponse().getApiId());
if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
xbee.getResponse().getZBRxResponse(rx);
for (int i = 0; i < rx.getDataLength(); i++) {
sample += (char)rx.getData(i);
}
Serial.println(sample);
}
else
{
Serial.println("something else");
}
}else if (xbee.getResponse().isError()) {
Serial.println("Error reading packet. Error code: ");
Serial.println(xbee.getResponse().getErrorCode());
}
delay(2000);
}
Coordinator configuration:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<profile>
<description_file>XB24-ZB_21A7.xml</description_file>
<settings>
<setting command="ID">1234</setting>
<setting command="SC">FFFF</setting>
<setting command="SD">3</setting>
<setting command="ZS">0</setting>
<setting command="NJ">FF</setting>
<setting command="DH">0</setting>
<setting command="DL">FFFF</setting>
<setting command="NI">Coordinator</setting>
<setting command="NH">1E</setting>
<setting command="BH">0</setting>
<setting command="AR">FF</setting>
<setting command="DD">30000</setting>
<setting command="NT">3C</setting>
<setting command="NO">3</setting>
<setting command="CR">3</setting>
<setting command="PL">4</setting>
<setting command="PM">1</setting>
<setting command="EE">0</setting>
<setting command="EO">0</setting>
<setting command="KY"></setting>
<setting command="NK"></setting>
<setting command="BD">3</setting>
<setting command="NB">0</setting>
<setting command="SB">0</setting>
<setting command="D7">1</setting>
<setting command="D6">0</setting>
<setting command="AP">2</setting>
<setting command="AO">0</setting>
<setting command="SP">20</setting>
<setting command="SN">1</setting>
<setting command="D0">1</setting>
<setting command="D1">0</setting>
<setting command="D2">0</setting>
<setting command="D3">0</setting>
<setting command="D4">0</setting>
<setting command="D5">1</setting>
<setting command="P0">1</setting>
<setting command="P1">0</setting>
<setting command="P2">0</setting>
<setting command="PR">1FFF</setting>
<setting command="LT">0</setting>
<setting command="RP">28</setting>
<setting command="DO">1</setting>
<setting command="IR">0</setting>
<setting command="IC">0</setting>
<setting command="V+">0</setting>
</settings>
</profile>
</data>
Router configuration
<?xml version="1.0" encoding="UTF-8"?>
<data>
<profile>
<description_file>XB24-ZB_23A7.xml</description_file>
<settings>
<setting command="ID">1234</setting>
<setting command="SC">FFFF</setting>
<setting command="SD">3</setting>
<setting command="ZS">0</setting>
<setting command="NJ">FF</setting>
<setting command="NW">0</setting>
<setting command="JV">0</setting>
<setting command="JN">0</setting>
<setting command="DH">0</setting>
<setting command="DL">0</setting>
<setting command="NI">Router1</setting>
<setting command="NH">1E</setting>
<setting command="BH">0</setting>
<setting command="AR">FF</setting>
<setting command="DD">30000</setting>
<setting command="NT">3C</setting>
<setting command="NO">3</setting>
<setting command="CR">3</setting>
<setting command="PL">4</setting>
<setting command="PM">1</setting>
<setting command="EE">0</setting>
<setting command="EO">0</setting>
<setting command="KY"></setting>
<setting command="BD">3</setting>
<setting command="NB">0</setting>
<setting command="SB">0</setting>
<setting command="D7">1</setting>
<setting command="D6">0</setting>
<setting command="AP">2</setting>
<setting command="AO">0</setting>
<setting command="SM">0</setting>
<setting command="SN">1</setting>
<setting command="SO">0</setting>
<setting command="SP">20</setting>
<setting command="ST">1388</setting>
<setting command="PO">0</setting>
<setting command="D0">1</setting>
<setting command="D1">0</setting>
<setting command="D2">0</setting>
<setting command="D3">0</setting>
<setting command="D4">0</setting>
<setting command="D5">1</setting>
<setting command="P0">1</setting>
<setting command="P1">0</setting>
<setting command="P2">0</setting>
<setting command="PR">1FFF</setting>
<setting command="LT">0</setting>
<setting command="RP">28</setting>
<setting command="DO">1</setting>
<setting command="IR">0</setting>
<setting command="IC">0</setting>
<setting command="V+">0</setting>
</settings>
</profile>
</data>
I am not sure if this is important or not, but when I attach my xbee+arduino router to my laptop, it does not print anything alhought there is a Serial.println command at the beginning of every loop iteration in the uploaded sketch. I have to upload my sketch every time if I want it to work. I don't have that problem with my coordinator.
Any suggestion or help will be appreciated.
Thanks in forward.