简体   繁体   English

Arduino XBee发送数据API

[英]Arduino XBee sending data API

I want to send data from an end device to a coordinator with XBee and Arduino. 我想将数据从终端设备发送到XBee和Arduino的协调器。 But, the Arduino reboots when sending data (sending data was aborted). 但是,Arduino在发送数据时会重新启动(发送数据已中止)。 What could the problem be? 可能是什么问题?

/* 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]));
                }
            }
        }
    }
}

EDIT (additional information): 编辑 (其他信息):

It doesn't change anything if I change the value type in the payload. 如果更改有效负载中的值类型,则不会更改任何内容。 About the baud rate, both of XBees are configured to 57600 baud. 关于波特率,两个XBees都配置为57600波特。 Here is the XBee's configuration: 这是XBee的配置:

ENDEVICE 装置

设备配置

在此处输入图片说明

COORDINATOR 协调员

协调器配置

在此处输入图片说明

The result from the serial port of this device is: 该设备的串行端口的结果是:

在此处输入图片说明

Finally, I use the Arduino ATmega 1284P . 最后,我使用Arduino ATmega 1284P I really have no idea what kind of problem could do this. 我真的不知道什么样的问题可以做到这一点。

There is some trouble :/ 有一些麻烦:/

First, the default coordinator ADD is 0x0 0x0, so the line where 首先,默认的协调器ADD为0x0 0x0,因此该行

XBeeAddress64 address = XBeeAddress64 (0x13A200,0x4081B77C );

should be 应该

XBeeAddress64 address = XBeeAddress64 (0x0,0x0 );

Then, is the Xbee at 57600 baud too? 然后,Xbee的波特率为57600吗?

To get an ACK, you can use: 要获得ACK,您可以使用:

  if (xbee.readPacket(1000))
  {     
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) 
    {
      xbee.getResponse().getZBTxStatusResponse(txStatus);
      if (txStatus.getDeliveryStatus() == SUCCESS) 
      {
        //It's sent
      } 
    }

It could be from you payload too. 也可能来自您的有效载荷。 You better use a hexadecimal value or int to be sure of what you send. 您最好使用十六进制值或int来确定要发送的内容。

EDIT: 编辑:

I see you don't use the last version of Xctu. 我知道您没有使用最新版本的Xctu。 Try it and test the direct communication between them to see if you can have direct contact between Coordinator and Routeur/End device. 尝试一下并测试它们之间的直接通信,以查看协调器与Routeur / End设备之间是否可以直接接触。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM