MQTT


Deprecated This team is no longer maintained, please use: https://github.com/ARMmbed/mbed-mqtt instead.

You are viewing an older revision! See the latest version

Using MQTT

What is MQTT?

MQTT is a pub/sub architecture that is optimized for realtime embedded devices. It enables one to many communication in a trivially easy fashion. For an in-depth explanation of what MQTT is and how it works please see https://github.com/mqtt/mqtt.github.io/wiki .

How to use it?

To use MQTT you must have two things.

  1. A Client
  2. A Broker

The MQTT Broker is a server that takes care of distributing messages to everyone and keeping everyone up to date. The MQTT client is a piece of software that publishes and subscribes to topics. The MQTT library is a client library that enables mbed devices to use the mqtt protocol. This can be seen in the mqtt hello world example.

MQTT Broker

There are many options for an MQTT broker out there. You can install your own locally, or use a private one in the cloud. If you want to quickly test your mqtt client implementation you can either use one of the many public mqtt test servers or install one locall. For online public brokers check out this list. For a local broker check out mosquitto.

On windows you will need to install the dependencies for mosquitto, make sure to read the readme_windows.txt file in the mosquitto install directory. For OSX/Linux you should be able to run the following command at your terminal to start up a mosquito broker with no security on port 1883

$ mosquitto

All connections will be reported to the terminal window. If you are connecting multiple devices make sure to change the client ID's, conflicting ID's are not allowed.

mbed MQTT Client

The mbed mqtt library that is used as part of the mqtt hello world program can be used with any transport layer to use mqtt on mbed. Go give the example a try, make sure to change the broker address and URL address to the broker of your choice.

If you are having trouble with your MQTT broker you can try running an mqtt client in python to validate the broker. Follow these steps to install a python mqtt client. 1) Install the paho-mqtt python client (make sure you have python 2.7.9 or greater installed)

$ pip install paho-mqtt

2) Save the following python code to mqttclient.py . Make sure to change the broker field to the correct broker you are looking at and the topic to the topic you are interested in.

Python-MQTT-Client

3) run the python script.

$ python mqttclient.py

The python script will report back all messages published to that topic.


All wikipages