A push button is connected to the ESP32 microcontroller. When its state changes, it will trigger an MQTT publish which will toggle the light controlled by a Shelly plus 1 relay
.
❗Keep in mind that you should either use a capacitor (better) or providing some delay in the code to debounce the push button and filter out spurious changes. Pull down the push button via a 10k resistor, if you don't set the pull-up mode on the input pin.
If you have a Shelly in your wall and want to try out the MQTT connection without purchasing or wiring up the micontroller, I've saved a prototype of the project on Wokwi.
-
For testing I use the Hive MQ public broker.
-
For production I use Mosquitto from a Docker container inside my local environment (see the Docker compose file).
❗ The code should already handle reconnections if something goes wrong.
- Arduino IDE to code, compile and upload the code to the ESP32 Wroom board.
- Remember to add the CP2102 driver to connect old ESP32 development board (with CP2102 as USB-UART bridge).
- ArduinJson, pubsubclient and ArduinoOta libraries.
- How to setup a local broker in a Docker container.
-
I will make the ESP32 aware of the ligth bulb status subscribing to the rpc channel/topic where the Shelly's relay automatically publish the status (on or off).[DONE ✔️] -
I will make possible an initial speech recognition through a microphone and a Keras neural network (via Eddge Impulse and Colab for training it), like in this video from DigiKey.[DONE ✔️] -
I won't use the official ESP-IDF with the built-in MQTT library (or via Cesanta Mongoose MQTT library) because is too much power for this project.[DONE ✔️] -
Using Kicad, directly create a PCB with push button, microphone + opamp (considering noise constraint) and microcontroller on the same board.
The answer lies in the low level of the libraries used. Python will depend on low level C code, while Rust can go to bare metal, but it's by far more tedious. Try doing this on Rust, I find it better on C++.
Then the library support for microcontroller is not yet ready as in C/C++.
Take a look also at the ESP-IDF version of this project. Don't look too much at it, otherwise you won't never come back to Arduino 😍 🙈.
- Useful installation video for Shelly's relays.
- How Shelly handle MQTT connections in the official doc.