Data acquisition over MQTT

Introduction

Measurement readings can be acquired through MQTT using JSON.

Setup

Please have a look at MQTTKit about how to configure a MQTT application.

Basic examples

Setup “mosquitto_pub”:

aptitude install mosquitto-clients

Define where to send data to:

export MQTT_BROKER=localhost
export MQTT_TOPIC=mqttkit-1/testdrive/area-42/node-1

Single readings

Publish single sensor readings:

mosquitto_pub -h $MQTT_BROKER -t $MQTT_TOPIC/data/temperature -m '42.84'

Multiple readings

Publish multiple sensor readings using JSON:

mosquitto_pub -h $MQTT_BROKER -t $MQTT_TOPIC/data.json -m '{"temperature": 42.84, "humidity": 83}'

Readings with timestamp

Publish sensor reading with timestamp in ISO 8601 format:

mosquitto_pub -h $MQTT_BROKER -t $MQTT_TOPIC/data.json -m '{"time": "2016-12-07T17:30:15Z", "temperature": 42.84, "humidity": 83}'

See also the whole list of Timestamp formats.

Annotations

Grafana Annotations can be created through MQTT at the /event.json topic suffix. While arbitrary fields can be submitted, Grafana evaluates the fields title, text and tags. It is possible to use HTML inside the text field, for example to link this event to another web application.

The synopsis is:

mosquitto_pub -h $MQTT_BROKER -t $MQTT_TOPIC/event.json -m '{"title": "Some event", "text": "<a href=\"https://somewhere.example.org/events?reference=482a38ce-791e-11e6-b152-7cd1c55000be\">see also</a>", "tags": "event,alert,important", "reference": "482a38ce-791e-11e6-b152-7cd1c55000be"}'

Annotations can also be submitted retroactively, just add a time field:

mosquitto_pub -h $MQTT_BROKER -t $MQTT_TOPIC/event.json -m '{"time": "2016-12-07T17:30:15.842428Z", "title": "Some event in the past"}'

See also the whole list of Timestamp formats.

CSV format

Todo

Not implemented yet.

Periodic acquisition example

Sawtooth

The characteristics of sawtooth signals (dynamic, slowly oscillating) are convenient to generate measurement sensor readings and publish telemetry data without having any hardware in place.

For getting started, please read about how to generate a dynamic, slowly oscillating sawtooth signal and publish it to MQTT.

Language bindings

List of Kotori MQTT clients
Name Description
Python
Arduino
Arduino/ESP8266
ARMmbed

Troubleshooting

See also

Please read about general Error signalling.

Todo

Add notes about no data appearing in Grafana, etc.


Applications

Todo

Refactor to acquisition/examples

Command line

Todo

  • Add example from Hiveeyes, link here.
  • Also add link from handbook/kotori and setup/getting-started to here.

Hiveeyes

The Hiveeyes project for collaborative beehive monitoring uses two different kinds of sensor nodes.

  • Hiveeyes One sensor nodes transmit data to a gateway using RF, the gateway receives and decodes telemetry data from Bencode format, then forwards it to the MQTT broker in JSON. This is specified in BERadio specification and implemented in Python using the serial-to-mqtt forwarder beradio-python.
  • Open Hive sensor nodes based on the Adafruit HUZZAH ESP8266 directly send telemetry data to the MQTT broker in JSON format.