In this post, I am going to set up a communication and storage system for IoT data. I am planning to use MQTT for communication as it is one of the most widely used protocols for sensor data communication. More details regarding MQTT can be found at http://mqtt.org.

From mqtt.org:

MQTT is a publish/subscribe, extremely simple and lightweight messaging protocol, designed for constrained devices and low-bandwidth, high-latency or unreliable networks. A MQTT publisher connects to a broker, and can send any arbitrary data to a “topic”. A MQTT subscriber can choose what “topic(s)” to listen to and process incoming data streams. In this post, we will listen to a topic and write incoming data to our storage system.

For storage, I am going to use InfluxDB. It is well maintained and scalable open-source solution provided by Influx Data. More details regarding InfluxDB can be found at https://www.influxdata.com.

You can write a small code to subscribe to MQTT topic and write incoming data to InfluxDB, or you can use Telegraf to achieve the same. Telegraf is one more software available from Influx Data which can subscribe to an MQTT topic and write data to InfluxDB.

To wrap this post up, I’ll show a basic Grafana dashboard to display incoming time series to verify if the complete setup is working or not. Of course, I’ll have a much better visualization scheme in the next post. For Grafana details go to Grafana.net.

Note:

This is very unsecured setup so do not deploy it in a production environment.

I am going to setup it on a ubuntu VM running on AWS t2.micro instance. You can run it on your local Linux machine with minor modifications. Make sure that following ports are open and accessible: 1883 (MQTT), 3000 (Grafana), and 22 (SSH).

Transmitting sensor data from Raspberry Pi

We are going to upload a picture taken by the camera in the beginning. In a real system, we may want to upload continuous stream of image snapshots but that requires very high network bandwidth. We will upload the image using SCP (copy over SSH).

We will also transmit 64 IR pixel values as well average of all the IR pixel as a background temperature. We are going to read 64 IR pixel values from socket /var/run/mlx9062x.sock, calculate an average value and publish to MQTT broker in the following format.