Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
101 views

A Web-Based IoT Solution For Monitoring Data Using MQTT Protocol

Uploaded by

nazm basm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views

A Web-Based IoT Solution For Monitoring Data Using MQTT Protocol

Uploaded by

nazm basm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

A Web-Based IoT Solution for Monitoring Data

Using MQTT Protocol


Krešimir Grgić Ivan Špeh, Ivan Heđi
Faculty of Electrical Engineering, Computer Science and ICT Department
Information Technology Osijek Virovitica College
University of Osijek, Osijek, Croatia Virovitica, Croatia
kresimir.grgic@etfos.hr ivan.speh@vrmti.hr, ivan.hedi@vsmti.hr
.

Abstract —In this paper, a web-based Internet of things mentioned area different improvements are achieved using
solution aimed for monitoring, tracking and analyzing data in enhanced tools for real-time monitoring and tracking, decision-
agriculture area is proposed. The purpose of the presented making support, automatization of processes, analyzing data
solution is to facilitate monitoring of different manufacturing and reporting.
process in mentioned area using IoT technologies. A real time
data is achieved using broker-based publishing/subscribing
Message Queue Telemetry Transport protocol which is briefly II. BACKGROUND
described. Using this protocol limitations resulting from To understand the need for this type of IoT implementation,
constrained networks in rural areas are avoided. Collected data a short brief of the drying process is explained. Drying process,
from sensors is shown and stored in web part of the information as the one of the most important postharvest treatment, ensures
system. An architecture of the web application is described as a storage durability, reduces the spoilage and increases the shelf
client-server three-tier architecture in which the graphical user life of agricultural products. To ensure the quality of the final
interface (presentation layer), application functions and logic product, the temperature and moisture factors must be
(application layer) and computer data storage (database layer) monitored during the drying process. If the value of
are developed and maintained as independent modules, on
temperature and moisture offset is greater than tolerance
separate platforms. This type of implementation is developed by
the manufacturers need for monitoring and tracking data. This
setpoint, manufacturers must take additional actions. Although
architecture is based on future concrete implementation, at least these actions are semi-automated using gas or oil burning
in segments, in several agricultural facilities in Virovitica- stoves, most manufacturers are using wood as fuel. Cost-
Podravina County. effectiveness analysis shows that price of drying process using
wood as fuel is 70% lower than using oil or gas. Today, almost
Keywords—Internet of things; monitoring; MQTT; Raspberry Pi; 80% of small manufacturers are using wood as fuel. One of the
sensors; three-tier architecture; web application main drawbacks of using wood burning stoves is an obligation
for temperature surveillance 24 hours a day, seven days a
I. INTRODUCTION week. Temperature and moisture sensors are already installed
in facilities and the values are shown on the control board
Internet of things (IoT) is no longer future tech trend installed at the front side of the facility. To successfully finish
because of an everyday growing number of objects connected the process, manufacturers must manually check values within
to the Internet worldwide. IoT can be defined as a network of a period of the time which is most often a problem, especially
objects which are equipped with sensors and network access during the night. This paper proposes distance monitoring
modules [1]. IoT object can be any device, vehicle or building system for temperature/moisture surveillance over the web-
from everyday life. With appropriate electronics and software, based graphical user interface. Already installed sensors are
these objects are able to collect and share data. According to connected to devices (e.g. Arduino Uno, Raspberry Pi) whose
[2] Gartner says that 6.4 Billion connected objects will be in main task is to send data (i.e. temperature and moisture values)
use in 2016., 30% more than in 2015. That number will grow to a central server over publish/subscribe messaging protocol
up to 20 billion by 2020. IoT represents the next evolution of MQTT. Central server has MQTT broker role, and his main
the Internet and extends its ability to gather, analyze, and task is to multicast data to subscribed devices. Also, during the
distribute data which can be turned into information and real-time monitoring, collected data is sent to web server and
knowledge. Furthermore, IoT has made Internet sensory SQL server where the data is stored for the purpose of the
(temperature, pressure, vibration, light, moisture, stress) future analysis and reporting.
thereby achieving improved monitoring, analyzing and
tracking systems [3]. IoT is present in almost every human
area: society, tourism, education, supply chain management, III. MESSAGE QUEUING TELEMETRY TRANSPORT
military, healthcare, industry and many others. This paper is a The main characteristic of IoT devices is the machine-2-
proposal for IoT implementation in the agriculture area, machine communication which is in this paper presented as a
focused on drying of agricultural products, especially tobacco, communication between multiple sensor devices and a single
chamomile, wheat, fruits or even lumber. Using IoT in data collection device. These sensor devices are most often

