1

I am using python-xbee and Python 3.7 to send API commands from an XBee connected to UART1 on a Beaglebone Black to a remote XBee. Both are Version 1 Pro models.

My remote XBee (the one I am sending commands to) has the following address:

SH=0013A200
SL=40DD7DCD

When I submit a command using the low portion of the 64-bit address

xbee.remote_at(dest_addr='\x40\xDD\x7D\xCD', command='0x17', parameter=D0_LOW, frame_id='A')

I receive the error:

UnicodeEncodeError: 'ascii' codec can't encode character '\xdd' in position 1: ordinal not in range(128)

My code is as follows:

from xbee import XBee from serial import Serial

PORT = '/dev/ttyO1' 
BAUD = 9600

# Send 0x17 AT command with parameter 04 for low (off), 05 for high (on)
# D0=4 Low
# D0=5 High

D0_LOW = 4 
D0_HIGH = 5

ser = Serial(PORT, BAUD)

xbee = XBee(ser)

xbee.remote_at(dest_addr='\x40\xDD\x7D\xCD', command='0x17', parameter=D0_LOW, frame_id='A')
# Wait for and get the response

print(xbee.wait_read_frame())

ser.close()

My question is this - what is the correct format for the dest_addr when the upper and lower bytes are known and no controller is being used (point-to-point only)?

If I change the address to use hex (e.g. \0x40\0xDD\0x7D\0xCD) then the error message is

The data provided for 'dest_addr' was not 2 bytes long

Do I need to format the address to ASCII 2 bytes?

tomlogic
  • 11,489
  • 3
  • 33
  • 59
Not a machine
  • 508
  • 1
  • 5
  • 21

3 Answers3

0

I think that you may be running into issues because your dest_addr is a regular python string as opposed to a byte string. You should try the following.

xbee.remote_at(dest_addr=b'\x40\xDD\x7D\xCD', command='0x17', parameter=b'\x04', frame_id='A')
Max Feinberg
  • 810
  • 1
  • 6
  • 21
  • Thanks Max. I tried that and I receive the same error - The data provided for 'dest_addr' was not 2 bytes long. – Not a machine May 23 '20 at 01:29
  • Looking at the documentation, the address should indeed only be 2 bytes while it's currently specified as 4 bytes. Can you try running `xbee.send("at", frame='A', command='MY')` and see what it returns? – Max Feinberg May 23 '20 at 01:39
  • The documentation is horrid! It doesn't explain how to derive a 2 byte address from a 64-bit address. Running that command waits indefinitely. – Not a machine May 23 '20 at 02:00
  • Is there a reason you're not using the digi-xbee library? – Max Feinberg May 23 '20 at 02:23
  • I would love to but the documentation isn't any better. I'll have a go at it tomorrow and see if it makes more sense. Long week! – Not a machine May 23 '20 at 02:52
  • @Notamachine I actually think that the digi-xbee library is quite well documented: https://xbplib.readthedocs.io/en/latest/user_doc/configuring_the_xbee_device.html – Max Feinberg May 23 '20 at 03:09
  • 1
    Let me re-phrase. There is a massive amount of documentation available. The flow is not intuitive to me. I prefer overview plus examples which are more than 3 lines. It doesn't mean the documentation it bad. It just isn't a good fit for the way I learn. As a researcher, I am used to ingesting very large quantities of information in a short period of time - but each person is different. – Not a machine May 24 '20 at 04:22
  • @"Max Feinberg" if you know where in the digi-xbee library docs it describes how to load the module containing IOLine I would be obliged. I have been going in circles trying to find it. – Not a machine Jun 05 '20 at 05:04
0

From the documentation:

A listing of all supported data frames and their respective fields may be found in xbee.ieee.XBee (or xbee.zigbee.ZigBee for XBee ZB devices) defined as api_responses.

Perhaps you can use help(xbee.ieee.XBee) or help(xbee.zigbee.ZigBee) (or even help(xbee.remote_at)) for a list of the methods and their parameters.

I also saw a source_addr_long on that page, so perhaps you can specify a dest_addr_long for your remote_at() call.

tomlogic
  • 11,489
  • 3
  • 33
  • 59
0

The answer is as follows:

remote_xbee='40DD7DCD'
frame_id = b'\x01'

#For D0 Off
xbee.remote_at(dest_addr_long=remote_xbee,command='D0',parameter='\x04', frame_id=frame_id)
Not a machine
  • 508
  • 1
  • 5
  • 21