Python xbee device.read_data doesn't read pushed remote data

I have set up several XBee S3Cs to sample analog pins 1 and 2 every 15 seconds with the destination address of another S3C set up as coordinator. I can see the frames–IO Data Sample RX Indicators–in XCTU and there is a value for the pins (1023 since nothing is attached to them yet). When I try to read the frame in a Python script (below), it never seems to get the data.

I believe the correct port is being opened because the program gives an error is XCTU is still connected and XCTU won’t connect if the program is running.

CE = Standard Router [0]
CI = 11
AP = API Mode without escapes [1] (but I’ve tried 2 as well)
AO = API Rx Indicator - 0x90 [0] (but I’ve tried 1 as well)

Any thoughts?

Copyright 2017, Digi International Inc.

Permission to use, copy, modify, and/or distribute this software for any

purpose with or without fee is hereby granted, provided that the above

copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES

WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF

MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR

ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES

WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN

ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF

OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

from digi.xbee.devices import XBeeDevice

TODO: Replace with the serial port where your local module is connected to.

PORT = “COM4”

TODO: Replace with the baud rate of your local module.

BAUD_RATE = 9600

def main():
print(" ±------------------------------------------------+“)
print(” | XBee Python Library Receive Data Polling Sample |“)
print(” ±------------------------------------------------+
")

device = XBeeDevice(PORT, BAUD_RATE)

try:
    device.open()

    device.flush_queues()

    print("Waiting for data...

")

    while True:
        xbee_message = device.read_data()
        # xbee_message = device.read_expl_data()
        if xbee_message is not None:
            print("From %s >> %s" % (xbee_message.remote_device,
                                     xbee_message.data()))


finally:
    if device is not None and device.is_open():
        device.close()
2 Likes