Project 21:IoT Data Collection and Upload

In the previous lesson, we learned about IoT servers and setup. From this lesson, we'll gradually build an IoT system through practical operations, starting with environmental data collection.
Data collection and upload are core IoT system components. It uses sensors to convert physical-world information(e.g.temperature, humidity, and light intensity) into data, which is then aggregated to an IoT server for analysis and application. In this lesson, we'll take uploading onboard sensor data as an example to learn the IoT data collection and upload process. 


Project Objectives


Knowledge Objectives


1.Understand the principles of MQTT data transmission.
2.Build a local SloT server using the UNIHIKER K10.
3.Upload multiple sensor data streams to an loT platform.


Practical Objective 


Connect to a wireless network using the UNIHIKER K10, set up a local server with the help of the SIoT platform, and upload data.


Materials List

HARDWARE LIST
1 UNIHIKER K10
1 USB Cable

Preparations


Hardware


Connect the UNIHIKER K10 to the computer using a USB Cable.

 

Software


Open Mind+, switch to“Upload Mode”, connect the UNIHIKER K10 as shown in the figure below, and load the UNIHIKER K10 library.

 

Hands-on Practice


Network Configuration


First, check that your computer and the UNIHIKER K10 are connected to the same wireless network, to ensure they are on the same local area network.

 

Set up the server


Start the SIoT platform program
Download the Windows version of SIoT V2  and extract the SIoT_V2_Win.zip file.
After extraction, double-click start SIoT.bat to launch the new version of SIoT. Once launched, a small black command window pops up to start the server. Don't close it while the project is running, and note your computer's IP address.

Note: It's recommended to turn off all computer firewalls before starting, or external devices may not access.


After starting the server, open your browser, enter the local IP address followed by :8080 (e.g., 192.168.35.1:8080) to access the server login interface.

The login username is siot and password is dfrobot. Enter them to access the SIoT data management interface. The server setup is now complete.


Create a Topic


After successful login,create a new topic (e.g., "light") on the SIoT platform web page.
Note: After creation, double-click the topic name in the label (e.g., siot/light) to auto-copy the full topic name. The full topic name is in the siot/[topic name] format, with "siot/" added auto and no manual entry needed.

After creation, you can see the topic name. Click“Details”to enter the message sending and receiving interface of this topic.
Next, create other topic ("temperature", "humidity" )in the same way, ensuring each data type has its own independent and corresponding topic name.

Code  


Let's first load the required graphical libraries: in "Extension" → "Module", search for and load the graphical libraries for Wi-Fi and MQTT.

Next, let's look at data upload blocks: "MQTT send message “hello”to cloud platform “topic/a”and save to database (SIoT V2)" and "MQTT send message “hello”to cloud platform “topic/a”". Both can complete data upload on the SIoT V2 platform. The difference is that the former automatically saves data to the SIoT V2 database for viewing on the IoT platform, while the latter uses the server as a forwarding tool to reduce platform load, but the uploaded data can't be viewed on the platform.

Today, we use the "MQTT send message“hello”to cloud platform “topic/a”and save to database (SIoT V2)" block to upload environmental data. Taking the upload of light data as an example, the upload block is as follows:

Now, following the core logic of connect to network → MQTT initialization → connect to server, we can supplement and complete the preparatory work for data upload. The complete program code for uploading light data is as follows:

To make it easier to verify whether the platform data is consistent with the data collected by the sensor, we can also use variables to display the data on the screen. The complete reference code is as follows:

Run the Code


Click the“Upload”button and wait for the upload to finish. Then, wait a bit. If the network and server connection is successful, "Network connection successful" and "Server connection successful" will be shown on the screen in sequence. Once connected, you can view the real-time environmental light intensity values on the UNIHIKER K10 screen. 
Note: If unsuccessful, please check the network connection and ensure that the firewall is disabled.
Next, return to the subscribed topic tab in the SIoT platform and click“Details” to check the uploaded data.

After entering, check“Auto-Refresh”to view changing light data in real-time and compare if it matches the data on the UNIHIKER K10 screen.

Code Review

 

Category

Blocks

Function

This block is used to send messages to a specified topic on a server platform that supports the MQTT protocol. The sent messages are stored on the server platform for easy viewing.
This block is used to send messages to a specified topic on a server platform that supports the MQTT protocol.


Have a Try


Try to upload and display the temperature and humidity data by yourself.
Tip: You need to upload the data to the corresponding topic, as shown below:

Knowledge Base


Next, let's learn and summarize the hardware knowledge used in this lesson.
Further Exploration of the MQTT Protocol
Today we used the MQTT protocol to upload and collect environmental data. Unlike the last lesson where we subscribed to topics, we published data directly to topics during implementation. Why is that?
Think from the roles of the three MQTT-protocol components: publisher, broker, and subscriber, and you'll quickly get the answer.
- The publisher, the message sender, only sends messages to specific topics without subscribing. 
- The subscriber, the message receiver, subscribes to one or more topics to get new messages; it can't receive messages without subscribing. 
Alright, now let's level up the question: Can a publisher exist as a subscriber?
The answer is: Yes. We need to change the usage scenario to display the data received by the IoT platform or broker on the UNIHIKER K10 screen. The core code is as follows:

Let's see how this process is done. First, the UNIHIKER K10 (publisher) sends environmental light intensity data. When the data reaches the broker (server), the broker broadcasts it to the subscribed UNIHIKER K10 (subscriber), which then displays the data. In other words, from the device's view, a data-sending publisher that subscribes to a topic is both a publisher and a subscriber.

Challenge Task


Try to adapt the functions of "Project 9: Smart Night Light" to realize that it can not only automatically control the on/off of the light, but also remotely view the status of the night light on a computer in another room.
Tip: Upload the smart night light's status to the SIoT platform in real time.

icon project21.zip 13KB Download(0)
License
All Rights
Reserved
licensBg
0