Having spent the last few days fiddling with MQTT, I have some thoughts and observations worth documenting.
Mosquitto out of the box isn’t configured for anonymous access. This is better for security, but if you haven’t used the software before can be a bit confusing and lead to a bit of head scratching. To allow anonymous access add the following to /etc/mosquitto/mosquitto.conf:
allow_anonymous true
listener 1883
This will allow anonymous access on clear port 1883. Still not interested in using TLS for the local server, so my microcontroller can talk to it easily.
Using JSON in a MQTT value is really nice. It’s trivial to extract it into a python dictionary. Should be easy to construct simple JSON in C on a microcontroller.
Lots of documentation I’ve seen recommends using https://www.pubnub.com/ as a cloud MQTT server. However, it doesn’t support MQTT over TCP any more. It looks like support was cancelled last year. This doesn’t seem to be made very clear at all. In general pubnub documentation doesn’t feel very user friendly. Its very bitty. It has lots of broken links. There’s a fair bit of stale documentation that is no longer relevant, which isn’t marked as such. Because of this I spent quite a long time analysing my firewall config, as nmap suggested port 1883 and 8883 were being filtered (newsflash, they weren’t). There was also a lot of confusion over which URL to use, which as it turned out, due to the aforementioned cancellation were all nonsense. Servers were present in DNS, but did not respond to ping which also didn’t help. ChatGPT and Gemini were also content to lie through their teeth about the service status, which is hardly surprising since their source material was outdated, obfuscated nonsense.
https://www.hivemq.com/ seems much better. It does actually support MQTT over TCP. It has a free, openly accessible test server. It has a free tier with login for basic messing about. It has good documentation. It has a decent AI chat bot that did a good job of answering my noob questions and got me up and running quickly. Open server allows anonymous access, TLS and clear. Logged in server requires TLS and username/password.
It seems like the best way to handle a microcontroller with weak TLS is to have a local MQTT server which can handle TLS, to forward stuff to the cloud. Doesn’t need to be anything fancy, as its not high traffic. Export data from microcontroller to local MQTT using clear MQTT, MQTT-SN, COAP, BLE etc.
For the purposes of my project, its feeling like a combination of HTTP for bulk payload and MQTT for general sensor data and notifications will be best. The clue is in the name: Message Queuing Telemetry Transport. Use it for sensor readings and management.
The paho MQTT python module seems quite nice.
All in all, quite nifty so far.