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.
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:
- Several cell phone MQTT-explorers
Mac: MQTT - Apple
- 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?