{{announcement.body}}
{{announcement.title}}

Capture IoT Devices Data Via RabbitMQ

DZone 's Guide to

Capture IoT Devices Data Via RabbitMQ

The purpose of this article is to give you an overview of how to capture events from MQTT enabled IoT sensors/devices and monitors it via ELK stack.

· IoT Zone ·
Free Resource

Introduction

The purpose of this article is to give you an overview of how to capture events from MQTT enabled IoT sensors/devices and monitors it via ELK stack.

After capturing events, you could either store it in event-stores or in time-series database for further processing.

Here I am taking a very basic example of capturing an event i.e temperature change city wise.

Below are the popular Internet of Things protocols and standard communication technologies :

  • MQTT
  • DDS
  • AMQP
  • Bluetooth
  • Zigbee

For this tutorial I am using MQTT protocol.

MQTT — MQ Telemetry Transport

MQTT is a machine-to-machine (M2M)/”Internet of Things” connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.

MQTT Broker — RabbitMQ

MQTT Broker is a pre-requisite to capture MQTT events from IoT devices. Here I am using RabbitMQ as MQTT Broker

Check this before selecting MQTT Broker and for a basic understanding of RabbitMQ watch this.

MQTT Client — Mosquitto MQTT Publisher

To simulate the actual behavior of the IoT device’s event generation I am using Mosquitto MQTT publisher.

Installation

  1. Install RabbitMQ Server.
  2. Install mosquitto package.
  3. Set up ELK on your machine.

Make sure to enable mqtt plugin in rabbitmq using below command:

Java
 




x


 
1
rabbitmq-plugins enable rabbitmq_mqtt


Create a Queue


Bind Exchange to Queue

Publish a Sample Message


Check Whether the Message Is Received or Not


Publish Message From Mosquitto MQTT Publisher

Let’s try to send some messages from Mosquitto publisher using the below command :

Java
 




xxxxxxxxxx
1


1
mosquitto_pub -h 127.0.0.1 -t weather.mumbai -m {“temperature”:{“min”:21,”max”:29,”unit”:”celsius”},”time”:1568881230} -u guest -P guest -p 1883 -d


Check Whether the Message Is Received or Not in RabbitMQ Queue

How To Install Elasticsearch, Logstash, and Kibana (ELK Stack)

Start Logstash Server

Use the below configuration which will read weather.* events from RabbitMQ queue and will dump the same into weather index in Elastic Search.

Java
 




xxxxxxxxxx
1
18


 
1
input {
2
rabbitmq {
3
host => “localhost”
4
port => 15672
5
heartbeat => 30
6
durable => true
7
exchange => “amq.topic”
8
exchange_type => “topic”
9
key => “weather.*
10
}
11
}
12
output {
13
elasticsearch {
14
hosts => “localhost:9200
15
index => “weather”
16
}
17
stdout {}
18
}



Paste the above configuration in logstash-rabbitmq.conf file

Run Logstash Server

Java
 




xxxxxxxxxx
1


 
1
logstash -f <path>/logstash-rabbitmq.conf



Once logstash started successfully, you will be able to see logstash queue created and binded with weather* events in RabbitMQ

Let’s Publish Some Test Messages via RabbitMQ GUI

K ibana Dashboard

Let’s check Kibana whether it is receiving any events under weather-index or not.

As you could see in below Kibana search that Elastic-Search received some events in weather-mumbai index via logstash.

Publish Some Message From Mosquitto MQTT Publisher

Java
 




xxxxxxxxxx
1


 
1
$ mosquitto_pub -h 127.0.0.1 -t weather.mumbai -m {“temperature”:{“min”:21,”max”:32,”unit”:”celsius”},”timestamp”:”2019–09–19T18:59:00"}’ -u guest -P guest -p 1883 -d



Finally, you can see your messages in kibana, now you can configure Kibana Dashboards and create charts for ex: compare last 3 month temperature change etc.

Thanks for reading!

Hope you have enjoyed reading the article.

Topics:
elk, internet of things, kibana, mqtt, mqtt broker, rabbitmq

Published at DZone with permission of Ritresh Girdhar . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}