ESP32 - MQTT Broker
Posted: Sun Aug 23, 2026 12:44 pm
I've been playing with MQTT recently - and I used a Raspberry Pi as a broker....
However - I could use an esp32 as a lightweight broker. Espressif have recently ported 'Mosquitto' to a component.
To run:
Create a new esp32 project (I called mine esp32_mqtt_broker) and cd to it's directory.
Add the component:
Rebuild the program (might need an idf.py fullclean first)
The very small program attached - creates an access point (or connect to local wifi) - ESP32Access with password pswd1234
I used IO MQTT Panel to connect (get the ip address by opening the esp32 COM port using PuTTY) - and created a switch and a text panel - with the switch sending 'on' or 'off' to sensor/toggle.
Other devices can connect / subscribe / publish although it probably can't handle large numbers of connections simultaneously. If required - it is possible to subscribe to a topic on the same device - to get notifications of new posts (I haven't tested this yet!)
One snag I hit - FC's CAL_IO defines A and B - as does the mbed component in the espressif libraries (this is a problem with C - symbols are program wide)
I got around this by undefining A and B (in supplementary code) -before importing the mqtt component. Then I redefined them (as 0 and 32)
Martin
However - I could use an esp32 as a lightweight broker. Espressif have recently ported 'Mosquitto' to a component.
To run:
Create a new esp32 project (I called mine esp32_mqtt_broker) and cd to it's directory.
Add the component:
Code: Select all
idf.py add-dependency espressif/mosquittoThe very small program attached - creates an access point (or connect to local wifi) - ESP32Access with password pswd1234
I used IO MQTT Panel to connect (get the ip address by opening the esp32 COM port using PuTTY) - and created a switch and a text panel - with the switch sending 'on' or 'off' to sensor/toggle.
Other devices can connect / subscribe / publish although it probably can't handle large numbers of connections simultaneously. If required - it is possible to subscribe to a topic on the same device - to get notifications of new posts (I haven't tested this yet!)
One snag I hit - FC's CAL_IO defines A and B - as does the mbed component in the espressif libraries (this is a problem with C - symbols are program wide)
I got around this by undefining A and B (in supplementary code) -before importing the mqtt component. Then I redefined them (as 0 and 32)
Martin