【Distributed Temperature and Humidity Acquisition System】Work Submission
[Copy link]
This post was last edited by lansebuluo on 2022-10-22 10:14
Distributed temperature and humidity acquisition system
1. Introduction
During my growth, from no network to the network spread all over the corner, in just these twenty years, the rapid development of science and technology has brought great convenience to our lives. In an era of network interconnection, we need to feel, integrate and utilize the convenience brought to us by the network. This time, in order to get closer to the network, we have this project-distributed temperature and humidity data acquisition system. As a centralized control system, the temperature and humidity data information scattered in various locations are collected into the system through WIFI network and wide area network, and saved; the temperature and humidity alarm value of each point can be set through the centralized control system. When the sampled data exceeds the set limit, the light or sound alarm will be issued at the sampling point. When you need to view the data, you can connect to the centralized control system through the network, retrieve the current data, and review the historical data.
The centralized control system uses the STM32H745I-DISCO development board + HLK-W800-KIT WIFI module. Don’t underestimate this WIFI module, as it is also a development board and is not used for data transmission.
Key Features:
1. Wireless temperature and humidity collection point (only 5V power supply required)
2. MQTT transmission, data collection and sampling point configuration
3. Independent centralized control system STM32H745I-DISCO
4. Data preservation and historical data viewing
5. The host computer software is connected to the centralized control system
6. Web configuration WIFI network
2. System Block Diagram
Hardware:
1. Centralized control: STM32H745I-DISCO development board
2. WIFI function: HLK-W800-KIT development board
3. Temperature and humidity sensor: SHT20
The hardware functions are divided into two parts:
1. Temperature and humidity sampling point, use HLK-W800-KIT development board of Hilink to expand the reading of temperature and humidity sensor SHT20, and IO pin to control buzzer and LED.
2. Centralized control point, using STM32H745I-DISCO development board and HLK-W800-KIT development board
The software functional block diagram is divided into three parts:
1. The host computer software is used to connect the centralized control point to the network, read the data of the centralized control point and configure the information of each sampling point.
2. The centralized control point software subscribes to the temperature and humidity data of the collection point through the MQTT protocol and saves the data.
3. Collection point software, WIFI connects to the router, reads temperature and humidity data, and sends the data to the MQTT server.
3. Functional Description
STM32H745I-DISCO development board
The STM32H745I-DISCO Discovery Kit is a comprehensive demonstration and development platform for the STM32H745I MCU, which is based on the Arm Cortex-M7 and -M4 dual-core microcontrollers from STMicroelectronics. It has an onboard Ethernet RJ45 interface, an extended 4GB eMMC, and a pin-out interface STMod+ for flexible expansion.
The software design diagram is as follows
The FreeRTOS real-time operating system is ported to the STM32H745I as the scheduler for the overall software operation. FreeRTOS is a mini real-time operating system kernel. As a lightweight operating system, its functions include: task management, time management, semaphores, message queues, memory management, recording functions, software timers, coroutines, etc., which can basically meet the needs of smaller systems.
Use the LWIP network protocol stack to complete the connection with the host computer software. LwIP is a lightweight IP protocol that can run with or without operating system support. It is especially suitable for use in low-end embedded systems and supports ICMP protocol, UDP (User Datagram Protocol), TCP (Transmission Control Protocol), etc.
Use the FatFs file system to operate the extended eMMC storage in the same way as operating files. FatFs is a general file system (FAT/exFAT) module suitable for implementing the FAT file system in small embedded systems.
A UART driver was written to connect to the wireless network extension, receive MQTT server data, and send valid data to the MQTT server.
WIFI expansion module (HLK-W800-KIT)
Lianshengde's WIFI chip W800 development board has a core of Pingtou Ge XT804, an operating frequency of 240MHz, built-in DSP, floating-point unit and security engine, built-in 2MB Flash, 288KB RAM, built-in UART, GPIO, SPI, SDIO, I2C, I2S, 7816, ADC, TouchSensor and other digital interfaces. It is very powerful and the price is very low, making it extremely competitive.
Used to connect to wireless routers or WIFI hotspots, achieve intercommunication with the wide area network, publish and subscribe to the specified MQTT server message. Receive MQTT server data, convert the data to the UART port, and send it to the STM32H745I-DISCO development board; receive UART data and send the data to the MQTT server through the wide area network. The information sent is the temperature and humidity limit of the sampling point and enable/disable alarm.
Use FreeRTOS open source real-time operating system as system scheduling, connect to WIFI wireless hotspot through web configuration, and the hotspot information is saved in the built-in FLASH.
Collection point (HLK-W800-KIT)
Used to connect to wireless routers or WIFI hotspots, achieve intercommunication with the WAN, publish and subscribe to specified MQTT server messages. Receive MQTT server data, read SHT20 sensor temperature and humidity data, and send the data to the MQTT server through the WAN. Receive temperature and humidity limits and enable/disable alarm configuration information and save them.
Software design block diagram
WIFI connects to wireless hotspot, FLASH saves network configuration information and temperature and humidity alarm information, I/O controls buzzer and LED, I2C interface reads SHT20 temperature and humidity sensor, web configuration.
Host computer software
The MFC single-document program written in VC++ is used to connect to the TCP server using a socket. The IP and port number to be connected to the TCP server are set through the interface. The temperature and humidity alarm values of the sampling points are configured, the real-time temperature and humidity values of the collection points are read, historical data is obtained, and it can be browsed in a table.
4. Source Code
download.eeworld.com.cn/detail/lansebuluo/625223
download.eeworld.com.cn/detail/lansebuluo/625224
download.eeworld.com.cn/detail/lansebuluo/625225
download.eeworld.com.cn/detail/lansebuluo/625226
5. Demonstration video of the work’s functions
Distributed temperature and humidity acquisition system-Distributed temperature and humidity acquisition system-EEWORLD University
6. Project Summary
In this project, the technologies applied include FreeRTOS real-time operating system, LWIP lightweight IP protocol stack, MQTT protocol, FatFs file system, Socket, VC++MFC single-document program, etc. Although the functions of this project are basically completed, after all, it is only done in spare time, and many details are not perfect enough. There should be no problem with the general framework. This is just a practical project, which should be good for learning.
Before I saw this event, the supply of many MCU chips was unstable, and the road to domestic substitution was spreading rapidly. I happened to see the W800 chip, and I also wanted to move closer to embedded systems and learn MQTT programming, because it is quite popular recently. I used to use TI's C2000 series chips, but they were out of stock, so I had to find STM32H745I as a substitute. It took me some time to get started, especially after transplanting LWIP. I wanted to use the wired network to connect to the WAN. LWIP turned on the DNS function, but after trying many configurations, it could not connect to the WAN. In order to realize the function of the project, I finally gave up and used the UART expansion WIFI module to connect to the WAN to reduce some difficulties.
When I first started planning this project, I was not very familiar with it and had not considered the workload at all. Only when I started doing it did I realize that I had to learn every aspect, including VC++, LWIP, MQTT, and FreeRTOS. After this project, my technical skills should have improved greatly. I am very grateful to Digi-Key Electronics and EEWORLD for providing me with the opportunity, which has allowed me to grow a lot. I also want to thank Administrator Dudu for his enthusiastic supervision and encouragement, which enabled me to better manage my time and complete it in time.
Post Summary
[ 2022 Digi-Key Innovation Design Competition] Material Unboxing -STM32H745I-DISCO - 2022 Digi-Key Innovation Design Competition - Electronic Engineering World - Forum (eeworld.com.cn)
【2022 Digi-Key Innovation Design Competition】Distributed Temperature and Humidity Acquisition System - Brief Design Summary - 2022 Digi-Key Innovation Design Competition - Electronic Engineering World - Forum (eeworld.com.cn)
【2022 Digi-Key Innovation Design Competition】Distributed Temperature and Humidity Collection System - Schematic Diagram of the Collection End -2022 Digi-Key Innovation Design Competition - Electronic Engineering World - Forum (eeworld.com.cn)
[ 2022 Digi-Key Innovation Design Competition] Distributed Temperature and Humidity Acquisition System -STM32H745I-DISCO Basic Learning -2022 Digi-Key Innovation Design Competition - Electronic Engineering World - Forum (eeworld.com.cn)
【Distributed Temperature and Humidity Acquisition System】+STM32H745I-LWIP Program - 2022 Digi-Key Innovation Design Competition - Electronic Engineering World - Forum (eeworld.com.cn)
[Distributed temperature and humidity acquisition system] + STM32H745I-FreeRTOS lighting- 2022 Digi-Key Innovation Design Competition - Electronic Engineering World - Forum (eeworld.com.cn)
[Distributed temperature and humidity acquisition system] + STM32H745I-LWIP debugging process - 2022 Digi-Key Innovation Design Competition - Electronic Engineering World - Forum (eeworld.com.cn)
[Distributed Temperature and Humidity Acquisition System] +WIFI Module Expansion Board V2 - 2022 Digi-Key Innovation Design Competition - Electronic Engineering World - Forum (eeworld.com.cn)
[Distributed Temperature and Humidity Acquisition System] +W800WIFI+ Temperature and Humidity Sensor - 2022 Digi-Key Innovation Design Competition - Electronic Engineering World - Forum (eeworld.com.cn)
【Distributed Temperature and Humidity Acquisition System】+ Temperature and Humidity Acquisition Module - 2022 Digi-Key Innovation Design Competition - Electronic Engineering World - Forum (eeworld.com.cn)
【Distributed Temperature and Humidity Acquisition System】+WIFI Data Receiving Module - 2022 Digi-Key Innovation Design Competition - Electronic Engineering World - Forum (eeworld.com.cn)
[Distributed temperature and humidity acquisition system] +MQTT debugging - 2022 Digi-Key Innovation Design Competition - Electronic Engineering World - Forum (eeworld.com.cn)
【Distributed Temperature and Humidity Acquisition System】+MFC Software - 2022 Digi-Key Innovation Design Competition - Electronic Engineering World - Forum (eeworld.com.cn)
【Distributed Temperature and Humidity Acquisition System】Work Submission - 2022 Digi-Key Innovation Design Competition - Electronic Engineering World Forum (eeworld.com.cn)
VII. Others
Application Software:
1. TCP debugging and packet capture: TCPUDPDbg and IPAnalyse
2. UART and WIFI debugging: Upgrade_Tools_V1.4.8
3. STM32 development compiler: IAR 9.10.2
4. W800 development and compilation: CDK 2.12.1
5. Host computer software C++ compilation: VS2015
Attached TCP/IP communication protocol
Client - actively initiates a TCP connection to the server.
Server---Listens on the TCP port and waits for a TCP connection to be established.
Server Port: 6000
Client: PC
Server: Development Board
The client actively sends a command request, and the server returns data based on the received content.
Except for special orders.
A frame of data transmitted in the TCP protocol consists of three parts. The end of the frame data is determined by the frame length at the beginning of the frame. The three parts are frame length SIZE, command COMMAND, and data content DATA. The format is defined as follows: **********************************************************************
BYTE * 4 + BYTE * 2 + BYTE * 2 + BYTE * (SIZE –4)
Frame length SIZE Transaction element identifier Command data content DATA
**********************************************************************
COMMAND
|
name
|
DATA
|
Remark
|
1
|
Query device information
|
none
|
|
2
|
Configuring device information
|
***
|
|
3
|
Read historical data
|
***
|
|
4
|
Temperature and humidity data
|
***
|
|
The client sends a frame:
serial number
|
name
|
Number of bytes
|
type
|
describe
|
1
|
length
|
4
|
32-bit unsigned integer
|
4 bytes in length
|
2
|
Transaction Metatag
|
2
|
16-bit unsigned integer
|
Increment
|
3
|
Order
|
2
|
16-bit unsigned integer
|
Fixed value: 0x0005
|
4
|
data
|
0
|
|
|
Example: 04 00 00 00 00 00 05 00
The server returns the following data:
serial number
|
name
|
Number of bytes
|
type
|
describe
|
1
|
length
|
4
|
32-bit unsigned integer
|
4 bytes in length
|
2
|
Transaction Metatag
|
2
|
16-bit unsigned integer
|
Receiving Values
|
3
|
Order
|
2
|
16-bit unsigned integer
|
Fixed value: 0x0005
|
4
|
data
|
4
|
32-bit unsigned integer
|
Device Name - 4 bytes
|
5
|
data
|
4
|
32-bit floating point
|
Maximum temperature
|
6
|
data
|
4
|
32-bit floating point
|
Minimum temperature
|
7
|
data
|
4
|
32-bit floating point
|
Humidity maximum
|
8
|
data
|
4
|
32-bit floating point
|
Minimum humidity
|
9
|
data
|
1
|
8bit unsigned integer
|
Temperature maximum enable
|
10
|
data
|
1
|
8bit unsigned integer
|
Temperature minimum enable
|
11
|
data
|
1
|
8bit unsigned integer
|
Humidity maximum value enable
|
12
|
data
|
1
|
8bit unsigned integer
|
Humidity minimum enable
|
13
|
data
|
4
|
32-bit unsigned integer
|
Length of saved data
|
14
|
data
|
-
|
----
|
Determine the number of devices based on data length
|
Example: 20 00 00 00 02 00 05 00 32 36 33 44 66 66 70 42 33 33 a3 c0 00 00 a1 42 33 33 23 41 01 00 01 00 00 01 00 00
The client sends a frame:
serial number
|
name
|
Number of bytes
|
type
|
describe
|
1
|
length
|
4
|
32-bit unsigned integer
|
Unfixed length, length is determined by the content
|
2
|
Transaction Metatag
|
2
|
16-bit unsigned integer
|
Increment
|
3
|
Order
|
2
|
16-bit unsigned integer
|
Fixed value: 0x0007
|
4
|
data
|
4
|
32-bit unsigned integer
|
Device Name - 4 bytes
|
5
|
data
|
4
|
32-bit floating point
|
Maximum temperature
|
6
|
data
|
4
|
32-bit floating point
|
Minimum temperature
|
7
|
data
|
4
|
32-bit floating point
|
Humidity maximum
|
8
|
data
|
4
|
32-bit floating point
|
Minimum humidity
|
9
|
data
|
1
|
8bit unsigned integer
|
Temperature maximum enable
|
10
|
data
|
1
|
8bit unsigned integer
|
Temperature minimum enable
|
11
|
data
|
1
|
8bit unsigned integer
|
Humidity maximum value enable
|
12
|
data
|
1
|
8bit unsigned integer
|
Humidity minimum enable
|
13
|
data
|
4
|
32-bit unsigned integer
|
Length of saved data
|
14
|
data
|
-
|
----
|
Determine the number of devices based on data length
|
Example: 20 00 00 00 00 00 07 00 32 36 33 44 66 66 70 42 33 33 a3 c0 00 00 a1 42 33 33 23 41 01 00 01 00 00 01 00 00
Server returns:
serial number
|
name
|
Number of bytes
|
type
|
describe
|
1
|
length
|
4
|
32-bit unsigned integer
|
4 bytes in length
|
2
|
Transaction Metatag
|
2
|
16-bit unsigned integer
|
Receiving Values
|
3
|
Order
|
2
|
16-bit unsigned integer
|
Fixed value: 0x0007
|
4
|
data
|
0
|
|
|
Example: 04 00 00 00 09 00 07
Server sends frame:
serial number
|
name
|
Number of bytes
|
type
|
describe
|
1
|
length
|
4
|
32-bit unsigned integer
|
Unfixed length, length determined by content
|
2
|
Transaction Metatag
|
2
|
16-bit unsigned integer
|
0x0000
|
3
|
Order
|
2
|
16-bit unsigned integer
|
Fixed value: 0x0008
|
4
|
data
|
4
|
32-bit unsigned integer
|
Name label - 4 bytes
|
5
|
|
4
|
32-bit unsigned integer
|
Data update sequence number
|
6
|
|
2
|
16-bit signed integer
|
temperature
|
7
|
|
2
|
16-bit unsigned integer
|
humidity
|
8
|
|
2
|
---------
|
Determine the number of data based on the data length
|
Example: 10 00 00 00 09 00 08 00 32 36 33 44 01 00 00 00 ff 00 30 00
The client sends a frame:
serial number
|
name
|
Number of bytes
|
type
|
describe
|
1
|
length
|
4
|
32-bit unsigned integer
|
Unfixed length, length determined by content
|
2
|
Transaction Metatag
|
2
|
16-bit unsigned integer
|
Increment
|
3
|
Order
|
2
|
16-bit unsigned integer
|
Fixed value: 0x0009
|
4
|
data
|
4
|
32-bit unsigned integer
|
Device Name - 4 bytes
|
Example: 08 00 00 00 05 00 09 00 32 36 33 44
The server returns:
serial number
|
name
|
Number of bytes
|
type
|
describe
|
1
|
length
|
4
|
32-bit unsigned integer
|
4 bytes in length
|
2
|
Transaction Metatag
|
2
|
16-bit unsigned integer
|
Receiving Values
|
3
|
Order
|
2
|
16-bit unsigned integer
|
Fixed value: 0x0009
|
4
|
data
|
4
|
32-bit unsigned integer
|
Historical data length
|
Example: 08 00 00 00 03 00 09 00 00 01 00 00
Server sends frame:
serial number
|
name
|
Number of bytes
|
type
|
describe
|
1
|
length
|
4
|
32-bit unsigned integer
|
4 bytes in length
|
2
|
Transaction Metatag
|
2
|
16-bit unsigned integer
|
Increment
|
3
|
Order
|
2
|
16-bit unsigned integer
|
Fixed value: 0x000A
|
4
|
data
|
2
|
16-bit unsigned integer
|
Reserve 1
|
5
|
data
|
1
|
8-bit unsigned integer
|
Reserve 2
|
6
|
data
|
1
|
8-bit unsigned integer
|
Keep 3
|
7
|
data
|
2
|
16-bit signed integer
|
temperature
|
8
|
data
|
2
|
16-bit unsigned integer
|
humidity
|
9
|
data
|
-
|
---
|
Determine the number of data based on length
|
Example: 0C 00 00 00 03 00 0A 00 00 01 00 00 FE 00 20 00
appendix
|