Cannot send / receive using Xbee in API mode (python)

I have two Xbee Pro 900s, each of which is attached to a Raspberry Pi. Both updates are updated to version 1061 and are installed in the Enable API with screens. They also have the same 7FFF modem VID. Both Pi have PySerial and the python-xbee library is installed.

Xbee 1 (Receiver) has serial number 0013A200409A1BB8
Xbee 2 (Sender) has serial number 0013A200709A1BE9

I have included my code below, which is just an example of the code I found on the Internet. My problem is that I am not getting anything from the corresponding Xbee. I absolutely do not know what is wrong, I checked the triple destination address and both Xbee configuration parameters.

Xbee 2 Code (Sender):

#! /usr/bin/python import time from xbee import XBee import serial PORT = '/dev/ttyUSB0' BAUD_RATE = 9600 # Open serial port ser = serial.Serial(PORT, BAUD_RATE) # Create API object xbee = XBee(ser,escaped=True) import pprint pprint.pprint(xbee.api_commands) DEST_ADDR_LONG = "\x00\x13\xA2\x00\x40\x9A\x1B\xB8" # Continuously read and print packets while True: try: print "send data" xbee.tx_long_addr(frame='0x1', dest_addr=DEST_ADDR_LONG, data='AB') time.sleep(1) except KeyboardInterrupt: break ser.close() 

Xbee 1 Code (Receiver):

 #! /usr/bin/python from xbee import XBee import serial PORT = '/dev/ttyUSB0' BAUD_RATE = 9600 # Open serial port ser = serial.Serial(PORT, BAUD_RATE) # Create API object xbee = XBee(ser,escaped=True) # Continuously read and print packets while True: try: print "waiting" response = xbee.wait_read_frame() print response except KeyboardInterrupt: break ser.close() 

When both programs are running, the Tx light on the sending Xbee flashes, but I receive nothing on the receiving Xbee. Is there something I'm missing? Thank you for your time!

+4
source share
2 answers

Are you using XBee or XBeePro? I had the same problem and this post helped me a lot.

Try changing the receiver code as follows:

 import config import serial import time from xbee import ZigBee def toHex(s): lst = [] for ch in s: hv = hex(ord(ch)).replace('0x', '') if len(hv) == 1: hv = '0'+hv hv = '0x' + hv lst.append(hv) def decodeReceivedFrame(data): source_addr_long = toHex(data['source_addr_long']) source_addr = toHex(data['source_addr']) id = data['id'] samples = data['samples'] options = toHex(data['options']) return [source_addr_long, source_addr, id, samples] PORT = '/dev/ttyUSB0' BAUD_RATE = 9600 # Open serial port ser = serial.Serial(PORT, BAUD_RATE) zb = ZigBee(ser, escaped = True) while True: try: data = zb.wait_read_frame() decodedData = decodeReceivedFrame(data) print decodedData except KeyboardInterrupt: break 

In my case, the above code outputs the following:

 [['0x00', '0x13', '0xa2', '0x00', '0x40', '0x9b', '0xaf', '0x4e'], ['0x68', '0x3f'], 'rx_io_data_long_addr', [{'adc-0': 524}]] 

Here I shared the configuration settings for the Node controller (compatible with X-CTU)

+1
source

Are you sure the XBee modules are in API mode ( ATAP=2 )? And 9600 baud?

Can you turn on mode in python-xbee to discard all characters and exit?

Have you confirmed the correct serial wiring? (I see that you are using USB, so this is not a problem.)

If you do not have hardware flow control, make sure that the XBee modules are set to ATD6=0 and ATD7=0 (RTS and CTS are disabled), and that python-xbee does not wait for confirmation of the connection.

If you have hardware flow control configured on XBee, make sure you tell python-xbee to use it.

Can you use a minicomputer or other serial terminal on RaspPi to confirm that the serial number is working? Use minicom on the receiving side to see if you get anything at all?

Can you try sending and receiving using radio stations connected to a PC instead of a Pi? Sending from PC to Pi or vice versa?

0
source

All Articles