# Python script for receiving messages in connectport x8

**URL:** <https://forums.digi.com/t/python-script-for-receiving-messages-in-connectport-x8/2679>\
**Category:** Python\
**Created:** [December 24, 2008, 12:44am UTC](https://forums.digi.com/t/python-script-for-receiving-messages-in-connectport-x8/2679 "2008-12-24T00:44:47Z")\
**Posts on this page:** 9\
**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:** [December 24, 2008, 12:44am UTC](https://forums.digi.com/t/python-script-for-receiving-messages-in-connectport-x8/2679/1 "2008-12-24T00:44:47Z")

</div>

Is there anyone who can help me with the python script where the messages from an xbee module are received in the connectport x8? I need to know the python script where the messages from the xbee module are received in the CP x8. I need to know where this is done (the method or routine) becasue I need to customize the action and sent data to another application outbound. I see when I press the switch1 in the xbee module that the ACT led on front of the connectport x8 flashes. I really dont need to monitor the led, but i do need to know where the messages are received in the CP x8.  
Thanks a lot.

---

<div class="post-metadata">

**Author:** ![jordanh](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@jordanh](https://forums.digi.com/u/jordanh)\
**Post date:** [December 24, 2008, 1:04am UTC](https://forums.digi.com/t/python-script-for-receiving-messages-in-connectport-x8/2679/2 "2008-12-24T01:04:12Z")

</div>

I can help you. Have you tried to write a simple Python script on the ConnectPort X8 in order to become comfortable with out the Python feature works on the product?

For example, if you create a file “example1.py” with the following:

print “Hello, world.”

And if you upload this file to the ConnectPort X8 and upload it using the form under Applications-\>Python and run it from the ConnectPort X8’s firmware command line:

C:&gt; telnet 192.168.1.1  
#\> python example1.py

Hello, world.

#\>

Do you see the output?

Jordan

---

<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:** [January 15, 2009, 11:29pm UTC](https://forums.digi.com/t/python-script-for-receiving-messages-in-connectport-x8/2679/3 "2009-01-15T23:29:35Z")

</div>

I tried the script and works with the xbee module. Now I need to communicate the cp x8 with a microchip node. Does anyone know how to do this? Because if I use the same script, it waits for the data forever.

Thanks

---

<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:** [December 24, 2008, 1:42am UTC](https://forums.digi.com/t/python-script-for-receiving-messages-in-connectport-x8/2679/4 "2008-12-24T01:42:00Z")

</div>

Hi Jordan

I created the file that you said and I can see the output.

Thank you

---

<div class="post-metadata">

**Author:** ![jordanh](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@jordanh](https://forums.digi.com/u/jordanh)\
**Post date:** [December 24, 2008, 1:56am UTC](https://forums.digi.com/t/python-script-for-receiving-messages-in-connectport-x8/2679/5 "2008-12-24T01:56:20Z")

</div>

Alright, then the next step is easy. Let’s receive a frame using Python.

Create a file “xbee\_ex1.py” and enter the following lines of Python:

[pre]  
from socket import \*

sd = socket(AF\_ZIGBEE, SOCK\_DGRAM, ZBS\_PROT\_TRANSPORT)  
sd.bind( (‘’, 0xe8, 0, 0) )

while 1:  
buf, addr = sd.recvfrom(128)  
print “Received ‘%s’ from ‘%s’” % (buf, str(addr))  
[/pre]

Upload this script and run it by telnetting to the ConnectPort X8.

#\> python xbee\_ex1.py

If you set the DH and DL parameters of your _remote_ XBee to be the high 32-bits and low 32-bits of the gateways address, you should see the frames containing the characters of data you give to the remote XBee for transmission.

Please try this example and cut and paste the output. I can explain to you what the fields in the address structure mean.

Note: if you are using Series 1 radios and the Digi 802.15.4 firmware, you will have to change 0xe8 to 0x0 in the code above.

Jordan

---

<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:** [December 29, 2008, 5:28pm UTC](https://forums.digi.com/t/python-script-for-receiving-messages-in-connectport-x8/2679/6 "2008-12-29T17:28:09Z")

</div>

Hi Jordan, I got the following output:

Traceback :  
File “”, line 4, in ?  
File “”, line 1, in bind  
socket.error: \<22, ‘Invalid argument’\>

Before, I have tried more examples with lines like sd = socket(AF\_ZIGBEE, SOCK\_DGRAM, ZBS\_PROT\_APS), but I am  
not really sure if that is supported, because the errors indicates that in the **init** is not define the options  
AF\_ZIGBEE and SOCK\_DGRAM. If I go to zb\_tcp\_serial/socket.py, I can see:

```
def __init__ (self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None):
    if _sock is None:
        _sock = _realsocket(family, type, proto)
    self._sock = _sock
    self.send = self._sock.send
    self.recv = self._sock.recv
    self.sendto = self._sock.sendto
    self.recvfrom = self._sock.recvfrom

```

So, I presume that when it going to search AF\_ZIGBEE in the code, it cannot find it.

I don’t know if I am ok, any help I will appreciated.

Thank you

---

<div class="post-metadata">

**Author:** ![jordanh](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@jordanh](https://forums.digi.com/u/jordanh)\
**Post date:** [December 29, 2008, 5:35pm UTC](https://forums.digi.com/t/python-script-for-receiving-messages-in-connectport-x8/2679/7 "2008-12-29T17:35:39Z")

</div>

I believe the problem is that you have a Python script already running.

Please use the ConnectPort X8’s web interface to find Applications-\>Python-\>Auto-start settings and disable any script that may be auto starting by unchecking the checkbox.

Jordan

---

<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:** [December 29, 2008, 6:59pm UTC](https://forums.digi.com/t/python-script-for-receiving-messages-in-connectport-x8/2679/8 "2008-12-29T18:59:29Z")

</div>

I unchecked all the scripts that were in the auto-start but nothing happens.

Any suggestion?

---

<div class="post-metadata">

**Author:** ![52637p](https://avatars.discourse-cdn.com/v4/letter/5/c6cbf5/32.png) [@52637p](https://forums.digi.com/u/52637p)\
**Post date:** [December 29, 2008, 7:19pm UTC](https://forums.digi.com/t/python-script-for-receiving-messages-in-connectport-x8/2679/9 "2008-12-29T19:19:04Z")

</div>

Did you reboot after unchecking them? The auto-start setting affects the running of the script at boot time… it does not affect the state of an already running script.

If you continue to have difficulty, it would also be interesting to see the “connection list” from the webUI, or the “who” output from the CLI. It will normally give an indication of all running Python threads.
