Portenta as an MQTT Broker


I have found lots of requests for an MQTT Broker on an Arduino and lots of statements saying it can't be done, doesn't have the resources. (I might be wrong but I think an MQTT broker just remembers several dynamic IP's and takes published messages and sends them to multiple subscribers, how many resources does that use if you only have a total of say 30 subscribers/publishers?)

I think it could be done using the Portenta, but haven't seen any code. This link shows it working on an ESP32, but it is a big jump to convert that to the Portenta.


I have a RPI3B and could easily run mosquitto but where is the fun in that. I could probably make a cloud MQTT broker with Gitpod.io but that would not run continuously. Heroku would run forever but that is about as user friendly as an alligator.

Lets face it a cloud broker like arduino or adafruit.io makes the most sense when you are fully up and running, but in the testing stage an Arduino makes some sense.

Many cloud vendors are very unforgiving with bad data, wrong capitalization basically not very userfriendly until everything works.

By the way a few great tools for MQTT are:

  1. http://mqtt-explorer.com/
  2. https://nodered.org/
  3. Several cell phone MQTT-explorers
    Android: https://play.google.com/store/search?q=mqtt%20explorer
    Mac: MQTT - Apple
  4. For Libraries I use the #include <ArduinoMqttClient.h> but I think several will work with the Portenta

My version of the Algorithm would be something like

1. Set up WiFi or Ethernet connection
2. Store subscriber IP and publisher IP - could be hard coded, also could be just one topic
3. Listen for messages on local network (If at home give it a static IP using your home router)
4. Receive published message --> send to subscribers
5. That's it

Am I missing something here?

In conclusion anyone got any MQTT Broker example code (either C++ or microPython) that might run a really small MQTT Broker on the Portenta?

So I am working on converting this awesome ESP32 MQTT library to be able to work on the MBED Portenta. One Advanced programming step is giving me some confusion the using namespace keyword.

On an ESP32 this code works fine,

   using TcpClient = WiFiClient;  
   using TcpServer = WiFiServer;

but presently on the Portenta it fails (might be some other issue), however this code works

       #define TcpClient  WiFiClient
       #define TcpServer  WiFiServer

And ends up loading the WifiClient but fails later on these messages.

Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
	at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:966)
	at java.util.LinkedList$ListItr.next(LinkedList.java:888)


Exception in thread "Thread-258" java.util.ConcurrentModificationException
 lots more errors ...

Any opinions or suggestions to try. Is the ESP32 WiFiClient made different from the Portenta WiFiClient or should the above code work and I have made some other issue

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.