[英]Arduino XBee sending data API
我想將數據從終端設備發送到XBee和Arduino的協調器。 但是,Arduino在發送數據時會重新啟動(發送數據已中止)。 可能是什么問題?
/* Transmit */
#include <SoftwareSerial.h>
#include <XBee.h>
int end = 1;
int alim_XbeeRS = A7;
int RX_XBee = 14;
int TX_XBee = 15;
XBee xbee = XBee();
//Allume le périphérique
void powerOn(SoftwareSerial portcom)
{
portcom.begin(57600);
digitalWrite(alim_XbeeRS, HIGH);
}
void setup ()
{
SoftwareSerial XbeeRS(RX_XBee,TX_XBee);
Serial.begin(57600);
XbeeRS.begin(57600);
pinMode(RX_XBee, INPUT); // Rx
pinMode(TX_XBee, OUTPUT); // Tx
pinMode(alim_XbeeRS, OUTPUT);
powerOn(XbeeRS);
xbee.setSerial(XbeeRS);
delay(5000);
Serial.println("XBee OP");
}
void loop()
{
if (end == 1)
{
Serial.println("sending");
ZBTxRequest _zbTx;
uint8_t payload[] = {'Y','E','S','\0'};
XBeeAddress64 address = XBeeAddress64 (0x13A200,0x4081B77C );
_zbTx = ZBTxRequest(address, payload, sizeof(payload));
Serial.println("sending");
xbee.send(_zbTx); // The program blocks here
}
else
{
Serial.println("waiting");
xbee.readPacket(100);
if (xbee.getResponse().isAvailable())
{
Serial.println("waiting 1");
if( xbee.getResponse().getApiId() == ZB_RX_RESPONSE)
{
Serial.println("waiting 2");
ZBRxResponse _rx;
xbee.getResponse().getZBRxResponse(_rx);
uint8_t* response= new uint8_t[50];
for(int i=0; i<_rx.getDataLength(); i++)
{
response[i] = _rx.getData()[i];
Serial.println(char(response[i]));
}
}
}
}
}
編輯 (其他信息):
如果更改有效負載中的值類型,則不會更改任何內容。 關於波特率,兩個XBees都配置為57600波特。 這是XBee的配置:
裝置
協調員
該設備的串行端口的結果是:
最后,我使用Arduino ATmega 1284P 。 我真的不知道什么樣的問題可以做到這一點。
有一些麻煩:/
首先,默認的協調器ADD為0x0 0x0,因此該行
XBeeAddress64 address = XBeeAddress64 (0x13A200,0x4081B77C );
應該
XBeeAddress64 address = XBeeAddress64 (0x0,0x0 );
然后,Xbee的波特率為57600嗎?
要獲得ACK,您可以使用:
if (xbee.readPacket(1000))
{
if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE)
{
xbee.getResponse().getZBTxStatusResponse(txStatus);
if (txStatus.getDeliveryStatus() == SUCCESS)
{
//It's sent
}
}
也可能來自您的有效載荷。 您最好使用十六進制值或int來確定要發送的內容。
編輯:
我知道您沒有使用最新版本的Xctu。 嘗試一下並測試它們之間的直接通信,以查看協調器與Routeur / End設備之間是否可以直接接觸。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.