I have two Arduinos both with an Xbee on it. One as Coordinator and one as Router. The Router sends states of switches to the Coordinator.
On start up i will send the initial states of my switches to the Coordinator. But the state isn't connected and my initial states goes lost.
What is the best way to check when the connection is ok and then send the initial data?
My test code:
#define switchPin 2
int oldVal = 0;
void setup() {
Serial.begin(9600);
pinMode(switchPin,INPUT_PULLUP);
// Initial state
Serial.write(digitalRead(switchPin));
}
void loop() {
int val = digitalRead(switchPin);
if (val != oldVal) {
Serial.write(val);
oldVal = val;
}
}
You could have the coordinator send a request to the router to have it re-send the current state.
You could have the router send current state every minute, regardless of whether there have been changes or not.
You could use the XBee radio modules in API mode and check the ATAI
setting to see if the router is associated to a network.