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