Mosquitto

From Earlham CS Department
Jump to navigation Jump to search

HIP is using Mosquitto software a platform to run an MQTT publish-subscribe data collection model. Its first use will be with the indoor air quality monitors in Joseph Moore Museum and in the Center for Science and Technology.

Publish-Subscribe and Mosquitto

There are two general approaches to moving data, each with advantages and disadvantages. One is a poll. In this approach, the data sits where it is being collected and a computer periodically asks for the current reading. For example, every minute, HIP's computer Proto runs a script that collects the most recent reading from each energy monitoring device it has set up on campus. Other than actual data collection, the computer does all the work.

MQTT, implemented in our case via the Mosquitto software program, is used for the other approach, publish-subscribe or "pub-sub." In this case, the device that collects the data (or, more generally, any machine that has information you want another machine to have) also publishes it as a message. Anyone with the right access and software can then subscribe to receive these messages. A message broker, in this case Mosquitto, is used to manage both publication and subscription.

A bit more technically, from the Mosquitto website:

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. This makes it suitable for "machine to machine" messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers like the Arduino.

Example of Mosquitto

Install mosquitto and mosquitto-clients. Then run the following commands (no need to change any settings for these):

  • in one terminal: mosquitto_sub -t hello/world
  • in another terminal: mosquitto_pub -t hello/world -m "hello world"

The first command subscribes you to the topic hello/world, which is hierarchically organized first by hello and then by world (think of the path to a file in Linux). The second publishes the message "hello world" to that topic. That message should appear in the first terminal.

As always, see man pages for more.

External Links

Mosquitto website Mosquitto man pages and other docs