hello, i am having issues with the receive code of the coordinator , i am transmitting correctly since i am receiving the data i need when i hook the xbee directly to the pc and open the xctu software , but i can't seem to come up with a good receiving code
#include <Printers.h>
#include <XBee.h>
#include <SoftwareSerial.h>;
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWireA (2) ;
OneWire oneWireB (3) ;
DallasTemperature sensorsA (&oneWireA) ;
DallasTemperature sensorsB (&oneWireB) ;
XBee xbee = XBee();
XBeeAddress64 addr64 = XBeeAddress64(0x00000000, 0xFFFFFFFF);
SoftwareSerial XBee(2,3); // RX, TX
void setup() {
Serial.begin(9600);
Serial.flush();
XBee.begin(9600);
}
void loop() {
sensorsA.requestTemperatures();
int senv= analogRead(A1);
int senv2= analogRead(A0);
delay(1000);
Serial.println(map (senv,1023,310,0,100));
delay(1000);
Serial.println(map (senv2,1023,310,0,100));
delay(1000);
Serial.println(sensorsA.getTempCByIndex(0));
delay(1000);
sensorsB.requestTemperatures();
Serial.println(sensorsB.getTempCByIndex(0));
}
this is the Router code in AT mode , it transmits the data of 2 temperature sensors and 2 moisture sensors .
does anyone know a good receive code ? i really could use the help and thank you .
so here is what i got so far hoping people can help more from here , i tried a lot with the receiver code and i started receiving the hexadecimal code , but when i am trying to separate the bytes i don't need from the data i am getting an error and i am pretty sure it is because of my logic in the while loop i just need the correct substitute , i tried stuff but everything got me in an endless loop, and last thing , what i am doing now is getting the bytes i need but i still want to transform them to ASCII not just one byte at a time , i need to transform all the data that i am keeping together.
So my code is :
#include <Printers.h>
#include <XBee.h>
#include <SoftwareSerial.h>
XBee xbee = XBee();
SoftwareSerial XBee(2,3); // RX, TX
void setup()
{
Serial.begin(9600);
XBee.begin(9600);
}
void loop()
{
if (XBee.available()) {
if (XBee.read() == 0x7E) {
Serial.println("dicarded bytes are : ");
for (int i = 0; i<14; i++) {
byte discard = XBee.read();
Serial.print(discard, HEX);
Serial.print(" .");
}
Serial.println("KEPT bytes are : ");
byte data=XBee.read();
while(data != 0xE5 || data != 0x14 || data != 0xFF || data != 0xB1){
Serial.print(data, HEX);
Serial.println(data);
byte data=XBee.read();
}
}
}
}
and the output is :
dicarded bytes are :
0 .13 .90 .0 .13 .A2 .0 .41 .63 .D6 .55 .FF .FE .C2 .KEPT bytes are :
3250
3250
3250
3250
3250
3250
3250
N.B: i can't specify how many bytes i need in the while loop since i am getting 2 analog data and 2 digital data which makes the length of the HEX sting that is incoming different each time that's why i just put the byte just after my data ends as the exit of the while loop. (don't know if that made sense ).
and it keeps going . So please if anyone has a better form of code or a better way to go around this please help.
I know I've tried to help you on this before, but I finally sat down and read parts of the
manual. Check out pages 42-44 and pages 79-81. They should help a bit.
When in API mode (not to be confused with AT mode - they're different), you are supposed to be sending/receiving more than just data (I think). Are you really using AT mode, or are you using API mode?
Also, take a look at this site. Although it is for the Xbee S2 and not the S2C, it will help you understand how to setup your modules and how to interpret the API message frames.
This will help you parse out the real data more efficiently than the way you're currently doing it.