Hello guys, I would like to ask for advice on how to code my microcontroller (nodeMCU esp-12) to turn ON/OFF digital pins of the remote router devices using a single coordinator device.
I have followed this guide and I was able to test it with 1 coordinator and 1 router. Now I would like to add another router device to the network. I was not able to find enough information on how to do that. Any help is appreciated
/code by tunnelsup
//youtube tutorial: https://www.youtube.com/watch?v=CzH146rR-7I
//toggles local LED and remote XBee LED on and off
int led = 13;
void setup(){
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop(){
digitalWrite(led, HIGH);
setRemoteState(0x5);
delay(5000);
digitalWrite(led, LOW);
setRemoteState(0x4);
delay(5000);
}
void setRemoteState (char value){
Serial.write(0x7E); //start byte
Serial.write((byte)0x0); //high part of length (always zero)
Serial.write(0x10); //low part of length
Serial.write(0x17); //0x17 is remote AT command
Serial.write((byte)0x0); //frame ID set to zero for no reply
//ID of recipient, or use 0xFFFF for broadcast
Serial.write((byte)0x0);
Serial.write((byte)0x0);
Serial.write((byte)0x0);
Serial.write((byte)0x0);
Serial.write((byte)0x0);
Serial.write((byte)0x0);
Serial.write(0xFF);
Serial.write(0xFF);
//16 bit of recipient of 0xFFFE
Serial.write(0xFF);
Serial.write(0xFE);
Serial.write(0x02);
Serial.write('D');
Serial.write('4');
//command data in as many bytes
Serial.write(value);
//checksum
long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '4' + value;
Serial.write(0xFF - (sum & 0xFF));
}