I'm sending 8 bytes through serial e.g 255 0 127 0 255 50 255 255 to the arduino (coordinator)
Each of these bytes is then sent to a corresponding radio (router) attached to an arduino(using the correct TX packet). This then turns on an LED (via PWM, hence 255 value). For some reason the router/arduino only sometimes receives this packet. I've debugged as much as possible and can't make sense. Here is the code concerned from both coordinator and routers.
In the examples im sending two values for debugging (rather than 8 ).
ROUTER :
//INCOMING
while( xbee.available() ){
// ... read the data.
xbee.read();
// If a complete message is available, check the contents
if( xbee.isComplete() ){
if( xbee.isRX() ){
Serial.println(xbee.getRXPayload(0));
ledVal = xbee.getRXPayload(0);
analogWrite(ledPin, ledVal);
}
}
}
delay(2);
//OUTGOING
if(value != newValue || buttonState != newButtonState) {
uint8_t payload[3];
payload[0] = value >>8 & 0xff;
payload[1] = value & 0xff;
payload[2] = buttonVal & 0xff;
xbee.prepareTXRequestToCoordinator( payload, sizeof(payload) );
xbee.send();
printPacket( xbee.getOutgoingPacketObject() );
newButtonState = buttonState;
newValue = value;
}
delay(2); // Small delay for stability
}
COORDINATOR
void loop() {
while( xbee.available() ){
// ... read the data.
xbee.read();
// If a complete message is available, display the contents
if( xbee.isRX() ){
printPacket( xbee.getIncomingPacketObject() );
}
}
while (Serial.available() > 0) {
int maxData[2]={Serial.parseInt(), Serial.parseInt()};
if (Serial.read() == '\n') {
for(int i = 0; i < 2; i++){
if ( maxData[i] != newData[i] ) {
uint8_t payload[1];
payload[0] = maxData[i] & 0xff;
xbee.prepareTXRequest(0x0013A200, devices[i], addr16[i], payload, sizeof(payload));
xbee.send();
// printPacketIn(xbee.getOutgoingPacketObject());
newData[i] = maxData[i];
}
}
}
}
delay(2); // Small delay for stability
// That's it! The coordinator is ready to go.
}
Thank you in advance.