Cloud Based Implementation of IoT Using MQTT Brokers

0
4133

Message Queuing Telemetry Transport (MQTT) is a standardised, lightweight protocol that transmits messages between connected objects in an IoT network.

A number of devices and gadgets communicate in real-time using advanced wireless technologies. Smart cities, smart offices, smart homes, etc, are interconnected specifically by the IoT in which gadgets and smart objects communicate with each other using specific wireless protocols. IoT is also referred to as Ubiquitous Computing or Pervasive Computing, and there are many real-time applications of these technologies. The FASTags introduced in the country recently to pass through toll plazas is a classical implementation of IoT, in which a small chip on a vehicle communicates with the nearby sensor and a transaction is done automatically.

In such scenarios, the scalability as well as reliability issues are addressed by high-performance network communications or advanced wireless communications using 4G, 5G and related technologies.

Protocols and engines for the implementation of Internet of Things
IoT helps smart gadgets communicate using less resources and minimum power consumption. In the IoT environment, MQTT is a specific protocol for low-powered and lightweight communication so that there is minimum load on devices and gadgets. It is the key data protocol used in IoT for swift communication in low-powered devices.

Lightweight and low-powered communication needs to be speedy and reliable in order to operate on high frequency network communications with various devices. MQTT enables this communication between a large number of devices and gadgets with varying configurations.

Layer Protocols
Data protocols MQTT, AMQP, CoAP, Node, Websocket
Infrastructure 6LowPAN, RPL, IPv4/IPv6
Communication transport Wi-Fi, LPWAN, Bluetooth
Semantics Web Thing, JSON-LD
Discovery Physical Web, DNS-SD, mDNS
Device management OMA-DM, TR-069
Identification URIs, EPC, IPv6, uCode


Dimensions of MQTT broker

In IoT communication, there are mainly two types of objects — publisher and subscriber. Data signals transmission is known as publishing. Technically, the transfer of data from the computer to a separate end is called publishing.

The sender of data signals is known as publisher and the receiver is referred to as subscriber. The MQTT broker is the central point or simply the IoT server that controls the communication between publisher and subscriber. It handles the data that the publisher transmits for other gadgets known as subscribers, as shown in Figure 1.

Figure 1: Key constituents of MQTT

For instance, if data is to be transferred from a temperature sensor to a farmer’s handheld phone, the data signals are sent by the temperature sensor (publisher) while the farmer’s device is the receiver (subscriber) of data.

A number of MQTT brokers are available in the free and open source space including Mosquitto, which implements the MQTT protocol for IoT based communications. It’s lightweight, high performance and suitable for use on all devices, from low-power single boards like Arduino and ESP8266 to computers and servers. Instead of a local PC, Mosquitto can be deployed on a cloud based server that implements this broker so that IoT communication is controllable over the Internet.

MQTT applications URL
Cloud MQTT cloudmqtt.com
Mosquitto mosquitto.org
EMQ X emqx.io
FLESPI flespi.com
Bevywise MQTTBroker bevywise.com/mqtt-broker
M2MQTT github.com/eclipse/paho.mqtt.m2mqtt
Mosca github.com/mcollina/mosca
Paho MQTT eclipse.org/paho
Rabbit MQ rabbitmq.com
Thingstream thingstream.io
VerneMQ vernemq.com
HiveMQ hivemq.com
MOQUETTE github.com/moquette-io/moquette
wolfMQTT wolfssl.com/products/wolfmqtt
EMQTTD emqtt.io
NET-MQTT hackage.haskell.org/package/net-mqtt
FLUUX mqtt.fluux.io

MQTT broker applications can be installed on specialised devices such as Raspberry Pi, Arduino, laptops, servers, and many others for real world applications.

Cloud platforms for MQTT
A number of MQTT cloud broker services are available, in which the MQTT brokers are available as infrastructure on demand without any physical deployment of these.

