In my recent MQTT testing endeavors, I've found a reliable and efficient setup that I'd like to share with you. MQTT, or Message Queuing Telemetry Transport, is the go-to protocol for IoT messages. Surprisingly, it has a robust history, dating back to 1999 when it was initially developed for industrial IoT devices. With its proven track record, MQTT has become a cornerstone in the world of IoT communication.
As I delve into testing my scripts, I find it essential to have a dual-setup: a tried-and-true subscriber to validate the successful delivery of my messages and my test code for experimentation. Currently, my focus is on streamlining the deployment process for a broker, publishers, and subscribers. This involves meticulous testing, especially considering the two primary MQTT protocols in use today: v3.1.1 and v5.0. For my public broker needs, I turn to https://test.mosquitto.org/. This platform, powered by Mosquitto, serves as an excellent public broker for both testing and practical utilization. You can see their connection protocols on the image to the right. There are, of course, others, but I like how this broker is documented, YMMV. To facilitate my testing process, I leverage a fantastic command-line subscriber called mqttx-cli, crafted by eqmx—a prominent figure in the MQTT landscape. This open-source, cross-platform MQTT client is versatile, supporting both v3.1.1 and v5.0 protocols. It seamlessly handles CA, self-signed certificates, and one-way or two-way SSL authentication. mqttx-cli proves invaluable as both a subscriber and publisher, ensuring thorough testing of message propagation and functionality. This setup not only streamlines my testing but also enhances the reliability and efficiency of my MQTT experiments. Okay, lets begin. brew install emqx/mqttx/mqttx-cli mqttx sub --hostname test.mosquitto.org --port 1883 --insecure --mqtt-version 5 -t hello/world mqttx pub --hostname test.mosquitto.org --port 1883 --insecure --mqtt-version 5 -t hello/world -m "hello world"
Incorporating mqttx-cli into your testing toolkit is a breeze. First, install the client to get started. Once that's done, you can seamlessly publish or subscribe to a topic of your choice and use your own code for the "other side" of the transmission. A word of caution, though: the popular topic `hello/world` may receive an avalanche of messages from various sources. To minimize the influx of test messages, consider opting for a more unique and specific topic.
This setup empowers you to rigorously test your own MQTT code and validate its functionality. It's worth noting that most public brokers don't support Quality of Service (QoS) beyond level 0, so keep that in mind as you fine-tune your testing parameters and of course, never put sensitive information on public brokers. Happy testing! Your comment will be posted after it is approved.
Leave a Reply. |
AuthorJames Benson is an IT professional. Archives
August 2022
Categories
All
|