How to turn off WiFi in async MQTT?
Posted: Thu Mar 28, 2019 4:58 pm
I'm hoping to get some help on a thorny problem I can't easily solve...
background:
I am using Async MQTT with the Lobo port to publish sensor data to a remote broker, every 15 minutes. This asyncio MQTT implementation solves a major requirement in my application - publishing sensor data without blocking other performance-critical coros.
the challenge:
There is one requirement that is not being met (or at least I don't see a solution in mqqt_as.py)
Here is pseudo-code for the application:
1. wait for 15 minute signal
2. connect to MQTT broker
3. publish sensor data to broker
4. disconnect from broker and turn off wifi
5. back to 1.
I'm struggling with step 4 above. The challenge is that Async MQTT appears designed to maintain a broker and wifi connection at all times. Any thoughts on a way to turn off Wifi when it is not needed? I'm happy to fork-and-adapt the async mqtt repo to my own needs, but first wanted to see if there is a built-in solution that I am missing.
thanks !
background:
I am using Async MQTT with the Lobo port to publish sensor data to a remote broker, every 15 minutes. This asyncio MQTT implementation solves a major requirement in my application - publishing sensor data without blocking other performance-critical coros.
the challenge:
There is one requirement that is not being met (or at least I don't see a solution in mqqt_as.py)
- when the application is not publishing to the broker I want to turn off WiFi to reduce the ESP32 power consumption
Here is pseudo-code for the application:
1. wait for 15 minute signal
2. connect to MQTT broker
3. publish sensor data to broker
4. disconnect from broker and turn off wifi
5. back to 1.
I'm struggling with step 4 above. The challenge is that Async MQTT appears designed to maintain a broker and wifi connection at all times. Any thoughts on a way to turn off Wifi when it is not needed? I'm happy to fork-and-adapt the async mqtt repo to my own needs, but first wanted to see if there is a built-in solution that I am missing.
thanks !