I want to build a Wireless Sensor Network with a XB24-B Series 2 XBee connected to Arduino Mega 2560 acting as a Coordinator and three XB24-B Series 2 XBees connected to three Arduino Uno boards respectively, acting as End Devices. To each Uno board at end is connected a temperature sensor. I have configured my XBees using X-CTU in the following ways:
Coordinator Xbee (ZNET2.5 COORDINATOR API) ->
PAN ID = 200
DH=0
Dl=0
NI=COORD
AP=2
End node_0 Xbee (ZNET2.5 ROUTER/END DEVICE API) ->
PAN ID =200
DH=0013A200 (High byte of Coordinator)
DL= 4060647B (Low byte of Coordinator)
JV = 1
NI = R1
AP=2
My Coordinator side Sketch is as follows :-
XBee xbee = XBee();
ZBRxResponse zbRx = ZBRxResponse();
uint8_t payload[5] = {0,0,0,0,0}; //initialises the data array with 0s
void setup(){
delay(1000);
xbee.setSerial(Serial3);
xbee.begin(9600);
Serial.begin(9600);
Serial.println("Ready");
}
void loop(){
xbee.readPacket();
if(xbee.getResponse().isAvailable()){
if(xbee.getResponse().getApiId() == ZB_RX_RESPONSE){
xbee.getResponse().getZBRxResponse(zbRx);
for(int i = 0; i < zbRx.getDataLength(); i++){
payload [i] = zbRx.getData(i);
}
uint8_t analogHi = payload[0];
uint8_t analogLo = payload[1];
int value = analogLo + (analogHi*256);
int A = value;
int C = payload[3];
int E = payload[4];
int flag = payload[2];
if(E == 0){
Serial.print("BOARD IDENTIFIER -> ");
Serial.println(E);
Serial.print("Temperature ");
Serial.println(A);
if (flag == 0){
Serial.print("-");
Serial.println(C);
}
else{
Serial.println(C);
}
}
else if (E == 1){
Serial.print("BOARD IDENTIFIER -> ");
Serial.println(E);
Serial.print("Temperature " );
Serial.println(A);
if (flag == 0){
Serial.print("-");
Serial.println(C);
}
else{
Serial.println(C);
}
}
else{
Serial.println("ERROR IDENTIFYING BOARD");
}
delay(1000);
}
}
// Serial.println("Inside loop");
//delay(1000);
}
My Router Side Sketch is as follows :-
uint8_t payload[5] = {0,0,0,0,0};
XBee xbee = XBee();
XBeeAddress64 remoteAddress = XBeeAddress64(0x0013A200 ,0x4060647B);
ZBTxRequest zbTx = ZBTxRequest(remoteAddress,payload,sizeof(payload));
int tempPin =0; //Analog pin 0
int ledPin = 13;
int tempReading;
int flag;
int ID =0; //change this accordingly to you node
void setup(){
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
pinMode(tempPin,OUTPUT);
analogReference(INTERNAL);
}
void loop(){
tempReading = analogRead(tempPin);
Serial.println(tempReading);
int celcius = getTemp(tempReading);
Serial.print("Temperature in celcius");
Serial.println(celcius);
delay(100);
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
delay(1000);
payload[0] = tempReading >> 8 & 0xff;
payload[1] = tempReading & 0xff;
if(celcius<0){
flag=0;
}
else{
flag=1;
}
payload[2] = flag;
payload[3] = celcius;
payload [4] = ID;
xbee.send(zbTx);
delay(60000);
}
float getTemp(float k){
k = (k * 110)/1024.0;
float celcius = k;
return celcius;
}
I have connected the Dout of XBee coordinator to Rx3 of Mega and Din of XBee coordinator to Tx3 of Mega
.
Now , when I open serial terminals in both the sides I could see nothing on the Coordinator Side serial window , except ready which I have printed statically.However, I could see the temperature readings being printed on the serial terminal on the end device side followed by a frame of random numbers.
Can anybody tell me where have I gone wrong? I am eagerly waiting for your advices.


