我计划在同一网络中连接到XBee系列2无线电的几个Arduino板执行相同的操作。他们将数据传输到另一个使用蜂窝连接一次上传所有数据的电路板。我想以某种方式唯一地识别每个板。我意识到我可以将序列号硬编码到Arduino板的EEPROM存储器中。然而,对于我想要做的事情,这不会很好地扩展。有没有办法使用Arduino代码读取XBee的序列号,以便我可以将它与我的数据一起传输?
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);
}
答案 0 :(得分:1)
您可以使用AT命令ATSH
和ATSL
(序列号高/低)检索序列号。您可以通过进入命令模式,发送这些序列然后返回,并解析响应来实现。
要进入命令模式,您需要等待1秒钟而不发送任何内容,发送转义序列+++
,然后等待一秒钟。 XBee模块应以OK\r
响应,表明它已准备好接收命令。
发送ATSH\r
,您应该得到一个十六进制字符串,表示序列号的前四个字节。用ATSL\r
重复最后四个字节。
并且知道如果您使用目标地址0
,XBee模块将自动将数据发送到您网络上的协调器。如果协调器在API模式下运行,它可以从接收数据的帧头中检索发送方的64位MAC地址。