ConnectPort X2B + Pikkerton ZBS-xxx

Hello,

I am currently trying to get sensor data from my zigbee-connected sensors into my ConnectPort X2B.
The Code i am currently working with is the following:


from socket import *
from select import *

# Create the socket, datagram mode, proprietary transport:
sd = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_APS)
# Bind to endpoint 0xe8 (232) for ZB/DigiMesh, but 0x00 for 802.15.4
sd.bind(("", 0x00, 0, 0))
# Configure the socket for non-blocking operation:
sd.setblocking(1)

try:
    # Initialize state variables: 
    payload = "GET
"
    erg = ""
    src_addr=("00:13:a2:00:40:5d:49:c4!",0,0,0)

    i = 1
    while 1:
        print "start new Measurement"
        # Reset the ready lists:
        rlist, wlist = ([], [])

        wlist = [sd]
        # Block on select: 
        rlist, wlist, xlist = select(rlist, wlist, [])

        # Send to the socket: 
        count = sd.sendto(payload, 0, src_addr)

        rlist, wlist = ([], [])

        rlist = [sd]

        # Receive from the socket: 
        erg, src_addr2 = sd.recvfrom(255)

        for temp in erg:
                print temp,

        i = i + 1
        if i > 2:
            raise Exception, "quit received"
 
except Exception, e:
    print e
    # upon an exception, close the socket:
    sd.close()

The Output would be for example:

payload: �l��)]@��

How may I transform this Output to get some useful info?

Ich hope you can help me.
Thanks in advance
Tim

Hello Timmiotoool,

I am not realy advanced with the connectport right now. But I looked up some things into the wiki from digi. http://www.digi.com/wiki/developer/index.php/Zigbee_Extensions_to_the_Python_socket_API

There I found some pieces of code that might help you. Even I tryed it with my ZBS-110

First. right now I dont know what you have requested. But it is not the “get” message.

please replace :

sd = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_APS)

with
sd = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_TRANSPORT)

sd.bind((“”, 0x00, 0, 0))

with
sd.bind((“”, 0xe8, 0, 0))

src_addr=(“00:13:a2:00:40:5d:49:c4!”,0,0,0)

with
src_addr=(“00:13:a2:00:40:5d:49:c4!”,0xe8,0xc105,0x11)

The received message will contain the measure values.

Example:
'POW=ON
FREQ=50.0625Hz
VRMS=229V
IRMS=0mA
LOAD=0W
WORK=0.000kWh

’ (ZBS-110)

I hope this will help you to get ahead and have a nice day.
If you have any questions please contact me.

Thanks Thomas.

I second your suggestions. The key problem Timmiotoool is having is he is binding (waiting) on a socket which will never receive any response - the sd.bind((“”, 0x00, 0, 0)) line.

It is like binding on TCP port 0 and then wondering why no HTTP web client can connet, because they will connect on port 80. (Actually TCP port 0 can’t be bind()'ed, but that’s a different issue).

One thing very helpful when trying to understand Python vs ZigBee issues is to use telnet to log onto the X2B, and then issue the command “set trace state=on mask=xbee:*”. You will then see a hex-dump of all Digi API frames being exchanged between the X2 and the internal XBee. The byte format is defined in the Digi Xbee ZB manual on the support site. Decoding the hex dump can be challenging, but at least you can see if a response arrives which doesn’t make it to Python due to bind() issues.