Through Lessons 8 and 9, we have gained a basic understanding of UNIHIKER M10 IoT service applications. Today we will try using multiple UNIHIKER M10 boards to build an IoT system for monitoring greenhouse environmental data. At the same time, you can visualize these data on a computer and project them on the campus electronic screen for students to view and analyze.

Goal
In the IoT Campus Dashboard System, the intelligent terminal collects data such as current soil moisture and ambient temperature/humidity in the botanical garden and sends them to the SIoT platform. The server side starts SIoT service and stores data. The mobile terminals include UNIHIKER M10 and the Mind+ visualization platform on the computer, used to remotely display soil moisture and ambient temperature/humidity information and control ventilation-window switching.

Get to Know
1. Master how to use a servo.
2. Master how to build an IoT system with multiple UNIHIKER M10 boards.
3. Master how to use Mind+ visualization panel.
Materials List
Hardware:

Software:
Mind+ programming software (V1.8.0 or above) x1
Note: This lesson uses Mind+ visualization panel, so UNIHIKER M10 SIoT service must be upgraded to version 2.0. You can find the update file in the course resources folder.
Instructions: Open the program, follow the steps below to switch to Python mode, connect the device, open the update.py file, and run it. Wait until the update is complete.

Hands-on Practice
The campus IoT dashboard system consists of intelligent terminals for data acquisition, a server for data storage, and mobile terminals for remote viewing and control. To present and analyze data more clearly, we will also visualize and display them on a computer screen. Ready? Let us build it.
Task 1: Data Collection and Ventilation Window Control
In this task, we will use temperature/humidity and soil-moisture sensors to collect and display
required data, and learn to control a servo to open/close the ventilation window.
Task 2: Build Campus IoT System
Based on Task 1, we will split intelligent terminal, server side, and mobile terminal
functions, and use three UNIHIKER M10 boards to build the campus IoT system.
Task 3: Dashboard Display Design
Combined with mobile terminal functions, we will learn Mind+ data visualization panel
and design a large-screen display window on the computer for viewing, analysis, and
operation.
Task 1: Data Collection and Ventilation Window Control
1. Hardware Connection
In this system we need to monitor greenhouse ambient temperature/humidity and soil moisture, and control servo rotation to open/close ventilation windows. Therefore, connect a soil moisture sensor, temperature/humidity sensor, and servo to UNIHIKER M10 as shown
below.

2. Software Preparation
Open Mind+ and follow the steps shown in the diagram to complete the software setup.

3. Write a Program
In this task, let us first complete the basic intelligent-terminal functions in the campus IoT
system: sensor data collection and servo-based ventilation-window control.
(1) Sensor Data Collection
First determine the data to collect: ambient temperature, air humidity, light intensity, and soil
moisture. Then display them at suitable positions and add corresponding prompts. To make
display easier, prompt text has been placed in `bg.png`; you only need to drag it into "Files in
Project".

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.

Next, initialize the temperature/humidity sensor according to wiring, create corresponding data display objects, and complete initialization.

To get real-time sensor data, place blocks for updating text information of corresponding objects in `forever`. Soil moisture status is judged according to the set threshold.

To use servo for window switching, find the "Servo" block library in "Pingpong" under "Extensions" and load it.

Then use `servo initialize pin` with `UNIHIKER pin 23` to initialize servo pin. Also set initial servo angle (window-closed angle), i.e., `servo rotate 90`.
Note: The project uses a 180-degree servo with angle range 0-180 degrees. Initial angle depends on application. For servo details, see Knowledge Section.

Opening windows can be implemented by setting different servo angles. We can also add window open/close buttons to control the servo. Complete reference code is below:

4. Run the Program
Click Run. UNIHIKER M10 shows temperature, air humidity, light intensity, and other data.
Click "ON" window and servo rotates; click "OFF" window and servo returns to initial position.

Task 2: Build Campus IoT System
1. Task Analysis
The campus IoT system includes three UNIHIKER M10 boards: intelligent terminal for collecting data and controlling actuators, server side for storing/transmitting data, and mobile terminal for viewing data and remote control.

After analyzing the roles of the three boards, complete preparations such as network configuration and enabling SIoT service before programming to implement greenhouse data transmission.
2. Preparation
(1) Connect to Network
First, connect the three UNIHIKER M10 boards and the computer to the same wireless network, then check "Wireless Connection" IP in "Network Information" of each board. If the first three segments are the same, they are connected to the same wireless network.
Note: For operations like connecting multiple UNIHIKER M10 boards to the same network
and checking network info, refer to the tutorial:
https://learn.dfrobot.com/makelog-308777.html.

(2)Enable SIoT2.0 Service
Enter server-side IP in browser to open UNIHIKER settings page, go to app switch, then click "Open Page" to enter SIoT2.0 login page. Username: `siot`; password: `dfrobot`.

After successful login, enter SIoT data dashboard page. Then create required topics.
Click "Create Topic" and fill in topic name. After confirming, corresponding topic tags are shown.
Note: If SIoT1.0 page still appears, press CTRL+F5 to force refresh cache.

This project needs six topics: "airtemp", "airhumi", "light", "moisture", "moisture_status", and "window",.
Note: "siot/" is fixed text that is filled in automatically, so you do not need to enter it
manually. Double-click the topic name to copy it directly.

