user2725109 user2725109 - 2 months ago 13
Python Question

xbee.remote_at not working

I am using python-xbee to work with XBee modules (Python 2.7). I have an XBee (coordinator) directly connected to my laptop through a serial port and another separate one (endpoint). I can easily communicate with them both using the

at
command, but I can't communicate with them using
remote_at
.

When I run

import serial
from xbee.zigbee import ZigBee
import time

PORT = '/dev/ttyUSB0'
BAUD_RATE = 9600

def print_xbee_data(data):
print(data)

serial_port = serial.Serial(PORT, BAUD_RATE)
# For some reason escaped=True does not work
xbee = ZigBee(serial_port, escaped=True, callback=print_xbee_data)

xbee.send('at', frame='a', command='nd', parameter=None)

# Delay: to wait to keep the thread running to receive the response(s)
time.sleep(5)


The output is:

{'status': '\x00', 'frame_id': '\x01', 'parameter': {'status': '\x00', 'source_addr': 'a\xd4', 'parent_address': '\x00\x00', 'profile_id': '\xc1\x05', 'source_addr_long': '\x00\x13\xa2\x00@0\xbd@', 'device_type': '\x02', 'node_identifier': ' ', 'manufacturer': '\x10\x1e'}, 'command': 'ND', 'id': 'at_response'}


But when I run (I am using both escaped and not-escaped address formats just to be sure)

xbee.remote_at(dest_addr=b'a\xd4', command='MY')
xbee.remote_at(dest_addr=b'\x61\xd4', command='MY')
xbee.send('remote_at',
frame_id='A',
dest_addr_long='\x00\x13\xa2\x00@0\xbd@',
dest_addr='a\xd4',
options='\x02',
command='D0',
parameter='\x02')
xbee.send('remote_at',
frame_id='A',
dest_addr_long='\x00\x13\xa2\x00\x40\x30\xbd\x40',
dest_addr='\x61\xd4',
options='\x02',
command='D0',
parameter='\x02')

time.sleep(5)


I get no output.


  • Why doesn't
    escaped=True
    work?

  • Why don't I get any output?

  • How can I go about fixing the problem?



Thanks a lot.

Answer

remote_at requires a non-zero frame_id to return a response. Run:

xbee.remote_at(dest_addr='\x61\xd4', command='MY', frame_id='A')

and the output is:

{'status': '\x00', 'source_addr': '\x00\x00', 'source_addr_long': '\x00\x13\xa2\x00@\n\x05\xab', 'frame_id': 'A', 'command': 'MY', 'parameter': '\x00\x00', 'id': 'remote_at_response'}

Although the status is OK ('status': '\x00') the above command is not doing what we want. Here 'source_addr_long': '\x00\x13\xa2\x00@\n\x05\xab' is the address of local XBee (coordinator). In order for the command to do what we want it to (send MY command to the remote device) we MUST specify the 64-bit address (long). Therefore the correct command is:

xbee.remote_at(dest_address_long='\x00\x13\xa2\x00@0\xbd@', dest_addr='a\xd4', command='MY', frame_id='A')

Replacing dest_addr='a\xd4' with dest_addr='\xff\xfe works, too.