Giter VIP home page Giter VIP logo

xbee-arduino's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xbee-arduino's Issues

Management LQI Request Issue

I am building a application that every node needs to know who are its parent and children. When I issue to the local node a ZDO request (Management LQI Request) I always get the value 0x3 (0x3 โ€“ None of the above) to the relationship with the neighbors. When I issue the request to a remote node I get the right value. I am using the S2 series. Why are this happening?

Arduino 101 - Intel Curie Issue

Ok folks now I have an interesting problem. I just started experimenting with the Arduino 101 board which is based on the Intel Curie as you know. I uploaded the sketches that I have used successfully on the Uno and Mega with no issue and ran a processing sketch that uses the digi java library - yes it was well tested and works like a charm. I am using API mode =1 - yes I modified an older version of the code for this purpose as I am send a large amount of data and that works like a charm as well.

Now the issue - when I try and do the same with the Arduino 101 I am running into problems. The Arduino receives and executes the commands no issue but when it sending data back it fails in the sense that frame is null. I did a few serial prints from the cpp file and the frame is being generated. So it has to be something else. Also when I send the command from xctu to get the data it comes back as null.

Any advice on tracking this one down?

Thanks
Mike

Almost forgot I am using windows 10, 64bit OS. Also tried it on the windows 10, 32 that I developed it on to begin with and it didn't work there either.

End Device API (E) to Router Device API (R) communication is not working

Hi,
I am trying to make following topology in API mode.
End device (E) <--->Router (R) <----> coordinator (C)
Is it feasible ? I have configured both xbees in API mode (2). I am not able to see communication happening between end point and router in APi mode. Please help to fix this.

However, following topology is working:
Router (R) <---> Coordinator (C)

Thanks,
Jyoti

XBee::send always escapes

The XBee::send method always escapes the content of the request. As a result when I send messages with an XBee configured for API mode 1,messages that contain bytes with value of 19 never get sent.

Mega Rx from Xbee causing high voltage 1023 on all analog input pins

Hello,

Having a very strange issue that seems associated to the Tx packet from the Xbee to the Mega Rx (on any serial port) which then causes a stuck high voltage on all the mega input pins. Nothing seems to reset the high voltage (1023 analog reading on any input pin) except a hard reset which then reads normal until a the xbee is attached. Prior to updating the latest Xbee lib, it would only start the issue when a Rx packet came through to the mega, now it happens when I connect the Tx from the Xbee to the Rx of the mega pretty quickly. and hangs as it had before. Not sure if you might understand more of how the Rx packets might affect the analog input readings of the mega.

Thanks.

Alec

Hanging up on send

Hi,

I have a code that was working nice until three weeks ago, when I was on version <0.6.0 of this library and on Arduino 1.6.5. Now, I'm on version 0.6.0 and Arduino 1.6.6. The hardware is a Arduino Mega.

Now, everytime I try to send something (e.g., the sample code of Series2_Tx or the code sample below), there is no activity on radio (the transmission LED on my Xbee shield does not blink). If I remove the radio and connect it on a FTDI cable, I can send data flawless using XCTU -- so, I believe the radio and the shield are ok.

#define NODEiD "Node1"
XBee radio = XBee();
XBeeAddress64 destino = XBeeAddress64(0x0013a200, 0x40c6740d);
char toSend[50];

ZBTxStatusResponse sendToNode(XBee radio, XBeeAddress64 to, char *s)
{
  ZBTxRequest zbTx;
  ZBTxStatusResponse txStatus;

  zbTx = ZBTxRequest(to, (uint8_t *) s, strlen(s));
  radio.send(zbTx);
  txStatus = ZBTxStatusResponse();

  return (txStatus);
}

void setup() {
  ZBTxStatusResponse txStatus;

  Serial3.begin(9600);
  radio.setSerial(Serial3);
  createMessage (toSend, 50, "ON", NODEiD, 0); // A procedure to fill toSend with data to be sent
  txStatus = sendToNode(radio, destino, toSend);
}

void loop() {
}

After some debugging, I traced down to line 1547 of XBee.cpp (flush();). When the execution flow reaches that line, the code hangs up.

Any idea on what is going on?

Zdp Scan function is not searching unless serial monitor is ON

Hi,
I am using Arduino UNO R3.
It seems device discovery/LQI inquiry function is not working unless serial monitor is opened.
It works only when serial monitor is ON. Can we get the discovery function working without serial monitor on (i.e. without connected to PC, only powered on using battery)?

Please REPLY as soon as possible.

My setup() function is given as below.

void setup() {
  Serial.begin(9600);
  xbee.setSerial(Serial);

  // Set AO=1 to receive explicit RX frames
  // Because this does not write to flash with WR, AO should be reverted
  // on reboot.
  uint8_t value = 1;
  AtCommandRequest req((uint8_t*)"AO", &value, sizeof(value));
  req.setFrameId(xbee.getNextFrameId());
  uint8_t status = xbee.sendAndWait(req, 150);
  if (status == 0)
    Serial.println(F("Set AO=1"));
  else
    Serial.println(F("Failed to set AO, expect problems"));
  scan_network();
}

