As living standards improve, people’s expectations for indoor environments are also rising. A comfortable indoor environment is extremely important for human health. Studies show that when the indoor temperature exceeds 28 °C and the humidity is higher than 70% RH, people are prone to feeling stuffy, sweaty, irritable, and fatigued, which can easily affect emotional stability and mental agility. When the indoor temperature falls below 20 °C, symptoms such as catching a cold are more likely to occur. Proper control of temperature and humidity is also a necessary condition for preventing the spread of germs.

The IoT Indoor Environment Monitor is a device that can monitor indoor temperature, humidity, light, and sound. These environmental data can also be uploaded to the SIoT platform, making it convenient for residents to view and analyze the data. By monitoring indoor environmental data, residents can adjust indoor temperature and humidity in a timely manner, thereby reducing the risk of disease.
Materials List
Hardware:

Software:
Mind+ Programming Software x1(download at https://mindplus.cc/en)

Goal
Display environmental icons and environmental data on the UNIHIKER, and send the environmental data to the SIoT platform according to their respective “Project ID / Device Name”.
Get to Know
1.Understand the architecture of the Internet of Things
2.Master the usage and working principle of the DHT11 sensor
Hands-on Practice
The IoT Indoor Environment Monitor can not only detect indoor temperature, humidity, light, and sound data, but also display these environmental data on the UNIHIKER. Finally, the environmental data are sent to the SIoT platform, where users can view the four types of data: temperature, humidity, light, and sound.
Task 1: Read Temperature and Humidity Sensor Values
Read the temperature and humidity data detected by the sensor and display the data on the UNIHIKER.
Task 2: Sending Data from the UNIHIKER to the SIoT Platform
Send the collected indoor environmental data to the SIoT platform via the MQTT protocol.
Task 1: Read Temperature and Humidity Sensor Values
1.Hardware Connection
The DHT11 digital temperature and humidity sensor is a composite sensor that can detect both temperature and humidity. Connect the temperature and humidity sensor to the P24 digital pin of the UNIHIKER. After the hardware connection is completed, use a USB cable to connect the UNIHIKER to the computer.
Note: For more information about the “DHT11 Temperature and Humidity Sensor,” refer to the Knowledge Base.

2.Software Preparation
Open Mind+ and follow the diagram below to complete the software preparation process.

Add the temperature and humidity sensor by clicking “Extensions”, find “DHT11 Temperature and Humidity Sensor” in the pinpong library, and click it to complete the addition.

3.Write a Program
After adding the temperature and humidity sensor library successfully, how can we obtain the data detected by the sensor? Use the “temperature and humidity sensor initialize pin” block, and initialize the pin as P24 under the “ Python main program start”.

To obtain the temperature and humidity values detected by the sensor, use the block below for reading temperature and humidity.

Then use the blocks for “displaying text” and “updating text content” to show the temperature and humidity data detected by the sensor on the UNIHIKER.
When temperature data and humidity data are displayed directly on the UNIHIKER, the two values can be easily confused. You can add text labels for temperature and humidity before the data. Use the “join” block to change the display format to “Temperature: temperature value”.

4.Run the Program
Click Run. After the program runs successfully, the UNIHIKER displays the real-time temperature and humidity data detected by the sensor.

5.Have a try
In the above program, the temperature and humidity data displayed on the UNIHIKER do not include units. In fact, from the temperature/humidity reading block, we can see that the unit of temperature is °C and the unit of humidity is %RH. Next, modify the program to add the corresponding units after the displayed temperature and humidity values.
Task 2: Sending Data from the UNIHIKER to the SIoT Platform
1.Software Preparation
(1)Enable the UNIHIKER SIoT Service
Long press the Home button on the UNIHIKER to enter the menu page, tap “Service Toggle”, and check whether the SIoT service is enabled. If it shows “Disabled”, tap the SIoT option and switch its status to “Enabled”.

(2)Add the MQTT-py Library
To send data to the SIoT platform, corresponding sending blocks are required. However, such blocks are not available in the UNIHIKER’s default block list. What should we do? Click “Extensions”, find “MQTT-py” in the official library, and click it to complete the addition.

2.Write a Program
Before writing the program, let’s analyze the functions that need to be implemented. First, the UNIHIKER interface needs to display indoor environmental data, including temperature, humidity, light, and sound values. Then, these indoor environmental data are uploaded to the SIoT platform according to their respective “Project ID / Device name”.

(1) Interface Design
To display indoor environmental data on the UNIHIKER, first design an attractive display interface. Import the background image and environmental icons from the image folder into the file system.

Use the image display block to show the background image and environmental icons on the UNIHIKER. Set the images to be displayed at the corresponding XY coordinates based on the icon coordinate analysis above.

Next, use the “text display” block and the “update text content” block to display temperature and humidity data, light data, and sound data on the UNIHIKER.

(2) Uploading Data
To upload data to the SIoT platform, first use the MQTT initial block to start the IoT server. Click the “Settings” icon and modify the “SIoT Server” address to the default IP address of the computer connected to the UNIHIKER: 10.1.2.3.

After initialization, initiate the MQTT connection using the “Connect MQTT” block. After a successful connection, keep the connection alive using the “MQTT stay connected,forever” block.

To send data to the SIoT platform, you must first subscribe to the topics used for sending data. Use the “MQTT Subscribe to” block. It should be noted that the topic format specified in the MQTT subscribe block is fixed as “Project ID / Device name”. Since four different environmental data types need to be sent to their corresponding topic channels, four different topics must be subscribed to.

After completing the four steps of MQTT initialization – connection – staying connected – subscription, you can then send data to the SIoT platform. Use the “MQTT Publish to” block to send environmental data to different channels on the SIoT platform every 5 seconds. After that, integrate the previously designed interface code to form the complete program as follows:

3.Run the Program
Run the program. After the program runs successfully, the Mind+ terminal prints “Connection Result: The Connection is successful,” and the UNIHIKER displays the corresponding environmental data. The program is set to send one set of environmental data to the SIoT platform every 5 seconds.To view the data, open a web browser and enter “10.1.2.3” in the address bar to access the UNIHIKER service page.

After entering the UNIHIKER service page, click “Service Toggle”, find SIoT, and click “Open Page” to enter the SIoT service page.

Enter the corresponding account and password, then click Log In.
Account: siot
Password: dfrobot

After logging in successfully, click “Device List” and find the subscribed topics.

Click “View Message” to see the corresponding data. Check the Auto Refresh Messages option so that the SIoT platform automatically refreshes messages whenever corresponding environmental data are received.

Click “Hide/Show chart” to view the line charts of the corresponding environmental data.

Knowledge Base
1. Understanding the Architecture of the Internet of Things
The Internet of Things (IoT) is a new type of information system, formed by the integration of three components:
- “Things”: Sensors, RFID devices, and various actuators that connect data information spaces with physical objects;
- “Network”: The use of the Internet to interconnect these things with the entire digital information space for widespread application;
- “Application”: Based on data collection and interconnection, large amounts of information are collected deeply, extensively, and automatically to achieve more intelligent applications.
Therefore, the architecture of the Internet of Things can be broadly divided into three layers: the perception layer, the network layer, and the application layer.

2. Understanding the Working Principle of the DHT11 Temperature and Humidity Sensor
The DHT11 digital temperature and humidity sensor is a composite sensor capable of collecting both temperature and humidity data. It adopts specialized digital module acquisition technology and temperature and humidity sensing technology to ensure the reliability and stability of the collected data.

Inside the sensor, a resistive humidity-sensing element is used to detect ambient humidity, and an NTC temperature-sensing element is used to detect ambient temperature.

In essence, the DHT11 temperature and humidity sensor converts data from temperature- and humidity-sensitive elements through corresponding circuit processing into digital values of temperature and humidity that can be directly read by the UNIHIKER.
3.Command Overview

Challenge
The above program completes the display of indoor environmental data on the UNIHIKER and also sends the data to the SIoT platform. The transmitted data are not filtered in any way. Research shows that when the indoor temperature exceeds 28 °C and the humidity is higher than 70% RH, people are prone to feeling stuffy, sweaty, irritable, and fatigued.
Next, create a new environmental data warning topic. When the temperature is higher than 28 °C, send “Current temperature is too high!” to the SIoT platform; when the humidity is higher than 70% RH, send “Current humidity is too high!” to the SIoT platform. The effect is shown in the figure below.









