Your final intention is not clear to me, so if possible please provide more details, and also attach a conceptual image. I really want to help.
`Example receive_callback(rx_callback) 2024-03-09T23:08:00Z
Im new at my work and my current objective is to adjust the code. Basically what i did is putting the whole script inside a class.
This is the part for the function:
if (USE_RECEIVE_CALLBACK is False):
# empty message queue
# with Python we we have a queue length of 4 packets
for i in range(4):
rdata = xbee.receive()
do_receive(rdata)
utime.sleep_ms(400)
else:
# register callback. PyCharm indicates, that lib does not have this function.
# but it works . FW version of XBEE Device must be >= 100B
xbee.receive_callback(RxCallback)
# we are waiting 2 seconds for incoming messages
utime.sleep_ms(2000)
# unregister callback
xbee.receive_callback(None)
if i understand everything correctly, the line xbee.receive_callback(RxCallback) registers the RxCallback function as a callback, starting whenever data is received. However my changes for classes adds the self argument. When i change the line to
xbee.receive_callback(self.RxCallback)
My edited code using class:
if self.RECEIVE_ENABLE is True:
# if we have a software with receive function → check if we have received a packet
print(“reading RF data…”)
if self.USE_RECEIVE_CALLBACK is False:
# empty message queue
# with Python we we have a queue length of 4 packets
for i in range(4):
rdata = xbee.receive()
self.do_receive(rdata)
utime.sleep_ms(400)
else:
# register callback. PyCharm indicates, that lib does not have this function.
# but it works . FW version of XBEE Device must be >= 100B
xbee.receive_callback(self.RxCallback)
# we are waiting 2 seconds for incoming messages
utime.sleep_ms(2000)
# unregister callback
xbee.receive_callback(None)
Im getting the following error and i dont really get, why and how it worked before:
Traceback (most recent call last):
File “/flash/main.py”, line 959, in
File “/flash/main.py”, line 893, in run
TypeError: callback must be a function