978-1-5090-3720-9/16/$31.00 ©2016 IEEE

249
978-1-5090-3720-9/16/$31.00 ©2016 IEEE
installed in isolated area where connection to the Internet is to distinguish data sent by the publisher, a topic string is used.
limited. For example, most of the facilities are built in rural For example, a client can publish temperature and humidity
areas where connection to the Internet is realized over slow values using different string for each value (e.g. temp/25 or
DSL connection or cellular network. In such environment, hum/40). On the other side, if a MQTT client wants receive the
unreliability which reflects high packet loss rate is one of the data, he must subscribe to the specific topic. To make a MQTT
main disadvantages [4]. There are several protocols proposed client from a device, an MQTT library must be installed and
for M2M/IoT communication with a focus on mentioned connection to an MQTT broker must be established over any
constrained environments. Most frequently adopted protocols kind of network. For example, MQTT client can be a small
are MQTT (Message Queue Telemetry Transport) and CoAP computer (Arduino or Raspberry Pi) connected to a wireless
(Constrained Application Protocol). IoT applications can be network with a library strapped to the minimum or a typical
simplified in the way of the error handling which can be done computer running a graphical program. The client
using these protocols [4]. implementation of the MQTT protocol is simplified and very
straightforward [5].
MQTT is a machine-to-machine (M2M)/Internet of Things
connectivity protocol for use on top of the TCP/IP protocol Temperature Web
stack which was designed as an extremely lightweight broker- sensor application

based publish/subscribe messaging protocol for small code


footprints (e.g., 8-bit, 256KB ram controllers), low bandwidth MQTT Server (broker)
and power, high-cost connections and latency, variable MQTT MQTT

availability, and negotiated delivery guarantees [9]. In the hub MQTT Client
message Subscription on topic
temperature
message
MQTT Client
and spoke model of Message Oriented Middleware messaging (publisher) (subsriber)

server forwards messages from sensor devices to monitor


devices [7]. In such architecture, a sensor device whose main
task is to continuously produce and send data to server is
defined as publisher. Central server, an MQTT broker, collects
messages from publishers and examines to whom the message TCP/IP network

needs to be send. On the other side, every device who had Fig. 1. Message queuing telemetry transport protocol model
previously registered its interests with a server will keep
receiving messages until subscription is canceled (Fig. 1). Client libraries can simplify the process of writing MQTT
Using this architecture, publishers and subscribers do not need client applications. MQTT libraries are available for different
to know for each other which is one of the major advantages of types of programming languages and platforms, for example,
this protocol. For example, temperature sensor devices need JavaScript, PHP, C, C++, Android, iOS etc. For the initial
not to know who are the clients that are subscribed for implementation, Python library will be used.
receiving data and conversely [13]. So, the publishers and
subscribers do not need to participate in the communication at B. MQTT Broker
the same time and do not need to be familiar with each other An MQTT broker is a central device in mentioned hub and
[16]. It is intended for devices with limited power and memory spoke model. The main responsibilities of an MQTT broker are
capabilities, where the network is expensive, has low handling communication between MQTT clients and
bandwidth or is unreliable. One of the key requirements of an distributing messages between them [4]. A broker can handle
Internet of Things concept is low network bandwidth used to up to thousands connected MQTT client at the same time.
send data and minimal device resource requirements. While When the message is received, broker must find all the clients
attempting to ensure reliability and delivery, MQTT has met that have a subscription to the received topic [5]. In presented
these requirements [12]. This protocol has been applied in a application, it is responsible for receiving messages from the
variety of embedded systems. For example, hospitals use this sensors connected to the device with implemented MQTT
protocol to communicate with pacemakers, oil and gas client library and forwarding it to the designated mobile device.
companies use it to monitor oil pipeline thousands of miles There are plenty other tasks and responsibilities that are
away. Facebook uses this protocol for messaging applications handled by the broker. First of all, there is authentication and
[17]. Fig. 1 shows proposed model of MQTT protocol which authorization of the clients for the security purposes. A client
runs on TCP/IP connection. can send username and password within connect message that
will be checked by the broker. On the broker side topic
A. MQTT Client permission is implemented in order to restrict client to publish
Any IoT object can be MQTT client that sends or receives or subscribe. Furthermore, for encrypted communication
telemetry data. This could be any device from a between the broker and the clients, TLS (Transport Layer
microcontroller up to a server. The type of the MQTT client Security) and SSL (Secure Sockets Layer) encryption is used,
(subscriber or publisher) depends on its role in the system. It the same security protocol that can be used by the HTTP
can produce or collect telemetry data. In both cases, MQTT protocol [14]. It is also possible to implement custom
client should first connect to a messaging server using a authentication or authorization logic into system [5]. There are
particular type of message explained in the following chapter. several message brokers that implement MQTT protocol like
After the connection is successfully established, a client must Mosquito - open source MQTT v3.1/v3.1.1. broker [18] and
declare himself whether he is a subscriber or publisher. In order HiveMQ – an enterprise MQTT broker [5].

