Go Small Go Wireless Outcome – MQTT

what is MQTT? what is mosquitto?

MQTT (formerly MQ Telemetry Transport) is a publish-subscribe based “light weight” messaging protocol for use on top of the TCP/IP protocol. It is designed for connections with remote locations where a “small code footprint” is required or the network bandwidth is limited. The publish-subscribe messaging pattern requires a message broker. The broker is responsible for distributing messages to interested clients based on the topic of a message. (https://en.wikipedia.org/wiki/MQTT)
http://mqtt.org/

In the focus-group we use a Broker called Mosquitto:
Mosquitto is an open source (BSD licensed) message broker that implements the MQ Telemetry Transport protocol versions 3.1 and 3.1.1. MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model.
http://mosquitto.org/

Here is how a typical Broker / publish / subscribe netowrk looks like:

net101-mosquitto

Topics:
A publisher published any kind of value int a topic. Subscribers subscribe to a topic and receive whatever publishers publish into that topic.
Topics are hierarchically organizes, like a folder-structure. subscribers can also subscribe to all subtopics of a topic, or for all topics.

 


advantages using a broker

A publish-subscribe pattern using a broker in the middle allows a dynamic setup of connected devices. The Broker is called a fix-point the network infrastructure. Devices can come and go, the rest of connected publishers or subscribers are not concerned about it.
For subscribers this means: if there is data i will get it, if not i don’t.
For publishers this means: whenever i want, i can connect to the Broker, push some data and go to sleep afterwards. The Broker deals with distributing the data.
The mosquitto-broker additinally is capable of storing all the values and persisting data. In case the broker crashes, it can rstore the latest state of values.

For a sensor-actor network this is exactly what we want. sensors are pushing data to the broker, actuators can pick them up if they want to.

For a Sensor-dress this is a convenient setup too. Imaging a dress where all the joint measurement-data is published into separate topics logically organized (/body/left/arm, /body/right/finger, …). A broker in the middle can distribute the data to processing-machines. One computer might generate sound out of the movement of a dancer, another machine might just render visual-output, another machine can be used to monitor the data and calibrate the suite. Mobile devices can easily be linked into the infrastructure to receive the same data.

 


installing mosquitto

There is an installer for windows.
On OSX mosquitto can be installed via homebrew.
(tutorials for how to use homebrew here >> http://www.screencasts.org/episodes/how-to-use-homebrew)
On linux mosquitto most likely can be installed using a package-manager
http://mosquitto.org/download/
http://mosquitto.org/documentation/

 


accessing mosquitto topics

Mosquitto comes with subcrition and publishing command-line tools. mosquitto_sub and mosquitto_pub can be used to subscribe to a topic, or to publish to a topic.

 


using mqtt with arduino and ESP8266

Download a wrapper around mqtt for Arduino from here
>> https://github.com/i-n-g-o/esp-mqtt-arduino
Then place the unzipped folder into your Arduino/library folder.

Look at the examples mqtt_pub and mqtt_sub.

Alternatively you can install libraries using the librariy-manager. Search for mqtt.
There are alternative mqtt-libraries from adafruit and Joel Gaehwiller.

Leave a Reply