您好我正在开发一个WSN,其中每个终端设备在开始传输之前必须接收来自协调员的呼叫。出于测试目的,我正在使用4 Arduino nano 3.0(在最终配置中我将使用具有M3 cortex cpu的不同微控制器)和四个XBee(具有zb固件的xb24-b)。我无法从协调器向选定的终端设备发送消息,同时我成功地将数据从终端设备传输到协调器。 这里是协调器节点上arduino上运行的代码。终端设备通过USB浏览器直接连接到电脑。
#include <SoftwareSerial.h>
// creo una porta seriale di tipo software sui pin 2(RX) e 3(TX)
uint8_t rxxbee = 2;
uint8_t txxbee = 3;
SoftwareSerial Serial_xbee(rxxbee,txxbee);
// variable to store the data received
int sensorValue = 0;
// costant values of the frame
const byte startDelimeter = 0x7E;
// length
const byte MSB_1 = 0x00;
const byte LSB_2 = 0x10;
// Frame-specific data
const byte frameType = 0x10;
const byte frameID = 0x0;
// 64-bit destination address
const byte MSB_5 = 0x00;
const byte b_6 = 0x13;
const byte b_7 = 0xA2;
const byte b_8 = 0x00;
const byte b_9 = 0x40;
const byte b_10 = 0x86;
const byte b_11 = 0xDB;
const byte LSB_12 = 0xA4;
// 16-bit destination network address
const byte MSB_13 = 0x0;
const byte LSB_14 = 0x0;
// broadcast radius
const byte broadcastRadius = 0x0;
// options
const byte opt = 0x0;
byte spedisci (byte value) {
Serial_xbee.write(value);
Serial.write(value);
return value;
}
void setup()
{
// starts serial communication
Serial.begin(9600);
Serial_xbee.begin(9600);
pinMode(sensorPin, INPUT);
}
void loop()
{
// send data through xBee
spedisci(startDelimeter);
spedisci(MSB_1);
spedisci(LSB_2);
long sum = 0; // accumulate the checksum
sum += spedisci(frameType);
sum += spedisci(frameID);
sum += spedisci(MSB_5);
sum += spedisci(b_6);
sum += spedisci(b_7);
sum += spedisci(b_8);
sum += spedisci(b_9);
sum += spedisci(b_10);
sum += spedisci(b_11);
sum += spedisci(LSB_12);
sum += spedisci(MSB_13);
sum += spedisci(LSB_14);
sum += spedisci(broadcastRadius);
sum += spedisci(opt);
sum += spedisci(0X10); // this is the payload[0] byte
sum += spedisci(0X10); // this is the payload[1] byte
spedisci( 0xFF - (sum & 0xFF));
}
有什么建议吗?
谢谢!
协调器api固件为21A7;终端设备api固件是29A7
答案 0 :(得分:1)
我认为当使用不是协调器的节点的64位IEEE地址时,需要使用0xFFFE作为16位网络地址。尝试更改代码的这一部分:
// 16-bit destination network address
const byte MSB_13 = 0xFF;
const byte LSB_14 = 0xFE;
当您准备离开Arduino平台时,请查看此开源便携式ANSI C XBee Host Library,以便在API模式下与XBee无线电通信。它可以简化很多软件开发。