niolabs / python-xbee

Python tools for working with XBee radios
MIT License
101 stars 45 forks source link

wait_read_frame() bad caharacter #60

Closed hassansofla closed 6 years ago

hassansofla commented 6 years ago

I tried to send a node discovery command and read it but it seems always there is a specific portion that consistently misses. My program is as follows: ser = serial.Serial(XBEEPORT, XBEEBAUD_RATE) zb = ZigBee(ser) zb.send('tx_explicit', dest_addr_long = \x00\x00\x00\x00\x00\x00\xff\xff, dest_addr = \xff\xfe, src_endpoint = '\x00', dest_endpoint = '\x00', cluster = '\x00\x31', profile = '\x00\x00', data = '\xf0'+'\x00' )
time.sleep(5) data1 = zb.wait_read_frame() print data1

Every time and always some hex portions are missed, in one hex portion there is a "o" printed after the hex like /x4Go/, and one hex portion is always printed like /r/ and always one hex portion is completely missed. Here is the output: {'profile': '\x00\x00', 'source_addr': '\x00\x00', 'dest_endpoint': '\x00', 'rf_data': '\xf0\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\xb8o\x05\xfe\xff\xb9\r\xe2\x8e\x1f5\x02\x0f\xf1', 'source_endpoint': '\x00', 'options': '\x01', 'source_addr_long': '\x00\x13\xa2\x00@\xad\xbc\xb8', 'cluster': '\x801', 'id': 'rx_explicit'}

So these bytes \xb8o\x05\xfe\xff\xb9\r\xe2 are supposed to show id of the node. but you can see that one segment was lost shown as \r\ and another segment was lost between first and second segment, you can see the second segment is wrong \xb8o\

Also, the same frame in XCTU works fine. The device I am using is S2, and in XCTU and also in python I can send other commands like on off to the device.

jamesleesaunders commented 6 years ago

One of the most common reasons for unpredicted frames is when the Xbee API settings are not correct.

What AP and AO settings have you got?

Try: API Enable (AP): 2 API Output Mode (AO): 3

Depending on what the above is you may also need to play with the ‘escaped=true’ setting when when constructing in Python.

ser = serial.Serial('/dev/ttyUSB0', 9600) xbee = ZigBee(ser, escaped=True)

Also see: https://github.com/niolabs/python-xbee/issues/26

hassansofla commented 6 years ago

Thanks for getting back to me. Past days I have been trying to try those settings and also other settings (for example digi says to use AP: 1 here ) Anyways, I still get bad characters/bytes. I read in one of the issues that asynchronous callback may be needed. I tried that but it never returns. Kinda stuck here if anyone can help appreciated.

hassansofla commented 6 years ago

The characters are right but in ascii not in hex, it's due to PySerial. Library is fine. We should close this issue.

jamesleesaunders commented 6 years ago

Cool. Glad you figured it out. Thanks for reporting your findings.