MQTT library recommendations

I would like to experiment with MQTT, I had a quick look in library manager for MQTT libraries and there are loads of them. I would like suggestions for libraries that work well and ones to avoid. I will use with both an ESP8266 such as a D1 Mini and an MKR WiFi 1010. I have no particular application in mind, I just want to play with it and understand what it can do.

Also, I have only been able to find MQTT client libraries for Arduino, no brokers as far as I can see. Brokers seem limited to either running on an RPi, a PC or a web based broker service. Have I just not looked hard enough or do Arduino based brokers not exist? Again, ideally I would like to run a broker on an ESP8266 and / or MKR WiFi 1010.

Suggestions and thoughts please.

Thanks very much.

I use the Mosquitto broker on a Raspberry Pi3. You can also use a public broker online. If there is a broker library for the Arduino, I am unaware of it.

I only use the ESP devices for my IOT over MQTT- all you need there is PubSubClient.h on the Arduino. (Well you do need ESP8266WiFi.h to connect the ESP WiFi to your LAN).

Thanks Steve,
Searching in Library Manager for PubSubClient narrows it down a lot, and only one of the results can be installed directly from LM, so I guess that must be the one you are using.

I was a bit surprised there not being a broker to run on, maybe, an ESP32 or similar. I would prefer to use a local broker than a web based one, and I am trying to avoid an RPi as I had one once and it drove me mad! (Drove my friend mad also with all the questions I kept asking him :confused: )

Hopefully someone out there is writing a broker library for Arduino as we speak :slight_smile:

I also (have) used Mosquito on an RPi.

If you use an RPi.. it -is- local..

You'll need something with more horsepower.

RPi
PC
Public MQTT Service (Internet based)

I configured my RPI as a broker/server... I also installed LAMP (Apache, MySQL & PHP)..

There is a PHP class/lib that ALSO lets you communicate with MQTT protocol..

  • which works out nice.. because you can log stuff to a DB and do other 'web based' actions.. and then have a PHP script send out the PUB/SUB updates..

PerryBebbington:
Thanks Steve,
Searching in Library Manager for PubSubClient narrows it down a lot, and only one of the results can be installed directly from LM, so I guess that must be the one you are using.

Yes.

I was a bit surprised there not being a broker to run on, maybe, an ESP32 or similar. I would prefer to use a local broker than a web based one, and I am trying to avoid an RPi as I had one once and it drove me mad! (Drove my friend mad also with all the questions I kept asking him :confused: )

Hopefully someone out there is writing a broker library for Arduino as we speak :slight_smile:

Unlikely, but an esp32 could handle it. But I won't hold my breath.

I have a few Pi's here that have been running for months. One is my MQTT Broker and another is my Home Assistant server. (Both have Node-Red, but don't get me started...) I also have a Pi4 on my bench that could replace my desktop in a pinch.

But, frustration with the Pi- I HEAR YOU!. None of mine are plug-n-play and connecting the WiFi is the most frustrating.

But, you can use one of the public MQTT brokers for free. There are data limits on the free accounts, but you have to use it an awful lot to exceed your quota.

The problem with running a MQTT broker on an Arduino platform is that the memory requirement is very large. QoS (quality of service) is a feature of MQTT that ensures messages with a QoS setting of 1 or 2 are delivered to the subscriber. So the broker needs to keep these messages until they are delivered to all subscribers.

There are some people working on a very limited MQTT broker for something like a ESP8266 without QoS support and only a hand full of connections. You can have a look at the following link. The last update is almost one year ago.

I use:

  • Adafruit MQTT library on a Feather M0 WiFi with the WiFi101 library

  • Raspberry Pi 3 connected via WiFi
    -- Mosquitto broker
    -- Node red for storing data from MQTT messages in influxdb and data processing

  • Eclipse Paho MQTT Utility on Windows 10 for sending test messages, and looking at messages

I started with the broker and Paho to make sure the broker was working and then started sending MQTT messages from different boards.

It’s all running for many months without issues.

SteveMann:
But, frustration with the Pi- I HEAR YOU!.

I had many frustrations, but the one I remember most was it having user permissions. I think that's absolutely bonkers on a machine intended to be messed about with, programmed and generally hacked and experimented. Why would I care about or want any kind of user access permissions on a machine intended to be played around with like that?

Hi Klaus,
Thank you also for your thoughts, much appreciated.

Well.. in theory.. the RPi.. is a mini computer. It runs a version of Linux.. so permissions -are- required here.

Just because 'we' hack them.. and tend to use them in conjunction with Arduinos.. and utilize the GPIO's.. many do not.

But I have ALSO ran into a permission problem (which was solved, but opening up all permissions more more less) when working on my Iron Man HUD (helmet) project...

I was having an issue getting serial communication to be 2 way at first.. as well as sending data via socket connection to my web page (app) that was running PHP/AJAX waiting for this communication/response.

After some searching I found a command line that basically opened up all permissions.. and because my project is a stand-alone/off-line* project... the security is not really a concerns of mine.

But I really recommend it.. $35 bucks.. and you have a fully capable MQTT server (and you can install other stuff if needed like LAMP)

Well.. in theory.. the RPi.. is a mini computer. It runs a version of Linux.. so permissions -are- required here.

Yes, but a computer sold with the express aim of it being hacked etc, having permissions as a default seems to me a direct contradiction of that purpose, especially considering you have found it's possible to turn them off. The default should be all off.

I really recommend it.. $35 bucks.. and you have a fully capable MQTT server

Maybe, if experimenting with MQTT lead me to a project where I find I need one. My friend won't be happy with all the questions....

Thanks anyway :slight_smile:

Its always up to the end user I suppose.. whatever you are comfortable with.

But the MQTT project was -FIRST- RPi project I had ever done.. (and I barely know anything about Linux or CLI stuff much)

*(second if you count a default RetroPie install for an arcade!... LOL)

Maybe for a project you want to play around with some Home automation stuff?

Maybe for a project you want to play around with some Home automation stuff?

When I had my first house, around 1980, I listened to the electromechanical room thermostat clicking on and off and wondered how I could make a better one. Since then I've lost count of how many better ones I've made. First with relays, then with analogue electronics combined with CMOS, a Z80 version and now with a PIC and a Nextion display. I've been messing with ESP8266s and MKR WiFi 1010 as the next improvement. I found out about MQTT on here and thought it would be interesting to play with. I don't want to be trapped into the idea of yet another heating controller improvement, but given that I've been making better ones for 40 years (ouch!) I imagine that's what will happen. For now, I just want to understand MQTT with no particular application in mind. Maybe I'll use it, maybe not.

Hi Perry,

I am in the same position as you were some months back. Can you kindly let me know which option you ended up taking for the libraries - Adafruit or pubsubclient (NickOleary)?

Your assistance is much appreciated.

I played around with MQTT but have not used it for anything serious. I think my experience is too limited to be any use to you. Read the comments and recommendations from those that advised me and go with what they say. I will just say I found MQTT easy to work with, the reason I've not used it is I don't really need it. It was interesting to play with though.