Christopher Hiller has an excellent followup blog post about MicroPython on ESP32, Get on the Good Foot with MicroPython on the ESP32 part 2 of 2. This post builds on an earlier one which introduced MicroPython ESP32 and continues on to explore logging sensor data to a MQTT server. One interesting highlight is the discussion of the upip package manager to natively install modules on the ESP32 from the REPL. This is a handy way to put packages on a board which has a network connection (like the ESP32). Check out the post for all the details:
In the first part of this excruciating tutorial, I taught the reader how to begin with MicroPython on an ESP32-based development board. We:
- Flashed the board
- Frolicked in the REPL
- Configured WiFi
- Uploaded scripts
- Build a circuit with a DS18B20 1-Wire temperature sensor
- Used MicroPython to read the temperature
In this part of the tutorial, we’ll take the data we gather with the sensor and publish it over MQTT.
If you’re unfamiliar with the concept, I’ll try to explain MQTT in a nutshell.
MQTT in a Nutshell
MQTT is a machine-to-machine protocol for publishing and subscribing to messages. Importantly, MQTT imposes no constraints upon the content nor structure of those messages.
In a typical setup, you have a single MQTT broker and one-or-many MQTT clients. A client may publish messages, subscribe to messages, or both. A client needn’t be an IoT device, a web app, a desktop or mobile app, a microservice, or anything in particular, as long as it speaks MQTT.
All clients connect to the broker. The broker is responsible for receiving published messages and (possibly) delivering them to interested clients.
Each message has a “topic”. As is vital to the publish/subscribe pattern, a message’s publisher doesn’t necessarily care if anyone is listening. Interested clients will subscribe to this topic.