我正在尝试发送一个字符,在这种情况下是字母“H”,通过Xbee通过附加了Xbee USB浏览器的Raspberry Pi发送,并从附带Xbee的Arduino接收响应“Hello”一个无线原型盾牌。
Raspberry上的代码:
from xbee import ZigBee
import serial
ser = serial.Serial('/dev/ttyUSB0',9600)
xbee = ZigBee(ser)
xbee.send('tx',dest_addr_long=b'\x00\x13\xA2\x00\x41\x49\x69\xD6',
dest_addr=b'\xFF\xFE',data=b'H')
while True:
try:
print(xbee.wait_read_frame())
except KeyboardInterrupt:
break
ser.close()
Arduino上的代码:
#include <SoftwareSerial.h>
// We'll use SoftwareSerial to communicate with the XBee:
SoftwareSerial Xbee(0, 1); // RX, TX
int incomingByte;
void setup() {
// Set up both ports at 9600 baud. This value is most important
// for the XBee. Make sure the baud rate matches the config
// setting of your XBee.
Xbee.begin(9600);
Serial.begin(9600);
}
void loop() {
if (Xbee.available()) {
// If data comes in from serial monitor, send it out to XBee
incomingByte = Xbee.read();
if(incomingByte == 'H') {
Serial.write("Hello");
}
}
}
问题是,当我运行代码时,我只接收Raspberry Pi上的传输状态,而不是其中包含“Hello”响应的数据包。
在Raspberry Pi上运行代码:
我通过使用XCTU工具运行相同的场景检查了这一点,并且我收到了一个响应数据包,其中包含“Hello”消息。那么如何让Raspberry Pi检测到响应数据包呢?
答案 0 :(得分:0)
简单错误。您没有将任何内容发送回XBee串口。
替换:
Serial.write("Hello");
使用:
Xbee.write("Hello");