Good day!
I have been reading "Building Wireless Sensor Networks" by Robert Faludi and I'm stuck on Chapter 5 : Simple Sensor Network. On page 142 of the book the author gave a step by step procedure on how to configure coordinator and router xbees, schematic diagram of the project and a Processing sketch. The project is about monitoring room temperatures. It uses 3 xbees--1 coordinator and 2 routers. The coordinator gets the analog values read by the router xbees and display them in a thermometer like GUI. The problem is that I can't run the Processing sketch. It gives "noclassdeffounderror gnu/io/serialporteventlistener " error. Since I don't know much about Processing I decided to give up on that and finish it off using Arduino.
This are the radio configuration:
Coordinator API
PAN ID 511
API Enable 2
Router AT
PAN ID 511
Channel Verification 1
AD0/DIO0 2
IO Sampling Rate 3E8
At first, I used 3 xbees (Xbee Pro S2B - Zigbee) without controllers. Using the XCTU Software I know the coordinator detects the routers because when I switch from Configuration Working Mode to Network Working Mode and play the Radio Module Network, I can see the 3 xbees connected. But when I exit the XCTU and open the COM PORT of the Coordinator in Arduino, all I get are ASCII characters. I can't display them because I can't copy but it starts with "~" which is an indication of a start byte. That's when I decided to hook it up with an arduino Uno (duh? :.).
I then uploaded this code:
float temp;
void setup(){
 Serial.begin(9600);
}
void loop(){
 if (Serial.available() >= 21){
  if(Serial.read() == 0x7E){  //start byte
   for(int i=1; i<19; i++){
    byte discardByte=Serial.read();
   }
   int analogMSB = Serial.read();
   int analogLSB = Serial.read();Â
   int analogReading = analogLSB + (analogMSB * 256);
  Â
   temp = analogReading / 1023.0 * 1.23;
   temp = temp - 0.5;
   temp = temp / 0.01;
   temp = temp * 9/5 + 32;
  Â
   Serial.print(temp);
   Serial.println(" C");  Â
  }
 }
}
But I can't determine which xbee is sending the temperature so I added an if statement determining the last two bytes of the xbees address (they have the same first six byte).
float temp;
int router;
void setup(){
 Serial.begin(9600);
}
void loop(){
 if (Serial.available() >= 21){
  if(Serial.read() == 0x7E){  Â
   for(int i=1; i<19; i++){
    if(i == 11 && Serial.read() == 0x06){
     router = 1;
     int analogMSB = Serial.read();
     int analogLSB = Serial.read();Â
     int analogReading = analogLSB + (analogMSB * 256);
    Â
     temp = analogReading / 1023.0 * 1.23;
     temp = temp - 0.5;
     temp = temp / 0.01;
     temp = temp * 9/5 + 32;
    Â
     Serial.print("1: ");
     Serial.print(temp);
     Serial.println(" C");
    }
    if(i == 11 && Serial.read() == 0x14){
     router = 2;
     int analogMSB = Serial.read();
     int analogLSB = Serial.read();Â
     int analogReading = analogLSB + (analogMSB * 256);
    Â
     temp = analogReading / 1023.0 * 1.23;
     temp = temp - 0.5;
     temp = temp / 0.01;
     temp = temp * 9/5 + 32;
    Â
     Serial.print("2: ");
     Serial.print(temp);
     Serial.println(" C");
    }
    byte discardByte=Serial.read();
   }     Â
  }
 }
}
Sorry for the "unacceptable" lemon grabs voice code, I'm not good with bytes
I can only display Router 2's temperature. I don't know what's happening with the data from Router 1.
So I checked it using this:
void setup(){
 Serial.begin(9600);
}
void loop(){
 if (Serial.available() >= 21){
  if(Serial.read() == 0x7E){  Â
   for(int i=1; i<19; i++){
    Serial.print(i);
    Serial.print(": ");
   Â
    byte discardByte=Serial.read();
   Â
    Serial.println(discardByte);
   }     Â
  }
 }
}
This is the result:
1: 0
2: 18
3: 146
4: 0
5: 125
6: 51
7: 162
8: 0
9: 64
10: 183
11: 112
12: 20
13: 144
14: 235
15: 1
16: 1
17: 0
18: 0
1: 0
2: 18
3: 146
4: 0
5: 125
6: 51
7: 162
8: 0
9: 64
10: 183
11: 112
12: 6
13: 90
14: 8
15: 1
16: 1
17: 0
18: 0
It has the same values from 1-11 and 15-18 but different from 12-14. I guess this confirms the three xbees are connected since i=12 & i=13 are supposed to be the 16-bit source network address(?)
The question now is, "How can I make sense of the 1-18 values of 'i' so I can determine which xbee is sending this particular data?"