2017-10-05 58 views
0

讀取的Xbee序號我打算有執行相同的操作在同一網絡中連接到的XBee系列2個無線電幾個Arduino的板。他們將數據傳輸到另一塊電路板,使用蜂窩連接一次上傳所有數據。我想以某種方式唯一標識每塊電路板。我意識到我可以將一個序列號硬編碼到Arduino板的EEPROM存儲器中。但是,對於我所要做的事情來說,這不會很好地擴展。有沒有辦法使用Arduino代碼讀取XBee的序列號,以便我可以將其與我的數據一起傳輸?與Arduino的

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); 
} 

回答

1

您可以檢索使用AT序列號命令ATSHATSL(序列號高/低)。您可以通過進入命令模式,發送這些序列並返回並解析響應。

要進入命令行模式,則需要等待1秒不發送任何,發送轉義序列+++,然後再等第二。 XBee模塊應回覆OK\r表示它已準備好接收命令。

發送ATSH\r,你應該得到較前四個字節序列號的十六進制字符串。對於底部的四個字節,重複ATSL\r

而且知道,如果你使用的0目的地地址,的XBee模塊會自動將數據發送到協調您的網絡上。如果協調器在API模式下運行,它可以從接收數據的幀頭中檢索發件人的64位MAC地址。

+0

謝謝你的回答言簡意賅。特別是關於檢索MAC地址的部分。我會研究它,因爲它似乎可能是我的項目的最佳解決方案。 –

+0

是不是有可能,人們可以購買兩套的XBee無線電臺使用相同的低序列號?只是好奇。 –

+0

不太可能。我相信所有基於802.15.4的XBee模塊(包括ZigBee和DigiMesh)都具有相同的SH值。 – tomlogic