Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send strings of data to an XBee with a python library?

Tags:

python

xbee

Which library should I be using, and how?

Python XBee seems to be only able to send commands in API mode, and I can't find an example of anyone using it to send a string. Maybe I'm misunderstanding what API mode is, but I can't find a payload in the documentation...

Are Digi's Python Socket extensions baked into Python? I can't seem to get any of the constants they claim to have defined in my Python (2.7.3rc2), nor can I find a mention of how to get these extensions on their site. It seems like that could be a way to pass around strings, but how do I use it?

like image 924
Valkyrie Savage Avatar asked Nov 18 '12 01:11

Valkyrie Savage


1 Answers

If the Xbee is connected to the computer as a serial device you can just use a serial library such as pySerial. Here are some code snippets from a project I just finished.

# Connect to Xbee
self.ser = serial.Serial(port, baud, timeout=timeout)

# Send data (a string)
self.ser.write(packet)

# Read data
self.data += self.ser.read()

We were using the Xbees in transparent mode - each byte you write on one end is visible on the other end with a read. There was no need for a special Xbee library.

like image 139
Tim Avatar answered Sep 27 '22 21:09

Tim