Now create two morose Mind+ files and remotely connect intelligent terminal and mobile terminal UNIHIKER M10 boards respectively, then we can start programming.
3. Write a Program
Preparation is complete. Next implement data transmission by programming.
(1)Server Side
The server side stores and transmits data. SIoT service is built into UNIHIKER M10, so no extra operation is required on server side; after power-on it can be used directly. You can also design simple prompt information on screen.

(2)Intelligent terminal
The intelligent terminal collects data and receives control commands from mobile terminal. First complete server connection settings and topic subscriptions.
Note: Filled topics must match topic labels on SIoT data-dashboard page.

Receive ventilation-window open/close information, and judge message content: `on` means open, `off` means close.

Publish data to corresponding server topics. In SIoT2.0 we can use `MQTT publish "" to topic` and `MQTT publish "" to topic and save to database`. Both can transmit data, but the former does not save data to server DB while the latter does. To view data on SIoT platform, we use the latter.

For UI display and sensor parts, you can copy and modify Task 1 code through "Backpack". For convenient sensor-data transmission later, create variables to store data.
Complete intelligent-terminal code is shown below:

The mobile terminal receives and displays data, and remotely controls ventilation window by
button press. First complete server connection settings and topic subscriptions. Then judge
received messages and update display content.

For UI display, continue copying/modifying Task 1 code and add `publish message and store` blocks. Complete mobile-terminal code is as follows:

4. Run the Program
Run programs on the three UNIHIKER M10 boards respectively. Observe intelligent and mobile terminal screens to acquire/view greenhouse environment and soil data. Click "Open/Close" at ventilation-window status on mobile terminal to remotely control servo rotation.
Note: If "network restricted" appears, rerun program. If prompted that `publish_save` does
not exist, disconnect and reconnect UNIHIKER M10, then enter `pip install -U siot` in terminal
to update siot.

Task 3: Dashboard Display Design
1. Write a Program
Campus IoT system is nearly complete. To present data better and let more students observe
conveniently, use Mind+ visualization panel to design a dashboard. After connecting to IoT platform, it serves as visualized mobile terminal of the system.
Note: For section descriptions of Mind+ visualization panel, see Knowledge Section.
(1)Create New Project
Click "Visualization Panel" button at top of Mind+ to open "Mind+ Data Visualization" window.

Move mouse to "New Project" and click "New Blank Project". In popup, fill project name and click OK; a new project tag appears on project-management page.

(2)Connect SIoT
After creating project, click "Edit" on the corresponding tag to enter editor. In top menu bar, click the down arrow icon., choose "Data Source Settings", and fill in IoT platform information in popup. After completion, subscription success is shown.

(3)Design Visualization Interface
In visualization editor, first set canvas size, theme, and cover in the right settings panel.

Now, according to requirements, find and add components from the left component area to complete setup and design. Next we use components in the example figure to learn configuration.

To add title text, find "Text" under "Decorative Components" in component area and drag it out like graphical blocks (drag back to component area to delete). Then adjust component position and set component/font properties in settings panel.

Note: "Component background color" here indicates component border and usually displays component title.

Add data display components to show current sensor data; they need to be bound to SIoT topics. Taking "Image Text" as example, in settings panel find "Topic" and click blank area on right, then select target topic from dropdown and data is displayed. After setting data content, you can continue other settings.

Add chart components to show historical sensor data and analyze patterns among data. They also need SIoT topic binding, similar to display components. After binding, you can select display data count. In addition, chart size can be changed by filling values in settings panel or dragging the lower-right corner.

Add switch components, which are under "Basic Components". They also need SIoT topic binding and corresponding message content. This project uses two switch types: “Switch” and "Image Switch". Both can receive and send topic messages. If layer issues occur, right-click component to adjust layer order.
Note: "on/off sending" message content must match the content filled in program block
`MQTT publish "" to topic and save to database`.

Now add other components and one white color block to complete visualization interface design. Full component setup is as follows:

2. Run the Program
Click "Save" in project-name dropdown menu, then click "Full Screen" to view the full visualization interface. Click ventilation switch to remotely control servo rotation.

To return, the "Edit" button is hidden by default in full-screen mode; move the mouse to original menu-bar area and it appears automatically.

Knowledge Base
1. Servos
A servo is an actuator that can control an object to move to a specified position (angle).
Common servos are 180-degree and 360-degree types. This project uses a 180-degree
servo.

2. Building IoT with Multiple UNIHIKER M10 Boards
In this lesson we learned to build IoT systems with multiple UNIHIKER M10 boards. A complete system usually includes intelligent terminals, server, and mobile terminals. Intelligent-terminal boards connect various sensors/actuators for data collection and actuator control; an IoT system can have multiple intelligent terminals. Mobile terminals are generally used for data viewing and remote actuator control; they can be UNIHIKER M10, computers, phones, etc. Server-side UNIHIKER M10 stores and exchanges data; just enable built-in SIoT service and power on.

General steps for building IoT with multiple UNIHIKER M10 boards: configure network so all devices are in the same subnet; enable server-side SIoT service; perform SIoT connection settings, subscribe topics, and send/receive data. If using SIoT2.0, create topics first before successful subscription.

3. Introduction to Mind+ Visualization Panel
Mind+ visualization panel is an interface design tool specially used to present data received by SIoT in a more convenient and intuitive way. You can design desired data-display and control interfaces by dragging components. In the project above, we learned the panel structure and operations. Next, let us look at functions of each area.


4. Block Overview

Challenge Yourself
After this lesson, you should have a good understanding of Mind+ visualization interface.
Try enriching your own visualization interface with more information such as temperature, air
humidity, and light intensity.









