This project briefly describes about creation of IoT Hub, digital twin and communication between them. The main goal is to measure the air quality in indoor environment and update the IoT devices with measurements. This project uses the air quality measurements from room. Now let us see how we can send these sensor data to IoT device which updates the Digital Twin. In this sample, we are sending sensor data to IoT device Raspberry1 which is in room Lobby100
In order to send data to the Digital Twin of Lobby100 and Raspberry1, we need to set up the corresponding Digital Twin infrastructure and the respective Digital Twins. The documentation for that is give in the folder digital_twin of this repository.
More specifically, we need the following prerequisites to be met:
- IoT-Hub, ADT-Service, TSI-Service are set up
- The services above are connected via the respective Azure functions
- A Digital Twin for Lobby100 and Raspberry1 is created in all of these services, using the example data provided in the digital_twin folder
To send the simulated data, we provide an example client app coded in Python, which is available via the following link: SimulatedDevice.py In order to run the app, we need to install required packages via the following command
pip install azure.iot.device
The configuration and running of the example client app is described in the following.
Download the python script SimulatedDevice.py and replace the connection string property with your own IoT device primary connection string to which the telemetry data is to be sent.
Get the IoT device connection string
Go to IoT Hub ---> click on specific IoT device to which you need to send data ---> detailed view of IoT device with properties such as device id, primary and secondary key etc
copy paste the connection string into the python script.
Datasets
We have obtained the real-time sensor data with SCD-30 sensors setup in three rooms and datacollection was made during the day time when people are working. The data collection set up is as follows :
Dataset | Room | Sensor_Type | No_of_Sensors | Time_Span |
---|---|---|---|---|
dataSet1.csv | Lobby100,Room102 | SCD-30 | 2 | 6 hours |
dataSet2.csv | Room101,Room102,Room103 | SCD-30 | 3 | 5 hours |
Dataset description:
a) dataSet1
1.Room 102
The dataSet1 was collected based on the following properties,There was maximum of two people working in Room 102 and windows were closed.
b) dataSet2
1. Room 101
The dataSet2 from Room 101 was collected when there were maximum of two people working in room for most of the time and three more people were also present in room for few minutes. The window was opened in the room for every one hour.
2. Room 102
The dataSet2 from Room 102 was collected when there were maximum of two people working in room for most of the time and two more people were also present in room for few minutes. The windows were closed in the room.
3. Room 103
The dataSet2 from Room 103 was collected when there was only one person working in room. The window was opened in the room for about three hours.
The sensor data from the datasets dataSet1.csv, dataSet2.csv is parsed to get co2 measurements. The measurements are then sent to Azure IoT devices. you can use the existing csv file for sample sensor data or replace with your own csv file with actual or mock up sensor values.
Using windows command line navigate to the folder in which the SimulatedDevice.py file is located (if you cloned the repository, then this is the current folder that you're in) python file. To run the app, execute the following command via the command line in this folder:
python SimulatedDevice.py
Example Output of the Client App
To validate the correct functioning of the app (or debug in the case of errors), two methods are possible:
Method-1: IoT Hub Overview
To verify if the telemetry data is sent to Azure IoT Device , there are metrics charts in IoT hub that shows the incoming device to cloud messages, messages used per day etc
Method-2: Azure CLI
Open the cloud shell from Azure portal and you need to create storage account when using it for first time.
Two cloud shells are present you can use either of them to test
-
PowerShell -command line for windows and
-
Bash- command line for Linux operating system
Install extensions in Azure CLI before using IoT commands
Required Extensions:
- azure iot extension
az extension add --name azure-iot
Monitor the events of IoT Hub device
az iot hub monitor-events --hub-name {iot hub name} --device-id {digital twin name} --consumer-group {consumer group name of iot hub events}
Replace the IoT Hub name, digital twin name and consumer group name accordingly.
We can see that telemetry data sent from client app is received in the Azure IoT digital twin model