# Get data from Xbee module

**URL:** <https://forums.digi.com/t/get-data-from-xbee-module/2898>\
**Category:** Python\
**Created:** [March 30, 2009, 12:58am UTC](https://forums.digi.com/t/get-data-from-xbee-module/2898 "2009-03-30T00:58:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejo](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@Alejo](https://forums.digi.com/u/Alejo)\
**Post date:** [March 30, 2009, 12:58am UTC](https://forums.digi.com/t/get-data-from-xbee-module/2898/1 "2009-03-30T00:58:26Z")

</div>

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

from socket import \*  
sd = socket(AF\_ZIGBEE, SOCK\_DGRAM, ZBS\_PROT\_TRANSPORT)  
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?

---

<div class="post-metadata">

**Author:** ![lynnl](https://avatars.discourse-cdn.com/v4/letter/l/22d042/32.png) [@lynnl](https://forums.digi.com/u/lynnl)\
**Post date:** [March 30, 2009, 2:33pm UTC](https://forums.digi.com/t/get-data-from-xbee-module/2898/2 "2009-03-30T14:33:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![meme](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@meme](https://forums.digi.com/u/meme)\
**Post date:** [April 3, 2009, 5:54am UTC](https://forums.digi.com/t/get-data-from-xbee-module/2898/3 "2009-04-03T05:54:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![meme](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@meme](https://forums.digi.com/u/meme)\
**Post date:** [October 1, 2009, 5:08am UTC](https://forums.digi.com/t/get-data-from-xbee-module/2898/4 "2009-10-01T05:08:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damons](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@damons](https://forums.digi.com/u/damons)\
**Post date:** [April 8, 2009, 2:23am UTC](https://forums.digi.com/t/get-data-from-xbee-module/2898/5 "2009-04-08T02:23:42Z")

</div>

Hello,

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!

---

<div class="post-metadata">

**Author:** ![meme](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@meme](https://forums.digi.com/u/meme)\
**Post date:** [April 16, 2009, 6:20am UTC](https://forums.digi.com/t/get-data-from-xbee-module/2898/6 "2009-04-16T06:20:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Admin1](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@Admin1](https://forums.digi.com/u/Admin1)\
**Post date:** [April 17, 2009, 7:12pm UTC](https://forums.digi.com/t/get-data-from-xbee-module/2898/7 "2009-04-17T19:12:55Z")

</div>

[http://ftp1.digi.com/support/documentation/90000976\_C.pdf](http://ftp1.digi.com/support/documentation/90000976_C.pdf)

---

<div class="post-metadata">

**Author:** ![Alejo](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@Alejo](https://forums.digi.com/u/Alejo)\
**Post date:** [April 20, 2009, 1:03am UTC](https://forums.digi.com/t/get-data-from-xbee-module/2898/8 "2009-04-20T01:03:36Z")

</div>

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!!!

---

<div class="post-metadata">

**Author:** ![Mawr](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@Mawr](https://forums.digi.com/u/Mawr)\
**Post date:** [April 20, 2009, 1:10am UTC](https://forums.digi.com/t/get-data-from-xbee-module/2898/9 "2009-04-20T01:10:37Z")

</div>

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’]  
\>\>\>

---

<div class="post-metadata">

**Author:** ![waltr](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@waltr](https://forums.digi.com/u/waltr)\
**Post date:** [October 1, 2009, 4:00pm UTC](https://forums.digi.com/t/get-data-from-xbee-module/2898/10 "2009-10-01T16:00:26Z")

</div>

mem,  
There are a few sources of Python code for Xbees on the web.  
Here are some links:  
[http://blogs.nyu.edu/blogs/as860/iameat/2008/04/serial.html](http://blogs.nyu.edu/blogs/as860/iameat/2008/04/serial.html)

[http://forums.trossenrobotics.com/tutorials/how-to-diy-128/xbee-basics-3259/](http://forums.trossenrobotics.com/tutorials/how-to-diy-128/xbee-basics-3259/)

[http://rubenlaguna.com/wp/2009/03/12/example-of-xbee-api-frames/](http://rubenlaguna.com/wp/2009/03/12/example-of-xbee-api-frames/)

[http://lizard43.blogspot.com/2009/04/xbee-series-2-reading-data-in-api-mode.html](http://lizard43.blogspot.com/2009/04/xbee-series-2-reading-data-in-api-mode.html)

And some code that I have been using and modifying here:  
[http://code.google.com/p/python-xbee/source/browse/trunk/xbee2.5/?r=6](http://code.google.com/p/python-xbee/source/browse/trunk/xbee2.5/?r=6)

wr

---

<div class="post-metadata">

**Author:** ![lynnl](https://avatars.discourse-cdn.com/v4/letter/l/22d042/32.png) [@lynnl](https://forums.digi.com/u/lynnl)\
**Post date:** [October 1, 2009, 4:06pm UTC](https://forums.digi.com/t/get-data-from-xbee-module/2898/11 "2009-10-01T16:06:15Z")

</div>

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).

[http://www.digi.com/wiki/developer/index.php/Modbus\_Example\_Ethernet\_Adapter](http://www.digi.com/wiki/developer/index.php/Modbus_Example_Ethernet_Adapter)

[http://www.digi.com/wiki/developer/images/e/e8/X2\_mbus\_2009Sep13.zip](http://www.digi.com/wiki/developer/images/e/e8/X2_mbus_2009Sep13.zip)