Thanks & Regards,
Jyoti Raj Sharma

Series 2 S2C

Can you confirm if we can use the library with Series S2C. I'm having some issues with a lot of error packets when i try to send a message between them.
Maybe something related with internal buffers...?
it used to work perfecty with a Series 1. The only change I made was to adapt/change all 16address and class and funcions with the ones created for series 2 and 64address.

Send issue

Hello,

i have been spending the last day or so trying to get my 2 (soon to be 3) xbee pro S2B to communicate with each other. in AT mode that works fine they both can send and receive.

when in API mode the Coordinator(PC) can send message to my router(arduino) node and it receives just fine, but when running the TX sample code it keeps on failing.

so i decided to edit the receive code to echo back anything it gets. but coordinator(pc) does not receive anything back. do any of you know what could be my problem?

#include <XBee.h>
#include <SoftwareSerial.h>

/*
This example is for Series 2 XBee
Sends a ZB TX request with the value of analogRead(pin5) and checks the status response for success
*/

// create the XBee object
XBee xbee = XBee();

uint8_t payload[] = { 'H', 'i' };

// SH + SL Address of receiving XBee //0013A200 40B7B2B8
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x40B7B2B8);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

// create reusable response objects for responses we expect to handle 
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();

// Define NewSoftSerial TX/RX pins
// Connect Arduino pin 8 to TX of usb-serial device
uint8_t ssRX = 9;
// Connect Arduino pin 9 to RX of usb-serial device
uint8_t ssTX = 8;
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
SoftwareSerial nss(ssRX, ssTX);

void setup() {
    // start serial
    Serial.begin(9600);
    nss.begin(9600);

    xbee.setSerial(nss);


    Serial.println("Starting up!");
}

void loop() 
{
    xbee.readPacket();

    if (xbee.getResponse().isAvailable())
    {
        // now fill our zb rx class
        xbee.getResponse().getZBRxResponse(rx);

        // got a response!
        Serial.println("got a response!");

        Serial.println("sending back.");
        zbTx = ZBTxRequest(rx.getRemoteAddress64(), rx.getFrameData(), sizeof(rx.getFrameData()));

        xbee.send(zbTx);

    }
    else if (xbee.getResponse().isError())
    {
        Serial.print("Error reading packet.  Error code: ");  
        Serial.println(xbee.getResponse().getErrorCode());
    }
}

The settings for the xbee's are:
Coordinator:

<?xml version="1.0" encoding="UTF-8"?>
<data>
  <profile>
    <description_file>XBP24-ZB_21A7_S2B.xml</description_file>
    <settings>
      <setting command="ID">3613</setting>
      <setting command="SC">000C</setting>
      <setting command="SD">3</setting>
      <setting command="ZS">0</setting>
      <setting command="NJ">FF</setting>
      <setting command="DH">0</setting>
      <setting command="DL">FFFF</setting>
      <setting command="NI">0x20</setting>
      <setting command="NH">1E</setting>
      <setting command="BH">0</setting>
      <setting command="AR">FF</setting>
      <setting command="DD">30000</setting>
      <setting command="NT">3C</setting>
      <setting command="NO">0</setting>
      <setting command="CR">3</setting>
      <setting command="PL">4</setting>
      <setting command="PM">1</setting>
      <setting command="EE">0</setting>
      <setting command="EO">0</setting>
      <setting command="KY"></setting>
      <setting command="NK"></setting>
      <setting command="BD">3</setting>
      <setting command="NB">0</setting>
      <setting command="SB">0</setting>
      <setting command="D7">1</setting>
      <setting command="D6">0</setting>
      <setting command="AP">1</setting>
      <setting command="AO">0</setting>
      <setting command="SP">20</setting>
      <setting command="SN">1</setting>
      <setting command="D0">1</setting>
      <setting command="D1">0</setting>
      <setting command="D2">0</setting>
      <setting command="D3">0</setting>
      <setting command="D4">0</setting>
      <setting command="D5">1</setting>
      <setting command="P0">1</setting>
      <setting command="P1">0</setting>
      <setting command="P2">0</setting>
      <setting command="PR">1FFF</setting>
      <setting command="LT">0</setting>
      <setting command="RP">28</setting>
      <setting command="DO">1</setting>
      <setting command="IR">0</setting>
      <setting command="IC">0</setting>
      <setting command="V+">0</setting>
    </settings>
  </profile>
</data>

and node:

