PC as Python Gateway

Is it possible to use a PC and USB connected Xbee as a Python gateway ?

I have an X4 gateway and the python scripts I upload are dependent upon a builtin module named _zigbee. This module support commands such as ddo_get_param ddo_set_param.

In the DIGI supplies python modules there is no PC host equivalent module, or if there is, where is it and how to I map my /dev/tty device to this module ?

If this is unclear, what I would like to do is for example execute ‘Python Drivers for Digi Adapters’\lt_sensor.py from a PC host.


I have partially solved this. Within the embedded kit gateway viewer is a zigbee.py.zip. This contains two files which allow a PC host to execute gateway python files locally.

The only issue I have found is that in using the DigiXBeeDrivers the checks for product types in xbeeprodid.py return different values on the PC compared with running on my X4 gateway and appears to be as a result of differences in struct.unpack. As I am new to the Python world I am still working through how to fix this.




Interesting - I didn’t know Digi had put that out into the wilds. To reiterate what Deancs is saying.

On the CP-X gateway there is a zigbee.py file, which is only a few lines of interface since the core get/set DDO functions are part of the RTOS on the gateway; thus there is no need to actually implement them in Python script.

In the ZIP file Deancs mentions is a second ZIP file called zigbee_py.zip which contains a real Python script of the same name. It does similar functions on a PC via an attached RS-232 based XBee module (such as a development board or XBee RS-232 adapter). Plus you don’t even need to use or understand most of the “Embedded Kit Gateway Viewer” - all you need is the zigbee.py file.

The only issue I remember with this module is the UDP-like ZB Socket it creates won’t return all the exact same errors & timing behavior as the one on the gateway. This is because the ZB-style socket is part of the TCP/IP stack within the gateway, whereas in the zigbee.py module is only simulated - but that doesn’t stop it from being very useful.

To demonstrate how easy these modules make retrieving data on a PC I have included a tiny python script that retrieves the temperature and light from a DIGI LT Sensor and DIGI Router module. As lynnl stated there are some differences in behaviour when running these on a gateway vs a PC, however in my case I require logging to an SQL database and therefore these modules have simplified the process significantly.

I have 5 modules retrieving 3 analogue sources every 10 seconds and writing these to a timestamped rows on MySQL. That equates to 129K rows per day, and although still prototype these has been working faultlessly.

The zigbee_py.zip file mentioned above is actually found within the source code zip file for the Embedded Kit Gateway Viewer. The source code is found here:


The text file in this source code says that it doesnt need zigbee_py.zip file to run the embedded_kit_pc application and that it’s there for our convenience. I am trying to alter the code (embedded_kit_pc file code) so that it can decode data that my Xbee dev. boards are receiving from a 3rd party device i have connected it to. Can you please give me some directions on where i can do this on the source code please? I’m having difficulty trying to find the right place to start making changes. Hope you can help me please!

I am not sure if I fully understand what you are trying to do. Is the third party device a sensor interfaced to an XBee module or a 3rd party XBee style RF device ?

If its an XBee device then the link below provides the DIGI drivers and samples for reading and decoding data received from DIGI adapters. For example if the device is a DIGI LT Sensor then in addition to zigbee.py you would require xbeelt.py and sensor_io.py.


The getXBeeData.py code sample (link below) I have posted previously in this thread is an example of using these together to retrieve temperature from an XBee module using a PC Host and a USB Dev board.

When I was working through the learning for me was the XBee IS command returns a data block which is a sample of all active A/D channels on the XBee Device. Using sensor_io.py/parse_IS properly decodes each of the A/D channels.

Sorry, let me clarify myself.

I have 2 RS232 Dev. boards (from the Professional drop in networking kit) both having Xbee modules (ZNet 2.5, router/end device AT firmware). My 3rd party devices are gas sensors (not from Digi, they’re made from a different company). These sensors are connected to the Xbee dev. boards via rs232.

I’m using the embedded kit gateway viewer application (aka PC companion application) that came with the drop in networking kit. I want to view what’s entering the serial terminal of the Xbee modules via the serial tab on the gateway viewer application program. The Xbee modules are in AT mode, and so the problem i’m getting is that the data that’s going out of the sensors is not formatted properly…i’m getting funny characters when i view the data on the serial tab in the program. I know how to decode the data, but i’m having difficulty trying to find where in the source code i should edit/add code to decode my data. The txt file in the source code says this:
“zigbee_py.zip can be used to create and run python code on your PC, to eventually be ported to your Digi python-enabled Gateway product. This file is not required for operation of the Embedded Kit Gateway Viewer app or source code, and is provided for your convenience in working with Digi products only.”

I’ve looked through the rest of source code and im having difficulty finding where i should start editing code to decode my data. Would you be able to point me in the right direction or give me some advice please!!

If your sensors are outputting asyncronous data suitable for sending to an RS232 adapter, what baud rate, parity, and number of stop bits do they use?

If they don’t support those options, are you sure they’re outputting serial data, rather than an analog signal or something?

The sensors are outputting data using the following:
baude rate = 9600
Data bits = 8
Stop Bits = 1
Parity = none
Flow Control = none

With those settings, provided the module settings match it should work fine. Have you tried connecting the sensor to the comm port on a laptop and see if you get “clean” data there? That would be a good sanity check.

Yes i have tested this on a com port and i am able to get data there. This data is in ascii format tho, but it’s correct when i decode it. So why doesnt it come out the same way in the PC companion application? I thought AT mode should send out whatever data it receives just as it is??? So there must be some sort of decoding done to the data. Can you tell me what it is please?

Can you share how you actually accomplished this?