Hello,
I do a lot of python programming, specifically around Django, so I usually have a lot of compute and threading services available, so I’m having a hard time trying to figure out how to listen/respond to an MQTT queue but also take input from the changes in a potentiometer. The idea of forking, multiprocessing, or parallel processing comes to mind, but none of these seem to be the best approach with MicroPython.
I’ve created some small IoT devices that input from a sensor and send that data to the appropriate place, but the current project I’m working on needs to be able to react to the changes in a potentiometer or the input from an MQTT queue.
I’m currently using a NodeMCU esp8266 board, a servo, a potentiometer, and HomeAssistant to control a device. The 8266 chip needs to take input from the potentiometer to move the servo, but also take input from an MQTT queue to also update the servo. The changes through the potentiometer need to update the MQTT queue as well...
Any help would be greatly appreciated.
Thanks!
ESP 8266, MQTT, and Potentiometer
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: ESP 8266, MQTT, and Potentiometer
Asyncio is the best programming style to have multiple tasks running.
A good tutorial for the micropython variant uasyncio is here: https://github.com/peterhinch/micropython-async
If you are looking for an easy option, I made a framework that keeps the esp8266 connected to the mqtt and loads components as configured. It takes care of everthing (connection, mqtt, ..) and you just have to configure your components or write new ones. This is not difficult and as you can see in the examples and templates.
I use this framework with homeassistant. Maybe it helps, maybe it's not what you are looking for: https://github.com/kevinkk525/pysmartnode
A good tutorial for the micropython variant uasyncio is here: https://github.com/peterhinch/micropython-async
If you are looking for an easy option, I made a framework that keeps the esp8266 connected to the mqtt and loads components as configured. It takes care of everthing (connection, mqtt, ..) and you just have to configure your components or write new ones. This is not difficult and as you can see in the examples and templates.
I use this framework with homeassistant. Maybe it helps, maybe it's not what you are looking for: https://github.com/kevinkk525/pysmartnode
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
-
- Posts: 2
- Joined: Thu Mar 07, 2019 1:30 am
Re: ESP 8266, MQTT, and Potentiometer
kevinkk525,
Thanks for the reply! Once I get a chance, I'll give your framework a try. Looking it over, it appears to be, as you said, everything I need.
Thanks for the reply! Once I get a chance, I'll give your framework a try. Looking it over, it appears to be, as you said, everything I need.