Question

I have two XBee Series 2 setup in mode API 2. One is setup as a controller and the other is setup as an end node. The end node is connected to an arduino and as of right now is just taking the value of an analog sensor and sending it out.

As of right now everything works when I am running the XBees through the X-ctu. In the new version, I add the controller module (on a USB explorer). I then click the middle button on the device that searches for other network devices. I then click the Console mode. Once I click the connect button I immediately start receiving the "Receive Packet". After looking at the frame details everything is in order.

The moment I attempt to use the xbee-api java library or the python-xbee library is when I start hitting issues. The code that I am using is completely copy pasted from the examples (they seem perfectly reasonable to work). Here is an example of the python code (Its COM3 on Windows and /dev/ttyUSB1. Both OSes have the same problem.)

from xbee import XBee
import serial
s = serial.Serial('COM3', 9600)
xbee = XBee(s)
while True:
  try:
    response = xbee.wait_read_frame()
    print(response)
except KeyboardInterrupt:
  break
s.close()

The applications hangs on xbee.wait_read_frame(). The java code works the same way when I call Xbee.open() when the code eventually gets to the line "sendAtCommand(new AtCommand("AP"));" (or using the sendSynchronous alternative). The method times out and throws an exception.

At this point, I have no idea where to go next. Works inside XCTU, but not any of the APIs. Is there something more that I need to do before the wait_read_frame to link the two together? (I assume not because they have the same pan id. In fact all settings other than the firmware is the same)

Thanks for any help!

Was it helpful?

Solution

Note that the XBee modules have two different API modes. ATAP=1 is the standard mode and ATAP=2 is an escaped mode.

You need to make sure that the code library you're using is configured to match the mode you've programmed on the XBee module.

In the case of python-xbee, you need to add escaped=True to your constructor. The Java library probably has something similar.

But, in my opinion there's no benefit to using escaped API mode. I recommend just setting ATAP=1 on the modules instead of trying to configure the libraries for escaped mode.

OTHER TIPS

Replace XBee by ZigBee.
On Windows machine, I am using Python 2.7.5
Try the example given below.

Code:

from xbee import  ZigBee
import serial
import time

port = serial.Serial(port='COM16',baudrate=9600,timeout=0)


xbee = ZigBee(port,escaped=True)

def filewrite(rcv):
    logfile = open("c:\\templog.txt","a")
    logfile.write(rcv)
    logfile.close



while True:

    recv = port.readline().strip()
    if (len(repr(recv)) > 2):
     try:
       response = xbee.wait_read_frame()
       filewrite(repr(response))
       print repr(response)
     except KeyboardInterrupt:
      break
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top