Hello,
I want to get sensor data from a remote xbee by using an IS (forced sample) api command. The rcvr (xbee1) is connected to an arduino mega. The xmtr is xbee2 (sensors) Try as I might, and reading Jon Titus’ book on xbees, I’ve had no luck. My goal is to force a sample transmission with the IS command. Take this data and parse it out for the sensor bytes. My ultimate goal is to have 4 independent xbees sending sensor data to the receiving xbee attached to the arduino. Can you please help me? Here is my code.
/* If there is no data in the reciever buffer an "H" prints out. I can't seem to get data into
the buffer as the result of this program is a printing of the "H".
Materials: 2 xbee series 1 in API mode, factory settings. Do--D3 are activated on xbee2 (sensors are here)
1 arduino mega. Mega Serial 0 Tx connected to xbee1 Din
Rx connected to xbee1 Dout
1 logic level converter bi directional 3.3 to 5 volts between xbee1 and mega
*/
byte IScmd[] = {0x7E,0x00,0x0F,0x17,0x53,0x00,0x13,0xA2,0x00, //API command byte, from the mega to Xbee1 then transmitted to xbee2, I S (49,53) equals forced sample
0x40,0x81,0x82,0x0D,0xFF,0xFE,0x02,0x49,0x53,0xF5};
byte Rcvd[27]; // array; data received from xbee2. Using D0,D1,D2,D3 on xbee2
void setup()
{
Serial.begin(9600); //using arduino mega to avoid any serial write/read conflicts
Serial1.begin(9600);
}
void loop()
{
for(int x = 0; x < 19; x++) //sends the command byte from mega to xbee#1 which transmits to xbee#2
{
Serial.write(IScmd[x]);
delay(1);
}
while(Serial.available() == 0) //program stops here if nothing in buffer.
{
Serial.print("H"); //lets me know nothing is there yet.
Serial.println();
delay(100);
}
if(Serial.available() >= 20) //data is in the buffer and waits until a mouthful of data in the buffer to read
{
if(Serial.read() == 0x7E)
{
for(int n=1; n< 27; n++) // reads the bytes from Xbee#2 into the array Rcvd
{
Rcvd[n] = Serial.read();
delay(1);
}
}
}
for(int i = 1; i<27; i++)
{
Serial1.print(Rcvd [i],HEX); //prints the bytes from Rcvd array
Serial1.println();
delay(50);
}
delay(500);
}