250
C. MQTT over WebSockets As it is shown in Fig 1., the publisher must send a
Using MQTT over WebSockets every browser can be PUBLISH packet with QoS = 0 and receiver accepts ownership
MQTT device. Due the publish/subscribe pattern of MQTT a of the message when it receives the PUBLISH packet.
real-time communication between end device (e.g. temperature When using QoS level 1, it is guaranteed that a message
sensor) and monitor device (e.g. a web application) is achieved. will be delivered at least once to the receiver. The publisher
Using QoS 1/2 message will arrive on the client or broker at sends the message and checks the delivery status using
least once/exactly once. The broker will queue all messages PUBACK message. If PUBACK message is lost, the broker
which client misses when it’s not connected. Messages which will send the same message again, until PUBACK message is
are retained on the server are delivered when a client received.
subscribes to one of the topics instantly. Paho.js [19]
implements this behavior and will be used in initial testing. PUBLISHER BROKER SUBSCRIBER

D. Message format STORE


MESSAGE
The message header for each MQTT command message
contains a fixed header with length of 2 bytes and an optional PUBLISH [QoS = 1]

message-specific variable length header and message payload STORE


MESSAGE

PUBLISH
TABLE I. MQTT MESSAGE

Bit 7 6 5 4 3 2 1 0
PUBACK
Byte 1 Message type DUP QoS RETAIN
DELETE
Byte 2 Remaining length MESSAGE

Byte 1 contains the Message type which is represented as a Fig. 3. At least once delivery (MQTT QoS =1)
4-bit unsigned value. There is 14 message type specified in 3.1
version of MQTT protocol. CONNECT (client request to In QoS Level 2, also called “assured delivery” and shown
connect to server), PUBLISH (publish message), PUBACK in Fig 3., the messages are delivered exactly once using a 4-
(publish acknowledgment), SUBSCRIBE (client subscribe way handshake. Using QoS level 2 it is possible to have
request) are some of the message types. A detailed description relatively longer end-to-end delay, but there is no messages
of the message types can be found in protocol specifications loss.
[10] and [11]. DUP flag is set when the client the client or
server attempts to re-deliver a PUBLISH, PUBREL, PUBLISHER BROKER
SUBSCRIBE or UNSUBSCRIBE message. This applies to
messages where the value of QoS is greater than zero (0), and STORE
an acknowledgment is required. QoS flag indicates the level of MESSAGE

assurance for delivery of a PUBLISH message. The QoS levels PUBLISH [QoS = 2]

are described in next chapter. If RETAIN flag is set to true, STORE


normal MQTT message becomes retained message. The broker MESSAGE

will restore last retained message with corresponding QoS for PUBLISH
specific topic. Each client that subscribes to this topic pattern PUBREC
will receive the retained message immediately. The broker will
save only one retained message per topic [5]. Remaining length PUBREL

represents the number of bytes remaining within the current DELETE


MESSAGE
message, including data in the variable header and the payload.
PUBCOMP

E. Quality of Service DELETE


MESSAGE
MQTT ensures reliability by providing the option of three
QoS levels: At QoS = 0 publisher sends a message at most
once and does not check if the message arrived at its Fig. 4. Exactly once delivery (MQTT QoS =2)
destination. No response is sent by the receiver, and no retry is
performed by the sender. This lower level is also called “fire
and forget” and the message can be lost depending on the IV. WEB-PART ARCHITECTURE
network condition [8]. An architecture of the web part of the proposed information
system can be described as a client-server three-tier
PUBLISHER BROKER SUBSCRIBER
architecture in which the graphical user interface (presentation
PUBLISH [QoS = 0] layer), application functions and logic (application layer) and
PUBLISH
computer data storage (database layer) are developed and
maintained as independent modules, on separate platforms.
DELETE
MESSAGE

