Arduino MQTT Broker

I am trying to make the Arduino Portenta a complete Edge Impulse Home Automation product. It seems MQTT is the standard method for subscribing and publishing Sensor, Actuator or Machine Learning data.

It seems that everyone uses the Mosquitto MQTT Broker on the Raspberry Pi, or some fancy cloud broker. As far as I can tell an MQTT Broker (other than some fancy bells and whistles) has a fixed IP and just receives an MQTT publish message from a dynamic IP and sends it to all the subscribed dynamic IP’s. That should not be very hard to get working for say 30 clients on the Arduino Portenta (Dual core with Wifi, BLE and Ethernet), however I am not finding much about an Arduino MQTT Broker.

I have just started looking in microPython but also finding nothing:

Am I missing something?

All I have found that is slightly interesting is:

Using C++
https://www.eclipse.org/lists/mosquitto-dev/msg00057.html

Using an ESP32

That’s it. Anyone any suggestions?

I put a similar topic in the Arduino Forum at

@jenny So while looking for a micropython MQTT broker is this you! I think this actual file is for a client, but I am interested in what you did.

https://os.mbed.com/teams/Cloud-Hackathon/code/MQTT-Python-Demo//file/cc36d40e9bf5/broker/broker.py/

Any words of wisdom if this would run on the Arduino PortentaH7 using OpenMV micropython? No worries since I will try it. Very cool to see your name there?

Hello @Rocksetta,

For the Arduino Portenta H7:
I just checked on the Arduino website and it seems the mqtt-client library is available: https://www.arduino.cc/reference/en/libraries/mqtt-client/ (I haven’t tried it myself)

For the ESP32:
Here is an example I wrote when I was still working at my previous company: https://github.com/luisomoreau/ESP32-cam-MQTT (using the PubSubClient library)

For the ESP8266:
Here is a lab I used to teach with some of my Engineering Students:
https://github.com/luisomoreau/IoT-Communication-Protocols-Lab-1 (also using the PubSubClient library)

And for the MQTT broker on Mbed OS, it actually seems that @jenny authored the code sample in your link :slight_smile:

And if you are new to MQTT, I’d recommend to use this lightweight software to visualise your payloads going through the broker: http://mqtt-explorer.com/
It is super easy to use and you can connect to any broker easily (just make sure you are on the same network if you use a Raspberry-Pi-base broker :wink: ).

Best regards,

Louis

Thanks @louis I am getting MQTT clients running on both Arduino and OpenMV. Also mqtt-explorer.com works great so does node-red. My interest is to get a very small MQTT broker working on the Portenta. I will have to look at the code @jenny worked on, the example page I saw was only an MQTT client.

I have a method to run C++ cross compiled programs on the arduino but not expecting that route to have much luck. Also I don’t need a full fledged Broker, just something that can handle 1-5 topics.

Presently looking into the handshake between MQTT client and broker.

So here is the full link to @jenny article

https://os.mbed.com/teams/Cloud-Hackathon/code/

I also got a standard Arduino ESP32 library MQTT broker working on an ESP32 I had lying around a Node MCU-32S Running tinyMQTT

So probably the best bet for me is to try to port this library to the Portenta.

1 Like