Get data from Xbee module

I have tried the following code to receive data from a xbee module and it works:

from socket import *
sd.bind( (‘00:13:a2:00:40:2c:93:34!’, 0xe8, 0, 0) )
while 1:
buf, addr = sd.recvfrom(128)
print “Recibido ‘%s’ de ‘%s’” % (buf, str(addr))

Now I need to receive data from other devices without pushing the SW1 button of the Xbee module.

How can I do this using python?

What kind of data? Serial data from an external device? Please explain in more detail.

Hi, im very new to this and just started using Zigbee … but i’ve gone thru the book and ran thru the tests etc. … what are the SW buttons on the development boards for?

What kind of data could i read from the nodes? I want to be able to write a program, upload it to the gateway and then run it on my pc like this hello world program given in the manual. Basically i want to be able to test how the nodes communicate with each other (mesh) and not with just the gateway (star).

Sorry for the basic knowledge … have never used this before.

yes can you tell me how this would be done using python please. i.e. receiving serial data from an external device.


The buttons are connected to pins 17-20 on the XBee. They are primarily used for testing purposes. You could use the buttons with IO sampling commands (IS, IR, IC, and D0,D1,D2,D3). For example, you could set D0-D3 as digital inputs (ATD03, ATD13, ATD23, ATD33) and then set IR to send IO samples to a remote (remote specified by DH and DL). Or instead of using IR, you could issue the IS command to query the IO lines on the local module. See the ZB manual for details.

Also, pin 20 on the XBee is the commissioning button (enabled by setting D0 to 1). If you press the button (connected to pin 20) 1 time, the XBee ZB will send a broadcast “Node Identification” transmission that causes the Associate LED on all other devices to blink rapidly for 1 second - to identify who is on the same network.

Hope that helps!

Thanks so much for that damons!!
Where can i access this ZB manual? The manual that came with the drop in networking kit i got doesnt seem to have much on how i can program with X-CTU.

Thanks everybody for posting in this topic.

I need a script in python that searches continuously for devices in the zigbee network without pushing the buttons SW1 or reset of the Xbee devices.

Any help will be appreciated!!!

Have you looked at the xbee/zigbee module? (The name changed recently from zigbee -> xbee).

This module contains a function called getnodelist(), which performs a discovery on the network and returns a list of node objects for each one found. The node objects contain the 64 bit address and can be transformed into a destination that is accepted by the zigbee socket sendto() function by using the to_socket_addr().

An example:

#> python

>>> import xbee
>>> dir(xbee)
[‘doc’, ‘name’, ‘package’, ‘ddo_command’, ‘ddo_get_param’, ‘ddo_set_param’, ‘get_node_list’, ‘getnodelist’,
‘register_joining_device’, ‘unregister_joining_device’]>>>
>>> node_list = xbee.getnodelist()
>>> for node in node_list:
… print node

>>> print dir(node)
[‘class’, ‘delattr’, ‘doc’, ‘format’, ‘getattribute’, ‘hash’, ‘init’, ‘new’, 'reduce
', ‘reduce_ex’, ‘repr’, ‘setattr’, ‘sizeof’, ‘str’, ‘subclasshook’, ‘addr_extended’, ‘addr_paren
t’, ‘addr_short’, ‘device_type’, ‘label’, ‘manufacturer_id’, ‘profile_id’, ‘to_socket_addr’, ‘type’]

There are a few sources of Python code for Xbees on the web.
Here are some links:

And some code that I have been using and modifying here:


I have a very simple example of a Python code which expects remote “serial” messages to show up from the XBee mesh, and it sends responses back to the “master/client/requester”. So the Python is the “server/slave” in the conversation.

(Technically, it expects Modbus/RTU serial requests, and uses Modbus/TCP to obtain an answer from a Modbus/TCP control device. The code runs on an X2 gateway).