DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Connecting the Dots: Unraveling IoT Standards and Protocols
  • Harnessing the Power of MQTT for the Future of IoT
  • 5 Data Models for IoT
  • A Camunda Greenhouse: Part 3

Trending

  • Event-Driven Pipelines With Apache Pulsar and Go
  • Identity in Action
  • Building AI-Powered Java Applications With Jakarta EE and LangChain4j
  • Slopsquatting: Building a Scanner That Catches AI-Hallucinated Packages Before They Reach Production
  1. DZone
  2. Data Engineering
  3. Data
  4. Capture IoT Devices Data Via RabbitMQ

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.

By 
Ritresh Girdhar user avatar
Ritresh Girdhar
·
Updated Jul. 08, 20 · Opinion
Likes (5)
Comment
Save
Tweet
Share
15.8K Views

Join the DZone community and get the full member experience.

Join For Free

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.

IoT MQTT Event Data (computing)

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

Opinions expressed by DZone contributors are their own.

Related

  • Connecting the Dots: Unraveling IoT Standards and Protocols
  • Harnessing the Power of MQTT for the Future of IoT
  • 5 Data Models for IoT
  • A Camunda Greenhouse: Part 3

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook