peterhinch / micropython-mqtt

A 'resilient' asynchronous MQTT driver. Recovers from WiFi and broker outages.
MIT License
549 stars 116 forks source link

publish to broker on an event trigger. #120

Closed davidecat closed 10 months ago

davidecat commented 10 months ago

Hello, first of all thank you for your work! Is there any example on how to use it to publish to the broker on an event trigger? Im testing it with 5 RPICOW with IR sensor to 1 RPIZero2 with mosquitto. Thank you again!

edit: Just to give some further info, i'm testing mqtt_as cause the official driver give me a weird behaviour. Using multiple publishers the first message of a new publisher is lost. I mean: 1 sends correctly, 1 resends correctly, 2 sends and mosquitto dont get is, 2 resends and its correct. if 1 sends again, the first is lost, the second is correct...

peterhinch commented 10 months ago

If you look at this example code the main task waits for a time before publishing. You could replace that with a wait on anything: an Event instance, a pin change, or whatever.

davidecat commented 10 months ago

Thank you @peterhinch, it works like a charm!