<?xml version="1.0" encoding="UTF-8"?>
<data>
  <profile>
    <description_file>XBP24-ZB_23A7_S2B.xml</description_file>
    <settings>
      <setting command="ID">3613</setting>
      <setting command="SC">C</setting>
      <setting command="SD">3</setting>
      <setting command="ZS">0</setting>
      <setting command="NJ">FF</setting>
      <setting command="NW">0</setting>
      <setting command="JV">0</setting>
      <setting command="JN">0</setting>
      <setting command="DH">0013A200</setting>
      <setting command="DL">40B7B2B8</setting>
      <setting command="NI">0x20</setting>
      <setting command="NH">1E</setting>
      <setting command="BH">0</setting>
      <setting command="AR">FF</setting>
      <setting command="DD">30000</setting>
      <setting command="NT">3C</setting>
      <setting command="NO">0</setting>
      <setting command="CR">3</setting>
      <setting command="PL">4</setting>
      <setting command="PM">1</setting>
      <setting command="EE">0</setting>
      <setting command="EO">0</setting>
      <setting command="KY"></setting>
      <setting command="BD">3</setting>
      <setting command="NB">0</setting>
      <setting command="SB">0</setting>
      <setting command="D7">1</setting>
      <setting command="D6">0</setting>
      <setting command="AP">1</setting>
      <setting command="AO">0</setting>
      <setting command="SM">0</setting>
      <setting command="SN">1</setting>
      <setting command="SO">0</setting>
      <setting command="SP">20</setting>
      <setting command="ST">1388</setting>
      <setting command="PO">0</setting>
      <setting command="D0">1</setting>
      <setting command="D1">0</setting>
      <setting command="D2">0</setting>
      <setting command="D3">0</setting>
      <setting command="D4">0</setting>
      <setting command="D5">1</setting>
      <setting command="P0">1</setting>
      <setting command="P1">0</setting>
      <setting command="P2">0</setting>
      <setting command="PR">1FFF</setting>
      <setting command="LT">0</setting>
      <setting command="RP">28</setting>
      <setting command="DO">1</setting>
      <setting command="IR">0</setting>
      <setting command="IC">0</setting>
      <setting command="V+">0</setting>
    </settings>
  </profile>
</data>

Edit: i know i have setup my xbee correctly, because if i switch them now the router(PC) can reserve data and the coordinator(arduino) can not send

Edit 2: if i manually make the frame and send it directly to the serial connection it works just fine. could there be a bug in the frame making part? is there a debug function that i can call to see what the actual frame looks like?

Can not send data very fast?

I use
xbee.send(zbTx);
To send data.If i send data and wait more than 1 second every thing work fine.
But how can i send data very fast?(less than 100ms)

//This work fine
void loop(){
xbee.send(zbTx);
delay(1000);
}
//This didn't work
void loop(){
xbee.send(zbTx);
delay(100);
}

Add to Arduino library manager

Since 1.6.2, the Arduino IDE supports a library manager, to allow easily browsing and downloading libraries from the web. It would be convenient if this library was added. To do that:

  1. a library.properties file must be added to this repo
  2. a request must be sent to the Arduino devs

If you want, I can submit a PR for 1 and take care of 2?

Packets aren't well read with SAMD board

Hello everyone.

I'm working on a XBEE project with SERIES 1 Digimesh firmware. I have tested every example setting request and response as ZB and address at 64 bits. All is working as expected with an AVR arduino board (I have been testing with a 1280p chip).

However, with a SAMD board, Tx is working but Rx example doesn't. Bytes aren't parsed well. I think, It could be something related with SAMD architecture or datatypes but I can't find where the problem is. I should point that I'm working with hardware Serial1 (SERCOM).

Has anyone got any idea??

Thanks in advance.

Getting rx device serial

Hi,

I am trying to use rx.getRemoteAddress32() and transmit to to a website via ethernet, however I seem to be getting the broadcast address instead of the source address. Any ideas of what I might be doing wrong?

I have also tried

float sensorHighAddress;
float sensorLowAddress;

sensorHighAddress = (uint32_t(rx.getFrameData()[0]) << 24) + (uint32_t(rx.getFrameData()[1]) << 16) + (uint16_t(rx.getFrameData()[2]) << 8) + rx.getFrameData()[3];
sensorLowAddress =  (uint32_t(rx.getFrameData()[4]) << 24) + (uint32_t(rx.getFrameData()[5]) << 16) + (uint16_t(rx.getFrameData()[6]) << 8) + rx.getFrameData()[7];

char sensorHigh[16];
char sensorLow[16];

dtostrf(sensorLowAddress, 16, 0, sensorLow);
dtostrf(sensorHighAddress, 16, 0, sensorHigh);

Message is seen to be delivered even tough the coordinator is unplugged.