CloudMQTT
URL: https://www.cloudmqtt.com
CloudMQTT is a commonly used MQTT broker and can be used for IoT interfacing and gadget communication. IoT applications using CloudMQTT include multiple scenarios like smart toll plazas, smart cities, smart homes or smart offices.

Figure 2: Creating a free instance on CloudMQTT

For researchers, the CloudMQTT includes the free package named ‘Cute Cat’ in which five users/ connections can be created and the IoT devices can be connected, as shown in Figure 2. The free instances can be built on the CloudMQTT network, using the current Google Account.

The key features of Cloud MQTT broker are:

  • 24×7 availability of MQTT broker
  • Managed Mosquitto servers in the cloud
  • Mosquitto implements the MQ Telemetry Transport protocol
  • Lightweight methods for messaging using a publish/subscribe message queuing model

The authentication details from CloudMQTT can be used in the IoT hardware or smartphones so that a real-time connection is established between CloudMQTT and gadgets, as shown in Figure 3.

Figure 3 Viewing authentication in CloudMQTT for connections

A variety of Android applications are available at the IoT MQTT dashboard on Google Play Store, as shown in Figure 4. Such IoT MQTT applications communicate directly with the MQTT broker platforms so that the IoT apps, tablets and cloud brokers can interact.

Figure 4 IoT MQTT apps on Google Play Store
Figure 4 IoT MQTT apps on Google Play Store

DIoTY
URL: http://www.dioty.co
DIoTY is another cloud based MQTT broker application with the free account that can be used to access IoT gadgets, as shown in Figure 5. It provides the scripts so that MQTT broker connections can be rendered to various programming environments.

Figure 5: Dashboard of DIoTY

The following programming platforms can be used for communication between MQTT broker and smart gadgets for publishing as well as subscribing the data and signals:

  • C#
  • Java
  • Python
  • Arduino
  • Node.JS
  • PHP
  • Go-Lang
  • NodeMCU

Paho Client is one of the best libraries in Python used for communication and interfacing the devices. For implementation using Python, the package ‘paho-mqtt’ is installed as follows:

$ pip install paho-mqtt

The following is the code snippet that can be integrated with IoT based devices and gadgets:

import paho.mqtt.client as mqtt
# Define event callbacks
def on_connect(client, mySignalData, CN):
if CN == 0:
print(“Connected successfully.”)
else:
print(“Connection failed. CN= “+str(CN))
def on_publish(client, mySignalData, MyString):
print(“Message “+str(MyString)+” published.”)
def on_subscribe(client, mySignalData, MyString, granted_qos):
print(“Subscribe with MyString “+str(MyString)+” received.”)
def on_message(client, mySignalData, msg):
print(“Message received on topic “+msg.topic+” with QoS “+str(msg.qos)+” and payload “+msg.payload)
mqttclient = myMQTT.Client()
# Assign event callbacks
mqttclient.on_connect = on_connect
mqttclient.on_publish = on_publish
mqttclient.on_subscribe = on_subscribe
mqttclient.on_message = on_message
# Connect
mqttclient.username_pw_set(‘kumargaurav.in@gmail.com’, ‘7881730a’)
mqttclient.connect(‘myMQTT.dioty.co’, 1883)
# Subscribing
mqttclient.subscribe(‘/kumargaurav.in@gmail.com/’)
# Publishing a message
x=input(‘Message’)
mqttclient.publish(‘/kumargaurav.in@gmail.com/’, x)
# Loop; exit on error
CN = 0
while CN == 0:
CN = mqttclient.loop()
print(“CN: “ + str(CN))

After executing the Python script, the data is handled and processed by MQTT broker, as shown in Figure 6.

Figure 6: Receiving data on the DIoTY dashboard using MQTT

Scope for research and development
Research scholars, academicians and practitioners can carry out research and make innovative problem statements on IoT using MQTT brokers. A number of research statements and domains exist in which MQTT based implementations can be done including telemedicine, personal security gadgets, defence equipment, military devices, agribots for smart agriculture, and many others.

LEAVE A REPLY

Please enter your comment!
Please enter your name here