ConnectPort X4 gateway + Retrieve asynchronous Data

I just bought the development kit from Digi that contains: ConnectPort X4 gateway, L/T sensor and Smart Plug.

My previous experience with xbees was the creation of a C# library to communicate with xbee nodes (Remote/ Queued/ Regular AT Commands, Send/ Receive Serial Data ). The communication was asynchronous (when a xbee sends a packet then i fired a new event).

I am not experienced with python. Is there any way to receive asynchronous without the IS command call?

The current version of my script calls function from DigiXBeeDrivers.zip library. Every time I call the sensor.sample() then the code blocks until the sensor’s response. The Smart Plug replies immediately but the L/T Sensor (uses sleep mode) replies when it wakes up. Thus, if i set the L/T Sensor to sleep for 1 min, i have to wait (in worst case) 1 min to retrieve data from Smart Plug.

My first thought was to use a different thread for each sensor. As I realized there is not enough memory in ConnectPort X4 gateway to afford the extra threads (is this right?).

Another thought was to keep a timer variable for each sensor and to call the sensor.sample() every time the sleep time expires (-1 sec). But i thing this is not a good idea (synchronization problems + difficulties with extra sensors).

Which is the best programmatic pattern for this case?

Easiest answer - set IR=0xFFFF, then every time the LTH Sensor wakes it will send you its data without you polling. Like magic, you’ll receive the IS ‘response’ without ever having sent the poll.

If you want to sleep longer than 65.5 seconds, then you need to use the SN/SP plus SO to cause it to sleep longer. For example, most of my LT/LTH Sensors wake only every 10, 15 or even 60 minutes.

Look up the ‘extended sleep cycle’ in the ZB manual.

You will also need to understand the use of SN/Sp in the X4! Read up on the ‘Child Poll Timeout’ section of the ZB manual, otherwise the X4 will NOT accept the IS data from the sensor.