Hello
I run a mosquitto broker on a Raspberry Pi 3 board which can be turned "on" and "off" by a NodeMcu board. NodeMcu is a MQTT Client and uses this protocol to communicate with Raspberry Pi 3. Further I need a http server on my NodeMcu in order to turn on and off a Raspberry Pi board via "http" protocol. I faced a following problem: I have to run the both http server as well as MQTT Client at the same time on NodeMCU board. I cannot do it because they both enter a blocking infinite loop. In a PC world i would use a separate Thread for each instance, but i don't think it is a good idea to implement this way on a such resource-sensitive board like NodeMCU. Any idea how to get running both instances in "parallel" or "semi-parallel"?
MQTT + HTTP Server simultaneously
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: MQTT + HTTP Server simultaneously
You use a webserver that uses uasyncio and the async mqtt client https://github.com/peterhinch/micropython-mqtt or you use a webserver that uses _thread in which case you have blocking loops in different threads.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: MQTT + HTTP Server simultaneously
Thank you kevink525 uasyncio would be a perfect solution for me.kevinkk525 wrote: ↑Wed Dec 25, 2019 7:30 amYou use a webserver that uses uasyncio and the async mqtt client https://github.com/peterhinch/micropython-mqtt or you use a webserver that uses _thread in which case you have blocking loops in different threads.