Fig. 2. At most once delivery (MQTT QoS = 0)

251
On the presentation layer, functionality of HTML-based Ajax request sent by the client is received from the application
graphical user interface has been extended with custom layer via PHP scripts. There are three types of PHP scripts:
JavaScript/jQuery functions and several bootstrap friendly 1) PHP script that handles user’s actions and receives
jQuery plugins. Using AJAX for communication with Apache data from MQTT broker – used for inserting, updating
web server, features of a single page application are achieved. and deleting data from data server
When a user action generates a client call to retrieve new data, 2) A PHP script that prepares data – after a request for
the server only returns view fragments. This means that is data is received, this type of script is used for
possible to update parts of the application, without reloading connecting and retrieving data from MySQL server
entire viewport. At the side of design, the bootstrap responsive which is then encoded in JSON format and sent back
framework is used. Data received on the MQTT Broker from to client
publishers is automatically forwarded to MQTT client devices 3) configuration PHP – used for manipulating with
where the gauges and diagrams are updated with fresh data session storage, database connection, and other
(Fig.5.). A central monitor device, also MQTT client, has a application configuration variables.
task to send data to the Web server in application layer where
data is validated and prepared for inserting into SQL tables. On the database layer, there are several MySQL database
servers where data is stored and retrieved. Data in this tier is
There is one central monitor device in system. Saved data can
be used to create different types of reports and analyze, which kept independent of application servers. There is the database
can be shown on other end-user devices in presentation layer. used for configuration storage, data storage and domain with
There are two types of ajax communication (both include user storage.
AJAX request and response) between presentation layer and
application layer: saving data (central monitor device) and V. IMPLEMENTATION DETAILS
reading data (all devices in presentation layer). So, data A prototype of proposed system is implemented in a
preview on graphical user interface of devices in presentation tobacco drying kiln type SD – 78/2 (7270mm x 3150mm x
layer can be directly from MQTT broker, or requested from 2850mm) with two chambers (Fig. 6) and integrated wood
server with several filters applied (date, time, facility id, burning stove TD – 80 (Fig. 7).
process id).
MySQL
server
Database layer

Configuration Data Users


query

result
SQL
SQL

Apache Fig. 6. Drying kiln with inside chambers


Web server
Application layer

PHP
PHP json
PHP config PHP action
creator On the front side of the facility, the control board is
attached to the kiln. On the control board, there are several
switches used for managing and monitoring drying process. As
mentioned, for initial test RaspberryPi model 3 is used. Main
XMLHttpResponse
XMLHttpRequest

AJAX response
AJAX request

differences between RPi model 3 and prior versions are


GET, POST

JSON

integrated wireless module (802.11n), integrated Bluetooth


module (Bluetooth 4.1) and 1.2GHz 64-bit quad-core ARMv8
CPU. Using this type of RPi there is no need for additional
Browser
HTML,
modules for connecting end device to the network. Using
1602A LCD screen attached to the control board, temperature
Presentation layer

JavaScript,
Jquery,
CSS and humidity values are shown on the board.

CENTRAL MONITOR
DEVICE

MQTT
Broker

Fig. 5. Web application architecture

Fig. 7. Raspberry Pi with connected display attached to burning stove

252
protocol limitations resulting from constrained networks in
rural areas are avoided. In proposed model the client producing
data (publisher) sends data to the server which forwards data to
end user devices. Also, the architecture of web-based
application aimed at showing results collected from sensors is
presented. Architecture is described as client-server three-tier
architecture with three separate layers – presentation,
application and database layer.

REFERENCES

[1] F. Xia, L.T. Yang, L. Wang, and A. Vinel, “Internet of things,”


