This article explains how to configure a Python application''s socket connection so that it waits to hear back from the zigbee end device before proceeding. This is opposed to normal behavior, which is simply sending the data down to the zigbee layer, which is still the localhost, and assuming that it will get to the zigbee end device successfully.
Normally, python application run on Digi gateways (ConnectPort X2, X4, X8, etc). The gateways will talk to various end nodes using zigbee. By using python, the gateways, have more flexibility on how they can gather and manage end data from the various end nodes.
One of the challenges that goes with this model is communicating over zigbee. Due to it's sometimes "non-deterministic" behavior (high latency and low data rates for example), data can sometimes be lost when attempting to communicate to end devices. Although zigbee does have an acking mechanism, which allows it to resend data that isn''t acknowledged, the python applciation doesn''t always know what''s happening.
In order to enable Zigbee layer ack waiting do this:
>>> from socket import *
>>> import xbee
>>> s = socket(AF_XBEE, SOCK_DGRAM, XBS_PROT_TRANSPORT)
>>> s.bind(('''', 0xe8, 0, 0))
>>> s.setsockopt(ZBS_SOL_EP, XBS_SO_EP_SYNC_TX, 1)
Then send your data. If it's successfully received, the end device will send an Ack. The Python application will then receive it and then continue from it's sendto() function.
Last updated:
Jan 01, 2024