Once associated (S2 devices) I can reliably send Transmit Requests from my router (Arduino+XBee S2) to my coordinator (XStick USB), however, if I unplug my coordinator the Arduino continues sending packets and appears to receive positive delivery reports (5 Flashes from the S2 TX demo). (I'm not under the impression that it is actually receiving response packets, I think the code has a bug)

I have tested this extensively with XCTU and it is working perfectly there. (Throwing a delivery error when the coordinator is powered off.

My guess is that there is a bug somewhere in the code that is evaluating the responses (or lack thereof?)

Arduino Mega 2560 Software Serial Not Working

Hello!

We have an xBee Pro S2C that is using this library very well on a Software Serial connection to ports 2 and 3 on an Arduino Uno. However, when we take the same setup and try it on a Arduino Mega 2560 using any of the ports specified here:

https://www.arduino.cc/en/Reference/SoftwareSerial
Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

We cannot get this setup to work on the Arduino Mega 2560. We did not try every combination of these ports but tried most of them and it continues to fail. We can get successful packets on an Uno on pins 2 and 3.

Code is as follows:

`#include "Arduino.h"
#include "XBee.h"
#include <SoftwareSerial.h>
#define IS_STAR 0
#if IS_STAR
#define rxPin 10 //input
#define txPin 11 //output
#else
#define rxPin 2 //input
#define txPin 3 //output
#endif
#include "SoftReset.h"

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///setup xbee object

XBee xbee = XBee();
SoftwareSerial xBeeSerial = SoftwareSerial(rxPin, txPin);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Setting up class & contructors

Laser::Laser () {

        pinMode(rxPin, INPUT);
        pinMode(txPin, OUTPUT);
        xBeeSerial.begin(9600);
        xbee.setSerial(xBeeSerial);
        Serial.begin(9600);`

Any thoughts as to what changes would need to be made to this library in order to run on a Mega if any?

At Command CE = 1 not working

I was wondering why I can not set the value of the CE on the Xbee, I am also trying to set up EE and KY, but the only thing that works is the ID.
I tried setting turnOn = 0x01 or 1 or 0x31 (Hex for 1). I looked at what X-ctu is doing and I am sending the same information (Value 0x01) , though I can not see the actual xbee frame being sent, I know my values and command are correct. The response is 0x00 for success.
Also I do have code at the end to issue ATWR and ATAC. I also tried to issue only the CE command or others, the thing is I know it is changing the value because I can take it will take it out of CE mode (CE = 0).
Below is the code. Any ideas.
Also I wrote some code that will take the xbee and pop it into API mode 2 from the ardiuno board, so that all the Xbee's will not have to be set up, the board can do it on a one time set up. Where can I submit that for this project.
Thanks,
Donald

#include <XBee.h>
#include </root/Arduino/libraries/xbee-arduino-master/Printers.h>

XBeeWithCallbacks xbee;

#define DebugSerial Serial
#define SerialXbee Serial1

void setup() {
DebugSerial.begin(9600);
DebugSerial.println("Starting up...");
SerialXbee.begin(9600);
xbee.begin(SerialXbee);
delay(1);
// Let all responses be printed
xbee.onResponse(printResponseCb, (uintptr_t)(Print ) & DebugSerial);
xbee.onPacketError(printErrorCb, (uintptr_t)(Print
) & DebugSerial);
// The paramater for the command value
uint8_t idPan [8] = {0x90,0xda,0xdc,0xff,0x45,0x5a,0xab,0xdf};
uint8_t turnOn = 1;
// Send a command to the xbee
// Set the Pan ID in the device
AtCommandRequest req((uint8_t*)"ID",(uint8_t*) idPan,8);
xbee.send(req);
// Set the device to a co-ordinator (Brain only)
req.clearCommandValue();
req.setCommand((uint8_t*)"CE");
req.setCommandValue((uint8_t*) turnOn);
req.setCommandValueLength(1);
xbee.send(req);
// Set the device for channel verification
// req.clearCommandValue();
// req.setCommand((uint8_t*)"JV");
// req.setCommandValue((uint8_t*) turnOn);
// req.setCommandValueLength(1);
// xbee.send(req);
// Turn on Sleep Mode Pin set to one, so turn on value will work
// req.clearCommandValue();
// req.setCommand((uint8_t*)"SM");
// req.setCommandValue((uint8_t*) turnOn);
// req.setCommandValueLength(1);
// Turn on Encryption
req.clearCommandValue();
req.setCommand((uint8_t*)"EE");
req.setCommandValue((uint8_t*) turnOn);
req.setCommandValueLength(1);
// Set the name of the device
uint8_t kyKey[16] = Data; // Changed I don't want to post my KY Code
req.clearCommandValue();
req.setCommand((uint8_t*)"KY");
req.setCommandValue((uint8_t*) kyKey);
req.setCommandValueLength(16);
xbee.send(req);
// Write the settings to the Xbee
req.clearCommandValue();
req.setCommand((uint8_t*)"WR");
xbee.send(req);
// Apply settings to Xbee right away without bootup
req.clearCommandValue();
req.setCommand((uint8_t*)"AC");
xbee.send(req);
// Call NO
}

// continuously reads packets, looking for ZB Receive or Modem Status
void loop() {
xbee.loop();
}

Support for devices without hardware Serial

I tried running this on a Trinket (which runs ATtiny chip), and that device doesn't have a hardware Serial, therefore the XBee.cpp file doesn't compile because XBee::XBee(): _response(XBeeResponse()) tries to do: _serial = &Serial;

The way I fixed my compilation problem is by editing the _response function and setting _serial = 0; but that seems like a hack. (PS: I ran into some other problems with my Trinkets, so I don't know if that actually worked).

At Remote command using API mode

Hi all, i am learning Arduino and Xbee device. I have a coordinator in API mode ( XB24-ZB ) connect to my PC using a USB board and a Router in API mode with Arduino, XBee shield and Xbee.
Both the Xbee are series 2.
I try to send a simple transmit packet from router to coordinator and it receive that, so now i want to send a AT command from router to coordinator but the coordinator dont receive the packet.
There is my code:

#include <XBee.h>

uint8_t irCmd[] = {'I','D'};
uint8_t irValue[] = {};
XBee xbee = XBee();

XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x40FC875B);
RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest(addr64, irCmd, irValue, sizeof(irValue));

void setup() {
Serial.begin(9600);
xbee.setSerial(Serial);
}

void loop() {
 xbee.send(remoteAtRequest);
 delay(5000);
}

For now i dont read the coordinator response, only send this packet. Where is my error? thanks a lot

Value being received is not what is expected

Received packet:
7E 00 0E 90 00 7D 33 A2 00 41 5D 7A 35 00 00 01 ED FF 80

Where RF data in hex is : ED FF. Which is way off..!

Coordinator Code:

#include <XBee.h>
#include <Printers.h>
XBee xbee = XBee();
int LEDPin=13;
float temp;
int temp2;
XBeeAddress64 address = XBeeAddress64(0x0013a200, 0x415d7a44);
String str1,str2;

void setup() {
xbee.begin(Serial);
Serial.begin(9600);
pinMode(LEDPin, OUTPUT);
digitalWrite(LEDPin, LOW);
str1="Temperature :";

}

void loop() {
if (Serial.available() >= 21){

if(Serial.read() == 0x7E){     //start byte 
  for(int i=1; i<19; i++){
    byte discardByte=Serial.read();
  }
  int analogMSB = Serial.read();
  int analogLSB = Serial.read();   
  int analogReading = analogLSB + (analogMSB * 256);
  
  temp = analogReading / 1023.0 * 120;
  temp = temp - 50;            // holds temperature value in type float
  str2=str1+temp;
  temp2=(int)temp;
  //Serial.println(str2);               
  uint8_t* utemp = reinterpret_cast<uint8_t*>(&temp2);     // stores int type data in uint8_t* format
  ZBTxStatusResponse txStatus = ZBTxStatusResponse();
  ZBTxRequest zbTx = ZBTxRequest(address, utemp, sizeof(utemp));
  xbee.send(zbTx);
  if(temp>24){
    digitalWrite(LEDPin, HIGH);
    }
  else{
    digitalWrite(LEDPin, LOW);
    }

}
}
}

error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'char*'

Its giving this error when trying to complile.

I think its a recent change.

I'm compiling using platformiIO.

Full error:
lib/xbee-arduino-master/XBee.cpp: In member function 'char* NodeIdentifierResponse::getNodeIdentifierString()':
lib/xbee-arduino-master/XBee.cpp:787:27: error: invalid conversion from 'uint8_t* {aka unsigned char_}' to 'char_' [-fpermissive]
return getFrameData() + 21;

^
*** [.pioenvs/megaatmega2560/lib/xbee-arduino-master/XBee.o] Error 1

Various API improvements

I am currently in the process of writing a book about Arduino and XBee, which will make use of this library. First off, compliments on the library: it is well designed and implemented, powerful but also easy to use.

While writing some examples for my book, I did notice that I still needed quite some boilerplate code, wrt checking for available packets, converting to the right type, etc. I think that, by expanding on the API that the library provides, a lot of this boilerplate code could be removed (without adding much of a performance overhead, or breaking backward compatibility). I also noticed some other improvements that could make things easier.

I'm willing to implement all of this, if you agree these are good additions and expect you can merge the changes without too much delay. I'd like to update the examples in my book using these improvements, but since I cannot publish before I'm sure these changes are actually merged, some timeliness would be required (e.g. merging this within the next one or two months).

In particular, these are the changes I have in mind:

  • Currently, the getXxxResponse() methods take an XBeeResponse reference, which they statically cast to the relevant subclass. I think these methods could be changed to take an argument of the relevant subclass directly? This saves the static_cast, and prevents silent failures when a user passes the wrong object. AFAICS we can just change the argument types, this will only break existing code that is already broken (because it passes the wrong response object type).

  • We could add getXxxResponse() methods that take no argument, but just return a new object of the right type. AFAIU, "return value optimization" should automatically convert this to passing in a reference argument that will be filled by the method, instead of copying over the data, so there should not be any additional performance cost (I'll make sure to verify that), while making the code easier to read. The existing methods can remain (and be used by the new methods even), so existing code will still work.

  • Defining the getXxxResponse() methods inside the .h file would allow inlining them. With the simplifications proposed above and below, their implementation should become very consise and pretty much no code will be generated for converting responses, then.

  • Inside XBeeResponse, common fields are currently stored as separate members. This means that data is being parsed inside readPacket() already, and that when the response is converted to a subclass, all data has to be copied over. The actual API packet payload, however, is stored as a single byte array, which can be easily "copied" over to the subclasses by copying the pointer. Then, (some of) the subclasses parse the data "on demand" in the various getXxx() methods.

    I would propose to adopt the latter scheme for all response data - enlarge the buffer and just let readPacket() copy all data over into the buffer (it should still parse the length and checksum, of course). Then getApiId(), getPacketLength(), etc. would use the bytes right out of the buffer. Converting the response to a subclass can then be simplified greatly, too.

    One caveat is that setFrameData() should probably be marked as deprecated and replaced by a setPacketData() that expects to receive a bigger buffer. Methods like setApiId() should be removed or deprecated too. Since I don't think anyone will be actually using these methods, this shouldn't affect compatibility much?

  • A significant portion of my sketch code is now about calling readPacket(), checking isAvailable() and isError(), converting the response to the right type and dispatching to the right piece of code to actually handle the response. I think that all of this boilerplate can be removed by using callback functions.

    I propose making a subclass of XBee, called XBeeCallbacks. This class would store a number of callback functions. Right now, I'm thinking this would be onPacketError() (when getResponse().isError() is true), onResponse() (called when any response is received, passing the unconverted XBeeResponse object) and one callback for every supported response type (e.g. onZBTxStatusResonse()). Possibly a getOtherResponse() would be useful to be called for every response class that does not have its own callback (to print error/debug messages).

    Then, this subclass would have a loop() method to be called from inside the sketch's loop() function, which handles calling readPacket(), checking the results and dispatching to the right callback.

    In addition to keeping a callback, it might be useful to also keep a void* per callback as "userdata", in case you need some variable data inside the callback (e.g. the Stream* to write error messages to). I'm not entirely sure if this is really needed yet, though it is often a good idea for callbacks.

    All this could be implemented on top of the existing API, making its use optional. I don't think any of the current API needs to be modified to support this. Implementing this in a subclass ensures that if you do not need the callback stuff, you won't suffer from the memory overhead of the callback pointers. If you do need to callback stuff, I think the only real performance penalty is a bit of memory for the callback pointers and the indirect function call.

    I have thought a bit about putting the table of callback pointers into PROGMEM but it seems it might be tricky to get that right (and you might sometimes want to switch the callbacks at runtime as well).

  • If callbacks are implemented, it might make sense to have some standard utilities

  • Adding a int->string conversion for some of the error codes (packet errors, TxStatus codes) might make sense, to help error / debugging output. This is probably best as methods on the relevant response classes.

  • Adding a default "print error" callback (passing a target Stream* as the userdata) makes it very easy to get a proper error message when something goes wrong. Versions of these could be made for the packet error callback, but also for the tx status response, or other relevant callbacks.

Let me know if any or all of these changes make sense, or if you have other ideas or suggestions!

Can we use char * instead uint8_t* in payload and AT commands?

Hello friend new here and in arduino development....so sorry if i make any mistake....i just wanna say see below example of AT command..
image
where i need to define int array for AT command...instead we can do it in command directly if we use char* instead of uint8_t* like i have done in below snap..
image

and same we can make for payload as
image

it make bit easier...and working softly...thank u...!!

Arduino library manager out of date

Hi,

I noticed that an old version of the lib gets downloaded when using the Arduino lib manager (specifically, a version with the flush() at the end of send() method).

Maybe the version number should be updated to include the last commits ?

Setting the AT Commands via API mode

How do I use this library to set the parameters/values of an at command via api mode.

Say for instance, I want to set up the pan ID as as say 23 so ATID = 23. How do I do this via the api mode. the example provided does not seem to work or provide such a solution.

SoftwareSerial not working with XBee

I have the 1.6.5 IDE and the latest (10/6) XBee library. When I try to connect my XBee with a SoftSerial interface, the Uno is resetting.

I use the following in Series2_Tx setup:
SoftwareSerial mySerial(8,9); // RX, TX
mySerial.begin(9600);
xbee.setSerial(mySerial);

and as soon as xbee.send(zbTx); is called the Uno reboots.

Small problem in AtCommand example

Hi,

I'm using xBee modules Series 2, and getting a small problem with the AtCommand example [I downloaded the library through the IDE]. The problem is that the module sends a Modem Status (type 8A) message right when it starts. This means that when the code checks for a response from the first AT command, it will receive this message as a reply; then all the other responses will be offset.

I think that adding a quick call to xbee.readPacket() at the end of the setup() function should fix this.

I also suggest that the example code be changed to give an ASCII output of what the response command is, like this:

    if (atResponse.isOk()) {
          SerialBridge.print("Command [");
          SerialBridge.print((char)atResponse.getCommand()[0]);
          SerialBridge.print((char)atResponse.getCommand()[1]);
          SerialBridge.println("] was successful!");

Otherwise works well so far. Thanks !

No packet ACK on Coordinator

Hello!
I'm connecting 2 Xbees with the examples Series2_Rx_Nss and Series2_Tx. Communication is working great, but I never get a positive ACK on the coordinator. On the end device, the delivery status returns "succesful". The relevant excerpt from the Series2_Rx example is:

      // got something
           
      if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
        // got a zb rx packet
        
        // now fill our zb rx class
        xbee.getResponse().getZBRxResponse(rx);
      
        nss.println("Got an rx packet!");
            
        if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
            // the sender got an ACK
            nss.println("Sender got and ACK");
        } else {
          nss.println("Sender didn't get an ACK");
        }

Which always prints "Sender didn't get an ACK". Any insight on this is much appreciated.

Thank you all in advance!

Zigee RSSI

Is there a way to get the RSSI for the transmitter (on the return packet ack)?

I tried doing:

  // Base Station Address
  // Change these two values to the coordinator node's address
  XBeeAddress64 XBee_Addr64 = XBeeAddress64(0x0013a200, 0x40f317ce);

  //Build Transmit Request Packet
  ZBTxRequest zbTx = ZBTxRequest(XBee_Addr64, (uint8_t*) params, strlen(params));

  //Send the Data packet
  xbee.send(zbTx);

  // We are expecting an ACK packet, time to check for it.
  // Wait up to half second for the status response to be delivered
  if (xbee.readPacket(500)) {
    // got a response!

    // The response should be a Zigbee TX Status Response
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
      xbee.getResponse().getZBTxStatusResponse(txStatus);

      // Check the delivery status
      if (txStatus.getDeliveryStatus() == SUCCESS) {
        // success.

        sprintf(tempParam, "packetId=1&rssi=%x",
                rx16.getRssi());

But all I seem to get is Hex 25 when I outputting the value.

XBee S3B doesn't respond to OP or MY

Many thanks to Andrew and Matthija for their contributions here. I've had great success using this library with everything but the ZdpScan example.

When I run the sketch, I get messages in serial monitor that OP and MY commands failed to read, with status message 0x2.

I'm using XBee S3B modules, which don't seem to list these commands anywhere in their documentation. I also know that the module is being recognized, as it successfully sets A0=1 Do you have any other ideas as to what might be causing this?

XBeeAddress64 could use uint64_t?

Right now, this class uses two uint32_t variables to store its address and all accesses are based on msb/lsb too. However, C (also on AVR) supports the uint64_t (unsigned long long) type, which could hold the entire address in a single variable. Any reason for not using this?

Adding this now should be possible without breaking compatibility:

  • Add a constructor that takes a uint64_t
  • Add uint64_t get() and void set(uint64_t) methods
  • Leave all current methods in place

It might make sense to add a uint8_t get(uint8_t) method as well, to retrieve a single byte of the address (which allows simplifying ZBTxRequest::getFrameData and Tx64Request::getFrameData).

ZBTxRequest has wrong API ID

Hi Andrew

I followed your example Series2_TX. When I am sending a package to my coordinator, then I do not get any status response from the coordinator.

I found out that the API ID of a ZBTxRequest is not 0x10 but 0x16 which is not even a valid API ID in the XBee protocol.

Am I missing something?

`#include <XBee.h>

include <Printers.h>

include <SoftwareSerial.h>

// Software Serial Port for Xbee
SoftwareSerial xbeeSerial = SoftwareSerial(10,11);

// Create an XBee object at the top of your sketch
XBee xbee = XBee();

// Create an array for holding the data you want to send.
uint8_t payload[] = { 'H', 'I' };

// Specify the address of the remote XBee (this is the SH + SL)
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x40b7b208);

// Create a TX Request
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));

ZBTxStatusResponse txStatus = ZBTxStatusResponse();

void setup() {

// Start the serial port for debugging
Serial.begin(9600);

// Start the xbee serial port
xbeeSerial.begin(9600);

// Tell XBee to use Hardware Serial. It's also possible to use SoftwareSerial
xbee.setSerial(xbeeSerial);
}

void loop() {

Serial.println("Go");

Serial.print("ZB TX API ID: ");
Serial.println(zbTx.getApiId());

// Send your request
xbee.send(zbTx);

// after sending a tx request, we expect a status response
// wait up to half second for the status response
if (xbee.readPacket(500)) {
// got a response!

// should be a znet tx status              
if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
  xbee.getResponse().getZBTxStatusResponse(txStatus);

  // get the delivery status, the fifth byte
  if (txStatus.getDeliveryStatus() == SUCCESS) {
    // success.  time to celebrate
    Serial.println("Success");
  } else {
    // the remote XBee did not receive our packet. is it powered on?
    Serial.println("Loss");
  }
}

} else if (xbee.getResponse().isError()) {
Serial.print("Error reading packet. Error code: ");
Serial.println(xbee.getResponse().getErrorCode());
} else {
Serial.println("This should not happen");
}

delay(5000);
}`

Controlling remote D0 pin

Hello,

This is my remote XBee SH and SL
SH --> 0013A200
SL --> 40A292BD

API Mode 2

I use this api frame to controlling D0 pin from XCTU

D0 HIGH --> 7E 00 10 17 01 00 7D 33 A2 00 40 A2 92 BD FF FE 02 44 30 05 89
D0 LOW --> 7E 00 10 17 01 00 7D 33 A2 00 40 A2 92 BD FF FE 02 44 30 04 8A

Now, How can I made the same with xbee-arduino library ?

I have tried this:

  XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x40A292BD);
                        uint8_t payload[] = {0x44, 0x30, 0x05};
                        ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
                        xbee.send(zbTx);

But not works to me.

Best regards

Can't get two xbee's to communicate...

Hey guys, I can't seem to get these two xbee's to communicate. I really want to get this project finished so I can finally fly my drone!!! Any help would be appreciated. Thanks!

Here is my xbee testing code.

selection_011

img_92641

img_17671

img_63411

Xbee S2C With ZigBee firmware can't communicate in API mode

Hi, Thanks a lot for the library!
I have a problem: I have two Xbee (with Zigbee firmare) and I'm trying to send data from Coordinator to Router.

  • If I send a remote AT command (with XCTU), the route receive the packet and the led attached to Xbee turns On/Off, so router and coordinator can communicate;
  • If I sand a packet in trasparent mode, Router receive the packet and I can see it with Arduino.
  • If I sand a packet in API mode (AT=2), the router seems to don't receive anything: I can't see it in arduino and the led attached to arduino (like the example Series2_RX) doesn't blink.
  • If I send a packet from router to coordinator, I can see It with XCTU, so the coordinator can receive rightly from router.

Any ideas?

Thanks!

Nothing printed at Serial

I'm using the echo_callbacks.ino example and I don't get nothing printed at Serial using xbee.onZBRxResponse(zbReceive). Any help?

AtCommand on Series1 no response

Just getting started with the XBee on a Leonardo so first step is just to talk to the XBee on the board I'm programming so I started with the AtCommand example.

Changed the software serial to hardware with my USB being Serial and XBee Serial1 (works fine that way with other programs). Made no other changes.

Uploaded that and never see any responses. Increased the delays to 10 seconds, still nothing.

Looked at XBee.h and discovered that the both #define SERIES_x were left defined so I commented out SERIES_2. Wouldn't compile after that due to a lot of callback methods not being defined so I assumed those were SERIES_2 and extended the #ifdefs to cover them. Still nothing.

Arduino + XBee S2B ZB : Failed when sending to a specific XBee address

Hello all,

My first words are to the amazing Andrew's work with the libraries to facilitate the use of XBee's.
I'm a newbie using XBee's and this library is an excellent tool! Thank you Andrew!

Now, my issue is, when using Arduino, I can't address to a specific XBee address.
When I try to send a packet to a specific XBee address it replies with "Failed to send packet. Status: 0xFF"

I'm using the "HelloSend.ino" sample code provided with the book Building Wireless Sensor Networks Using Arduino by Matthijs Kooijman. Thank you Matthijs.

(note: I'm using .txt extension files to be easier to post here)

Here is my code (I have changed only the addressing) to send a packet to the XCTU XBee Router address 0x0013A2004146B59A .

void sendPacket() {
    // Prepare the Zigbee Transmit Request API packet
    ZBTxRequest txRequest;

    txRequest.setAddress64(0x0013A2004146B59A);  //send packet to XCTU XBee Router

    uint8_t payload[] = {'X', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!'};
    txRequest.setPayload(payload, sizeof(payload));

    // And send it
    uint8_t status = xbee.sendAndWait(txRequest, 5000);
    if (status == 0) {
      DebugSerial.println(F("Succesfully sent packet"));
    } else {
      DebugSerial.print(F("Failed to send packet. Status: 0x"));
      DebugSerial.println(status, HEX);
    }
}

See full code here : HelloSend.txt

I also tried a different approach setting the address using XBeeAddress64:
XBeeAddress64 remoteAddress = XBeeAddress64(0x0013A200, 0x4146B59A);

Also gives me an error when assigning to a specific XBee address using Arduino!
Could anyone help me on what I'm doing wrong?

My best regards!

This is my scenario:

  • 3 XBees S2B
  • Firmware (send attached profile files):

ZigBee Coordinator API (connected to Arduino Uno): 0x0013A2004146B5F2
profile_23A7_Coordinator_0x0013A2004146B5F2.txt

ZigBee Router API (connected to Arduino Uno): 0x0013A2004146B626
profile_23A7_Router_0x0013A2004146B626.txt

ZigBee Router API (connected to XCTU): 0x0013A2004146B59A
profile_23A7_Router_0x0013A2004146B59A.txt

My Tests:

With XCTU XBee (ZigBee Router API ):

  • All XBee's are visible between each other.
  • sending message from XCTU XBee to all network XBee's (address 0x000000000000FFFF) , packets are received on all network XBee's (Arduino XBee Coordinator and XCTU XBee Router).
  • sending message from XCTU XBee Router to the Arduino Xbee Coordinator (address 0x0000000000000000) packet is received on Arduino XBee Coordinator.
    All works fine when addressing to 0x000000000000FFFF and 0x0000000000000000 using XCTU XBee Router!

With Arduino Xbee (ZigBee Router API ):

  • sending message from Arduino XBee Router to all network XBee's (address 0x000000000000FFFF) packets are received on all network XBee's (Arduino XBee Coordinator and XCTU XBee Router).
  • sending message from Arduino XBee Router to Arduino Xbee Coordinator (address 0x0000000000000000) , packets are received on Arduino XBee Coordinator.
    All works fine when addressing to 0x000000000000FFFF and 0x0000000000000000 using Arduino Xbee Router.

With Arduino Xbee (ZigBee Coordinator API ):

  • sending message from Arduino XBee Coordinator to all network XBee's (address 0x000000000000FFFF) packets are received on all network XBee's (Arduino XBee Router and XCTU XBee Router).

All works fine when addressing to 0x000000000000FFFF using Arduino Xbee Coordinator.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.