International Journal of Communication Systems, vol. 25, pp. 1101-
1102, 2012.
Fig. 8. Connected temperature sensor in lab environment
[2] S. Charmonman, P. Mongkhonvanit, V. Dieu, and N. Linden
Temperature measurement is achieved using the DS18B20 “Applications of internet of things in e-learning,” International Journal
sensor that provides 9-bit to 12-bit Celsius temperature of the Computer, the Internet and Management, vol.23, no.3, pp. 1-4,
September-December 2015.
measurement. DS18B20 communicates with RaspberryPi over
[3] D. Evans, “The internet of things – how the next evolution of the
one data line [20]. After connecting the sensor to RPi as shown internet is changing everything,” white paper, April 2011.
in Fig. 8, data can be sent to the central server (broker). For
[4] L. Dürkop, B. Czybik, and J. Jasperneite, “Performance evaluation of
reading data from sensors and sending values to the broker, M2M protocols over cellular networks in a lab environment,”
Python language with Paho Python MQTT library is used. In Intelligence in Next Generation Networks (ICIN), February 2015, pp.
this library, a client class is implemented and RPi is extended 70-75.
with MQTT support [5]. [5] HiveMQ Enterprise MQTT Broker. (2016, Feb. 8). [Online]. Available:
http://www.hivemq.com/.
[6] Scalagent, “JoramMQ, a distributed MQTT broker for the internet of
import paho.mqtt.client as paho things,” white paper, September 2014.
import time [7] Scalagent, “Benchmark of MQTT servers,” white paper, January 2015.
client = paho.Client() [8] E.P. Frigieri, D. Mazzer, and L. Parreira, “M2M protocols for
client.on_publish = on_publish constrained environments in the context of IoT: A comparison of
approaches,” in International Telecommunications Symposium.
client.connect("193.198.57.183", 1883)
client.loop_start() [9] V. Gazis et al., “A survey of technologies for the internet of things,” in
International Wireless Communications and Mobile Computing
while True: Conference, August 2015, pp. 1090-1095.
temperature = read_temperature() [10] International Business Machines Corporation (IBM), “MQTT V3.1
(rc, mid) = client.publish Protocol Specification,” August 2010.
("test/temp", str(temperature), qos=1) [11] A. Banks, R. Gupta, “MQTT Version 3.1.1,” Octobar 2014.
time.sleep(30) [12] V.Lampkin et al., Building Smarter Planet Solutions with MQTT and
IBM WebSphere MQ Telemetry, First Edition, September 2012.
Fig. 9. Publishing data with Python
[13] D. Thangavel, X. Ma, A. Valera, H. Tan, and C.K. Tan, “Performance
The portion of code in Fig. 9 shows how to publish data. evaluation of MQTT and CoAP via a common middleware,” Intelligent
Sensors, Sensor Networks and Information Processing, April 2014.
After the client is created, it connects to the broker and starts
[14] V. Karagiannis, P. Chatzimisios, F. Vazquez-Gallego, and J. Alonso-
the background network thread. It then starts a loop reading Zarate, “A survey on application layer protocols for the internet of
from sensors every 30 seconds and publishing the value to the things,” Transaction on IoT and Cloud Computing, vol 1., January 2015.
topic test/temperature. On the other side, an open source [15] K. Tang et al., “Design and implementation of push notification system
MQTT Mosquito broker installed on linux server is used to based on the MQTT protocol,” in International Conference on
multicast data to subscribed devices. After receiving data on Information Science and Computer Applications, September 2013.
the subscribed device, data is sent from central monitor device [16] S.K. Shriramoju, J. Madiraju, and A.R. Babu, “An approach towards
to WEB and SQL server as shown in the previous chapter. For publish/subscribe system for wireless networks,” International Journal of
Computer and Electronics Research, vol. 2., pp. 505-508, August 2013.
the purpose of central monitor device, PC is used.
[17] E.G. Davis, A. Calaveras, and I. Demirkol, “Improving packet delivery
performance of publish/subscribe protocols in wireless sensor
VI. CONCLUSION networks,” Sensors, 2013.
This paper has proposed IoT solution for realizing real-time [18] Eclipse Mosquitto. (2016, Feb. 12). [Online]. Available:
http://mosquitto.org/-
web-based solution aimed for monitoring and tracking
[19] Eclipse Paho JavaScript Client. (2016, Feb. 12). [Online]. Available:
temperature and moisture values in the agricultural drying https://eclipse.org/paho/clients/js/.
process. The focus was on reliable delivery of data from [20] Maxim Integrated. (2016, Feb. 14). [Online]. Available:
sensors to end user devices using broker-based www.maximintegrated.com.
publish/subscribe messaging protocol MQTT, which main
characteristics are low overhead, asynchronous
communication, low complexity and low power. Using this

253

You might also like