I plan to have several Arduino boards connected to XBee series 2 radios in the same network performing the same operation. They are to transmit data to another board that will upload all of the data at once using a cellular connection. I would like to uniquely identify each board in some way. I realize I can hardcode a serial number into the EEPROM memory of the Arduino board. However that will not scale very well for what I am trying to do. Is there a way to read the XBee's serial number using Arduino code, so that I can transmit it along with my data?
string serialnumber
volatile int IRQcount1;
volatile int IRQcount2;
int pin2 = 2;
int pin3 = 3;
int pin_irq1 = 0; //IRQ that matches to pin 2
int pin_irq2 = 1; //IRQ that matches to pin 3
void setup() {
Serial.begin (9600);
}
void IRQcounter1() {
IRQcount1++;
}
void IRQcounter2() {
IRQcount2++;
}
// I would like some function to get the serial number here
void get_xbee_serial() {
}
void loop() {
attachInterrupt(pin_irq1, IRQcounter1, RISING);
attachInterrupt(pin_irq2, IRQcounter2, RISING);
delay(25);
detachInterrupt(pin2);
detachInterrupt(pin3);
Serial.print(F("Xbee Serial Number = "));
Serial.print(serialnumber);
Serial.print(F(" Counter 1 = "));
Serial.print(IRQcount1);
Serial.print(F(" Counter 2 = "));
Serial.println(IRQcount2);
}
You can retrieve the serial number using the AT commands ATSH
and ATSL
(serial number high/low). You can do that by going into command mode, sending those sequences followed by a return, and parsing the responses.
To get into command mode, you need to wait 1 second without sending anything, send the escape sequence +++
, and then wait another second. The XBee module should respond with OK\r
indicating that it's ready to receive commands.
Send ATSH\r
and you should get a hex string representing the top four bytes of the serial number. Repeat with ATSL\r
for the bottom four bytes.
And know that if you use a destination address of 0
, the XBee module will automatically send data to the coordinator on your network. If the coordinator is running in API mode, it can retrieve the sender's 64-bit MAC address from the frame header of the received data.