Create a Virtual Sensor Using MQTT
image
MQTT stands for message queuing telemetry transport. It is basically a protocol for IoT that work on principle of publisher and subscriber where publisher is client and subscriber is server. It is a light weight and simple protocol with easy use. MQTT service run on two different port 1883, 8883. It an application layer protocol. It support TLS (Transport Layer Security) on port 8883 and plain text on 1883.
 

Usage of MQTT

In real world the MQTT is used in exchanging of data between MES manufacturing execution center SCADA system supervisory control and data acquisition. MQTT protocol can help anyone in monitoring infrastructure remotely.

Architecture

cavsum2
Application required for virtual iot

Setup Virtual Sensor (Publisher)

Virtual Sensor is an easy way to generate sensor data in JSON format without having a real life sensor.

With the help of virtual sensor we can visualize real life iot and can get the data of the sensor with virtual sensor we can perform the real life iot experiment so that we can perform our experiment without any hardware. In this virtual sensor we get some options

To download and install virtual sensor just follow the link given below



cavsum3
Options in Virtual Sensor

cavsum4
Running virtual sensor

By default virtual-sensor send data to local MQTT server and publish data on “sensors/temperature/data”

cavsum5
Virtual sensor name and value can be customized using different options like –name, –min, –max.

cavsum6
Install Mosquitto service

Virtual sensor need a MQTT broker to send data. Which can be installed on localhost or any other server.

There are multiple MQTT broker service available on internet as well some applications also provide GUI interface with services.

Here we are going to use mosquitto service for MQTT broker for some reasons.

To install mosquitto service in Debian based system run the following command.

cavsum7
Command used

  • apt-get install mosquitto
  • Starting mosquitto service
  • Service mosquitto start

Installation of MQTT Explorer

MQTT explorer is the GUI dashboard which can connect to MQTT broker and monitor the receiving sensor data.

To Download MQTT Explorer follow the below link.

https://github.com/thomasnordquist/MQTT-Explorer/releases

Now go to assets and the appropriate file as per operating system. Here we will be downloading AppImage format.

cavsum8
after this your MQTT Explorer will be downloaded and to run this we need to make the file executable.

Now execute MQTT Explorer (./MQTT-EXPLORER-0.3.5.AppImage)


cavsum9
And finally you will have a GUI


cavsum10

Running Virtual-Sensor & Monitoring visualization:

Run virtual-sensor as a light sensor where –i represents the MQTT Broker IP Address

Now execute the following command

node virtual-sensor.js –name “light-sensor” –min=300 –max=500 –i “IP_ADDRESS”

it will make Virtual Sensor to connect with MQTT broker.



cavsum11
Now Connect MQTT Explorer to MQTT Broker and we can see all the sensor data coming to broker and visualize it.


cavsum12

Hence we created a small virtual lab which is using MQTT Service.

Using the above technique we can make a whole IoT network. Our Cyber Range is a complete infrastructure with features like vulnerable IoT, Adversary Simulation , LMS (Learning Management System), Red and Blue Training