|
回復 3# kenn1660
請參考:不好意思沒 時間翻成中文 網頁請自搜
The above two methods separate entire networks, but if you have four XBee's in a multipoint situation, you still need a way to select which of the other three modules to talk to. This is why every Xbee has a 64-bit serial number programmed onto it that can be read out through the SL
(lower 4 bytes) and SH (upper 4 bytes) registers. Every node on the network knows each other's serial numbers or addresses.
So when Point A sends a packet to Point C, it includes Point C's address. All the modules in the network receive this and the microcontroller code compares the included number to their own.
If it matches, the data is for them. If not, the data is discarded.
Note that this must all be implemented by you in the software of the device you attach to the XBee. The XBee itself does not know who else is on the network or how to check the serial numbers.
即使在廣播模式 every Xbee 有獨特的編碼註冊 has a 64-bit serial number (Address) programmed onto it
----------------------------------------------
If you are using the API mode on these XBee chips (sure, if you use the XBee-api library), you do not need to include the address of the sender in the message.
This information is automatically specified in the frame. Have a look at the getRemoteAddress16() and getRemoteAddress64() methods in class ZNetRxBaseResponse .
So what you have to do, is send a first message "hello" i.e. to the Coordinator (which you can address easily as 0x0000) from the Node you want to know the address.
Using the above mentioned methods you can get this information.
你只要用程式先分辯此訊號來自哪個 Xbee use-> getRemoteAddress64()
去忽略不要收的訊號 或許可改善延遲的情況
範例
#include <XBee.h>
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
Rx64Response rx64 = Rx64Response();
XBeeAddress64 adr64;
int statusLed = 10;
int errorLed = 11;
uint8_t option = 0;
uint8_t data = 0;
void flashLed( int pin, int times, int wait ) {
for( int i = 0; i < times; i++ ) {
digitalWrite( pin, HIGH ); delay( wait ); digitalWrite( pin,
LOW );
if( i + 1 < times ) delay( wait );
}
}
void setup() {
pinMode( statusLed, OUTPUT );
pinMode( errorLed, OUTPUT );
xbee.begin( 9600 );
}
void loop() {
xbee.readPacket();
if( xbee.getResponse().isAvailable() ) {
if( xbee.getResponse().getApiId() == RX_64_RESPONSE ) {
xbee.getResponse().getRx64Response( rx64 );
option = rx64.getOption();
data = rx64.getData( 1 );
if( data == 'B' ) {
adr64 = rx64.getRemoteAddress64();
uint8_t payload[] = { 5, 7 };
Tx64Request tx = Tx64Request( adr64, payload, sizeof
( payload ) );
xbee.send( tx );
TxStatusResponse txStatus = TxStatusResponse();
if( xbee.readPacket( 5000 ) ) {
if( xbee.getResponse().getApiId() == TX_STATUS_RESPONSE )
{
xbee.getResponse().getZBTxStatusResponse(txStatus);
if( txStatus.getStatus() == SUCCESS ) flashLed
( statusLed, 5, 50 );
else flashLed( errorLed, 3, 500 );
}
}
else flashLed( errorLed, 2, 50 );
}
}
}
} |
|