MIcropython as MQTT broker

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: MIcropython as MQTT broker

Post by karfas » Sat May 01, 2021 1:14 pm

(600m2, 60m corridor, 20 rooms, 40cm stone walls, 40 esps, 1 pi4)
So if i actually manage the network connections in a mesh, and manage a station and AP on every esp (with a single root).
What is to stop me using the station to publish (upstream) and the AP to subscribe (downstream).
As far as I understand, this is not the way a mesh (e.g. ESP-Mesh, see https://docs.espressif.com/projects/esp ... ata-stream) is working. I also don't see the need for a star topology, as each ESP will most likely "see" his neighbour (you might want to try this first), so this comes down to a simple case of routing (either traditional or via mesh).

How much data do you expect to transfer ? Routing a number of video streams over one ESP32 will most likely not work, but I don't see a problem with a few sensor readings now and then.
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

beyonlo
Posts: 58
Joined: Thu Nov 26, 2015 8:03 pm

Re: MIcropython as MQTT broker

Post by beyonlo » Tue Jun 01, 2021 6:40 pm

Hi all.

I would like to use a MQTT Broker on MicroPython (on ESP32) too.

Just a idea/question: Are there a pure Python MQTT Broker? So, maybe, is possible to port it to MicroPython.

Is that a good idea?

Anyway, the best way is to have a MQTT Broker that works with uasyncio, of course.

Thank you.

smurf
Posts: 7
Joined: Wed Feb 27, 2019 11:25 am

Re: MIcropython as MQTT broker

Post by smurf » Wed Jun 02, 2021 1:39 pm

Yes there are pure-python MQTT brokers, hbmqtt for one. The problem is that it's basically unmaintained, and the fork that *is* maintained is based on anyio which hasn't been ported to micropython (yet, it's somewhere on my list of interesting things to do).

Also, you will have moments with iffy networking, which means that you need to buffer some messages. Unfortunately you probably don't have much free memory on your MicroPython device once you load all that broker code onto it. MQTT is not a simple protocol.

I wouldn't do that. IMHO it's far more useful to teach MicroPython about ESP's wifi mesh support, and run Mosquitto on a Raspberry Pi somewhere. At least that way you have some chance of stable operation of the whole setup.

laldana73
Posts: 1
Joined: Thu Jun 03, 2021 6:45 pm

Re: MIcropython as MQTT broker

Post by laldana73 » Thu Jun 03, 2021 7:25 pm

Hello, this library https://github.com/martin-ger/esp_mqtt can help you to use an esp8266 module as a MQTT broker. But this is not Micropython, is using NONOS SDK or esp8266SDK.
https://github.com/cesanta/mongoose the mongoose networking library can be used to build a MQTT broker in the esp32. you could use this to build a module for ESP32 Micropython port.
or you coud use COAP in Micropython, instead MQTT

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Another approach?

Post by pythoncoder » Fri Jun 04, 2021 8:11 am

In any application which must run 24/7 I would test these solutions carefully to ensure they recover from loss of WiFi connectivity. I would also test that they can run continuously for days on end: this can be a tall order for ESPx unless there is a watchdog timer.

Running MQTT in a mesh configuration using bridges is an interesting idea, but it isn't how MQTT was designed. There could be hidden pitfalls.

I think it's also worth considering using MQTT as designed, but with long range radio technology. I haven't looked into this in detail, but LORA supports networking. So I wonder if it's possible to configure a Raspberry Pi running Mosquitto to use a LORA device. Clients could run on PyCom hardware with a modified version of mqtt_as.
Peter Hinch
Index to my micropython libraries.

Post Reply