Python script for receiving messages in connectport x8

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.

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:> telnet 192.168.1.1
#> python example1.py

Hello, world.

#>

Do you see the output?

Jordan

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

Hi Jordan

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

Thank you

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

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

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

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

Any suggestion?

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.