Home/Support/Support Forum/how to detect I/O pin changes using python XBeeDevice.add_io_sample_received_callback()
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

how to detect I/O pin changes using python XBeeDevice.add_io_sample_received_callback()

0 votes
I want to have a callback function invoked whenever a digital input changes state. This seems quite straightforward from the XBee python library example, which I have used as my template:

def io_callback(io_sample: IOSample, remote_xbee, send_time):
logger.debug("io_callback called!")
logger.debug(f"sample value is {io_sample.get_digital_value(IOLine.DIO4_AD4)}")

device.set_io_configuration(IOLine.DIO4_AD4, IOMode.DIGITAL_IN)

However, when I trigger the DIO4 (press the user button), it seems to always send the message to the DH,DL destination address, and my host callback doesn't get invoked. I'd like to:

a) not send anything to DH,DL
b) have my callback invoked

As it happens, I can achieve this simply by setting DH/DL to the local device. I was wondering if there is a better way to achieve this? Especially, if I want to decouple behaviour a) from behaviour b). For example, I might want my callback to implement some logic based on the received data before deciding whether the destination device should know anything about it. I suppose I could poll or wait on another thread, but I can't help thinking I'm missing a simple setting.
asked Aug 10 in Python by eulerlagrange New to the Community (2 points)

Please log in or register to answer this question.

1 Answer

–1 vote

answered Aug 10 by mvut Veteran of the Digi Community (13,036 points)
Could you elaborate how that relates to my query? which is basically: (having configured my pins correctly) is there a way to have a callback invoked (without having to set the DH/DL to the local device)?
The point I was trying to make is to use the right calls to view the inputs. Setting it the way you have is doing it just the way the firmware is designed to do it. That is, send it to the DL and DH address.
I'm still not sure what you are trying to say. The links you provide tell you how to set up a pin as input/output analog/digital etc. Surely the nature of my question implies I've already gone beyond that? In other words, yes I can read the state of the button when I press and release it. Yes, I can get it to send an IO sample packet to DH/DL. So I know there is the IC command that triggers the sending of the packet.

But the question is: can I get it to trigger a callback (using the XBee Python Library) locally, without transmitting the sample packet? Maybe "the right calls" _are_ documented in your links, only I couldn't see them. Can you be more specific?

I've looked at the source code for XBee Python and can't see anything obvious. Thanks for trying helping me out, but maybe someone out there knows a simple trick.
No, not that I am aware of. Not without using the XBee 3 and its Micro Python interface and its Micro Python code.