The IoT not only helps us upload and record data, but also removes the limitations of physical space, making remote control possible. In this lesson, we'll build a system for remote control of windows and explore various ways of IoT-based remote control.
Project Objectives
Knowledge Objectives
1.Understand feedback mechanisms in lol systems.
2.Subscribe to topics and parse received data.
3.Implement multi-mode remote control.
Practical Objective
Build a local server with SIoT to remotely control servo motor rotation, which drives the window to open or close. Add multi-mode control for switching between automatic and manual modes. In automatic mode, the window closes when light is dim and opens when it's sufficient.
Materials List
Preparations
Hardware
(1) Insert the servo into servo port S1 with correct polarity: align the yellow signal wire with the green pin on the expansion board.

(2) Stand the UNIHIKER K10 upright, and insert it into the expansion board slot with the screen facing forward.

(3) Connect the UNIHIKER K10 to the computer with a USB cable, and connect the expansion board to the computer with its power cable separately (the UNIHIKER K10 only needs to connect to the computer when uploading programs). Then switch the power to ON.

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
Next, we'll achieve remote control of windows in multiple ways via two tasks.
Task 1: Remote Control of Window Opening and Closing
In this task, we'll learn to remotely control servo motor rotation via the SIoT platform to drive window opening and closing.
Task 2: Switching of Automatic Control Modes
In this task, we'll add an automatic control mode to remotely switch the system's working mode and automatically close the window in dim light.
Task 1: Remote Control of Window Opening and Closing
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 named "window" on the SIoT platform webpage.
Note: After creation, double-click the topic name in the label (e.g., siot/window) 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.

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, we can refer to Project 20 and complete the code following the logic of:connect to the network→MQTT initialization→connect to the server→ subscribe to the topic→set up message reception control.
In the set up message reception control program segment, judge the block by the received message content and control the servo motor to act accordingly. For example, when "on" is received, the servo motor rotates to 150 degrees (window-opening angle); when "off" is received, it rotates to 60 degrees (window -closing angle), as shown below.

Additionally, to ensure the servo motor is in the closed state at the program's initial stage, use the self-publish and self-receive method from the previous lesson: send an "off" block to the "siot/window" topic once before the loop starts. The complete program code is shown below:

Run the Code
Click the“Upload”button.. Wait for the upload to complete and then wait a moment. If the network and server connect successfully, the screen will show “Network connection successful”and”Server connection successful”in sequence. Once connected, you can see the UNIHIKER K10 screen display “Window closed”in real-time.
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.

Then, enter a message (on or off), click the“Send”, and observe the current rotation angle of the servo motor as well as the information displayed on the UNIHIKER K10 screen.


Now test the servo arm's installation position based on servo angles: 150° (open) and 60°(closed). Ensure the angles meet your window opening and closing needs. The installation example is shown in the figure below.

Task 2: Switching of Automatic Control Modes
Code
Now we'll add an automatic control mode based on Task 1. The window can determine if it's nighttime according to ambient light and automatically close.
We can add the "auto" block based on "on" and "off". When receiving the "auto" block, the program activates the automatic mode and controls by comparing the collected light intensity value with a threshold (e.g., 300 Lux). The window control table is as follows:
| receive message | light<300 | light≥300 |
auto | close | open |
on | open | open |
off | close | close |
We learned the logic of automatic control in the first major topic, and the core control program is as follows:

The automatic control mode can be implemented by creating a variable, such as“flag”. When "auto" is received, set its value to 1 to enter the automatic mode. When "on" or "off" is received, set the flag to 0 to exit it. In the loop, judge the flag status. If it's 1, execute the judgment code. The code for using the variable is as follows:

In automatic mode, to enable remote viewing of the window status, send "auto- on" or "auto-off" command to the SIoT platform during automatic control. The core program is shown below:

Run the Code
Click the“Upload”button. Wait for the upload to complete, then wait a moment. If the network and server are connected successfully, the screen will show "Network connection successful" and "Server connection successful" in sequence. Once connected, the UNIHIKER K10 screen will display the real-time ambient light intensity value and "Window closed" in real time.
Note: If unsuccessful, please check the network connection and ensure that the firewall is disabled.
Next, return to the subscribed topic tag on the SIoT platform, enter "auto", click “Send”, check the Auto-refresh checkbox, and observe the received messages below. Then, cover the light sensor with your hand and observe the servo motor's rotation and data changes.

Knowledge Base
Next, let's learn and summarize the hardware knowledge used in this lesson.
Feedback in the IoT System
According to different control subjects, the forms of control can be divided into manual control and automatic control.
Manual control is controlled by humans directly or indirectly. The output control signal is usually obtained directly through calculation after input.

Manual control with IoT participation has obviously broken through distance limitations, allowing operators to adjust the system more flexibly.

Automatic control involves continuously comparing real-time collected data with a preset threshold to determine the control action (output). Usually, except for the initial threshold setting, this process needs no human involvement.

IoT-supported automatic control can not only monitor the operating status of each module in system, but also control the actuators and adjust the thresholds.

In short, the IoT makes control system operation more flexible. It breaks geographical restrictions, enables effective monitoring of the control system and real-time adjustment according to actual conditions, thus reducing labor costs and improving production efficiency.
Challenge Task
In previous practice, the automatic control threshold was preset. This value can be modified remotely. Try it!
Tip: Create a new topic for threshold control, implement the function using variables, and the core code is shown below.









