I've run into an issue using pybytes on my LoPy4 with Pysense shield.
I would like to get data from sensors, send them to Pybytes and go to deepsleep.
I do have sepadate funcions to get the data from sensors and to send the data.
Simplified code without any definitions and library imports:
sensorData = getSensorData() sendData(sensorData) py.setup_sleep(sleepTime) py.go_to_sleep()
The getSensorData() returns JSON dictionary with all the sensor data.
The sendData() looks like this:
def sendData(data): pybytes.send_signal(1, data['batt']) pybytes.send_signal(2, data['temp1']) pybytes.send_signal(3, data['press']) . .
(two dots represent more lines in the function, 9 values are being sent, wanted to save some space :) )
The problem is that calling sendData() jumps out immediately and the actual data sending process takes on later. From what I understand pybytes.send_signal() sets up a new thread with given arguments and is done.
So when I run the code, LoPy goes to deepsleep before it actually sends out any data to Pybytes.
Is there any flag or variable I could check to see if my Lopy board is still sending out the data and in that case wait before going to deepsleep??
sensorData = getSensorData() sendData(sensorData) while(True): if not "pybytes_still_sending_data": py.setup_sleep(sleepTime) py.go_to_sleep()
Possible workaround may be to put time.sleep() for like 20 sec before the deepsleep, but I would like to avoid this "solution".
I came up with a solution to this that for the moment seems to work. It is based on checking the length of the outgoing message queue (will fail if no mqtt connection)
for _ in range(10): in_queue = len(pybytes.__pybytes_connection.__connection.__mqtt._msgHandler._output_queue) if in_queue == 0: break time.sleep(1)
I have hit this too. Maybe an optional callback parameter to send_signal which gets executed when done?
Ill put this on the feature list!
I had like to know the answer to this too.
Would love to know this as well, or if there's any way to get confirmation that a message/signal was sent (with_ack)?