Friday, July 12, 2024

More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Search in posts
Search in pages

Cloud Based Implementation Of Internet of Things (IoT) Using MQTT Brokers

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 Internet of Things (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 IoT

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 a various IoT projects 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.

- Advertisement -

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 Fig. 1.

Key constituents of MQTT
Fig. 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.

- Advertisement -

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 these MQTT brokers so that IoT communication is controllable over the Internet.

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 is a commonly used MQTT broker and can be used for IoT interfacing that gadget communication. IoT applications using CloudMQTT include multiple scenarios like smart toll plazas, smart cities, smart homes, or smart offices.

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 Fig. 2. The free instances can be built on the CloudMQTT network, using the current Google Account.

Creating a free instance on CloudMQTT
Fig. 2: Creating a free instance on CloudMQTT

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 Fig. 3.

Viewing authentication in CloudMQTT for connections
Fig. 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 Fig. 4. Such IoT MQTT applications communicate directly with the MQTT broker platforms so that the IoT apps, tablets, and cloud brokers can interact.

IoT MQTT apps on Google Play Store
Fig. 4: IoT MQTT apps on Google Play Store



DIoTY is another cloud based MQTT broker application with the free account that can be used to access IoT gadgets, as shown in Fig. 5. It provides the scripts so that MQTT broker connections can be rendered to various programming environments.

Dashboard of DIoTY
Fig. 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.”)
print(“Connection failed. CN= “+str(CN))
def on_publish(client, mySignalData,
print(“Message “+str(MyString)+”
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
[email protected]’, ‘7881730a’)
# Subscribing
# Publishing a message
mqttclient.publish(‘/’, 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 Fig. 6.

Receiving data on the DIoTY dashboard using MQTT
Fig. 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.

This article was first published in September 2020 issue of Open Source For You

Dr Gaurav Kumar is managing director of Magma Research and Consultancy and is associated with various academic institutes, where he delivers expert lectures and conducts technical workshops on the latest technologies and tools


Unique DIY Projects

Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components