A LoRa environment acquisition system based on ESP32 and STM32
Through the Lora environment acquisition system based on ESP32 and STM32, the low-power wide area network technology is used to realize real-time monitoring and data transmission of environmental parameters, solving the limitations of existing systems in terms of coverage, energy consumption and data transmission, and achieving efficient and reliable environmental monitoring and intelligent management.
Patent Information
- Application Number
- CN202411686109.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-24
- Publication Date
- 2025-04-04
AI Technical Summary
The existing environmental monitoring systems have many limitations in terms of coverage, energy consumption and data transmission, making it difficult to realize real-time and remote monitoring of multiple environmental parameters and data transmission.
The Lora environment acquisition system based on ESP32 and STM32 is adopted, and the low-power wide area network technology is used to realize long-distance wireless data transmission between the master control system and the slave control system through the Lora communication module, combining temperature and humidity sensors and combustible gas sensors for real-time monitoring, and data storage and analysis are carried out through the cloud platform.
Real-time and remote monitoring and data transmission of multiple environmental parameters are realized, timely monitoring and reliability of data transmission are improved, intelligent adjustment and intelligent decision-making are supported, and the intelligent process of environmental management is promoted.
Smart Images

Figure CN119758803A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet of Things and environmental monitoring technology, and is specifically a Lora environmental acquisition system based on ESP32 and STM32. The system uses low-power wide area network technology to achieve real-time monitoring and data transmission of multiple environmental parameters, and is suitable for various application scenarios such as smart agriculture, urban management and meteorological observation. Background Art
[0002] In recent years, with the rapid development of Internet of Things technology, the importance of environmental monitoring has become increasingly prominent, especially in the fields of climate change, resource management and smart cities. Traditional environmental monitoring methods often rely on manual data collection, which is inefficient and difficult to achieve real-time monitoring. In addition, the existing sensor networks have many limitations in terms of coverage, energy consumption and data transmission, which is not conducive to large-scale application. Therefore, the development of a Lora environmental acquisition system based on ESP32 and STM32 can use low-power wide area network technology to achieve remote and real-time data collection and upload, which will provide a more efficient and accurate solution for environmental monitoring and has important practical application value. Summary of the invention
[0003] In order to facilitate the intelligent adjustment of the environmental monitoring system according to real-time data, improve the efficiency and real-time performance of data transmission, and optimize environmental safety monitoring, the present application provides a Lora environmental acquisition system based on ESP32 and STM32 and its control method.
[0004] To achieve the above-mentioned purpose, the present invention provides the following technical solutions: a Lora environment acquisition system based on ESP32 and STM32 and a control method thereof, comprising a master control system, a slave control system, a Lora communication module, a sensor module, a display module and a cloud platform, wherein the master control system is composed of an ESP32 microcontroller, a communication interface and a power management module; the slave control system is composed of an STM32 microcontroller, a sensor interface and a data acquisition unit; the Lora communication module is used to realize long-distance wireless data transmission between the master control system and the slave control system; the sensor module includes a temperature and humidity sensor and a combustible gas sensor for real-time monitoring of environmental changes; the display module adopts an OLED screen for displaying the collected data; the cloud platform is used for data storage and analysis, and supports user remote access and monitoring.
[0005] As a further solution of the present invention: the frame format data is composed of multiple key fields, including Lora address, Lora channel, frame header, command type, function code, register value, CRC16 check and frame tail, each field together constitutes a data frame, the host sends the data frame to the slave through the Lora module to realize the collection and transmission of real-time environmental data. Among them, the Lora address is used to uniquely identify each slave to ensure accurate data transmission; the Lora channel specifies the communication frequency to avoid signal interference; the frame header is used to distinguish different types of data frames; the command type indicates the specific operation of the data frame, such as data request or status update; the function code further subdivides the command type to indicate the specific operation content; the register value contains the actual environmental monitoring data; the CRC16 check is used to ensure the integrity and correctness of data transmission to prevent data errors during transmission; the frame tail is used to mark the end of the data frame.
[0006] As a further solution of the present invention: the host sends data frames to the slaves in two ways: fixed-point sending and broadcast sending, so as to meet the needs of different application scenarios. In the fixed-point sending mode, the host sends data frames to a specific slave through the Lora address. Only when the Lora address of the slave matches the address sent by the host and the channel is consistent, the slave can receive the data, thereby ensuring the accurate transmission and reception of the data. In the broadcast sending mode, the host sets the Lora address to a specific address FFFF, so that as long as the Lora channel of the slave is the same as that of the host, all slaves on the channel can receive the data frame, which is suitable for scenarios where it is necessary to update environmental monitoring data to multiple slaves simultaneously. In the broadcast sending mode, the host sets the Lora address to a specific address FFFF, so that as long as the Lora channel of the slave is the same as that of the host, all slaves on the channel can receive the data frame, which is suitable for scenarios where it is necessary to update environmental monitoring data to multiple slaves simultaneously.
[0007] As a further solution of the present invention: during the data frame transmission process, the host will adjust the format of the data frame according to different transmission types to optimize system performance and ensure that the slave can correctly parse and process the received data while maintaining the integrity and validity of the data.
[0008] As a further solution of the present invention: the data frame parsing process received by the slave from the host includes multiple steps to ensure correct reception and parsing of data.
[0009] As a further solution of the present invention: First, after receiving the data, the slave determines whether the first two bytes received are the frame header. If so, it enters the receiving mode and prepares to receive subsequent data. In the receiving mode, the slave continues to monitor the received data to determine whether it is the end of the frame (also two bytes). If the end of the frame is detected, it means that the data reception is completed and the system enters the end mode.
[0010] As a further solution of the present invention: the effective data parsing process performs state machine conversion through function codes to efficiently respond to different types of requests. The specific steps include: first, after the system receives the data, it extracts the function code therein and determines its type. According to the different function codes, the system will enter the corresponding processing state. The system state includes query state, setting state and abnormal state. In the query state, if the function code is query, the system will prepare the response of the current environmental data, collect the required data and format it, and then return the response data to the requesting host or slave in time through the sending thread; in the setting state, if the function code is setting, the system will parse the corresponding setting instructions and update the relevant parameters, and return confirmation information after completing the update to ensure the effective execution of the command; in the abnormal state, if the function code does not meet expectations, the system will record the error information and can choose to send an error response to the requester for subsequent troubleshooting. Through this state machine conversion mechanism based on function codes, the system not only improves the processing efficiency of different requests, but also ensures the superior performance of the environmental acquisition system in terms of real-time and reliability.
[0011] As a further solution of the present invention: the ESP32 acts as a master control device, and performs real-time and remote data communication with each environmental acquisition slave through the Lora module. Each slave is equipped with a variety of sensors, which can obtain multiple environmental data such as temperature, humidity, and combustible gas concentration. These data are sent in a response frame format to ensure the reliability and accuracy of information transmission. After receiving the slave data, ESP32 not only parses it, but also performs integrity verification to detect data loss or tampering. At the same time, ESP32 will record status information from different slaves to prepare for subsequent data upload, thereby ensuring the efficiency and stability of the system.
[0012] As a further solution of the present invention: After the data processing is completed, ESP32 packages and transmits the valid environmental data to the preset cloud platform through Wi-Fi or other network interfaces. This process includes converting the received data into a format that conforms to the cloud platform API and adding necessary authentication information to ensure the security of data transmission. At the same time, ESP32 will periodically check the network connection status and adopt a retry mechanism when the network is abnormal to minimize data loss. In addition, ESP32 can also set a scheduled upload function to adjust the data upload frequency according to actual needs to ensure timely update of real-time monitoring information.
[0013] As a further solution of the present invention: after receiving the data from ESP32, the cloud platform will store and analyze the data to provide users with visual environmental monitoring information. This process improves data management efficiency and supports intelligent decision-making and early warning functions, allowing users to keep abreast of environmental changes. In addition, the cloud platform can also generate historical data reports to help users perform long-term trend analysis. In this way, ESP32 acts as a key bridge to ensure that the data collected from the machine is efficiently and securely transmitted to the cloud, achieving comprehensive environmental monitoring and management, and promoting the development of intelligent environmental management.
[0014] Compared with the prior art, the present invention has the following beneficial effects: (1) Real-time data monitoring: By combining ESP32 and STM32 with the Lora module, the system can realize real-time and remote collection and transmission of environmental data, thereby improving the timeliness of monitoring; (2) Support for multiple sensors: Each slave is equipped with multiple sensors, which can obtain comprehensive environmental data (such as temperature, humidity, and combustible gas) to meet the needs of different application scenarios; (3) Data reliability guarantee: The response frame format and integrity check mechanism are adopted to ensure the reliability and accuracy of data during transmission and reduce the risk of data loss or tampering; (4) Flexible data upload strategy: ESP32 supports scheduled upload function and network status monitoring, which can be adjusted according to actual needs; (5) Data upload frequency can effectively respond to network abnormalities and avoid information lag; (6) Cloud platform intelligent analysis: After data is uploaded to the cloud platform, it is stored and analyzed to provide users with visual monitoring information and historical data reports, support intelligent decision-making and early warning functions, and help users respond to environmental changes in a timely manner; (7) Promote intelligent management: The present invention further promotes the intelligent process of environmental management through efficient and secure data transmission and intelligent analysis, and improves management efficiency and decision-making level.
[0015] Figure 1 This is a schematic diagram of a LoRa environment acquisition system based on ESP32 and STM32.
[0016] Specific implementation method: Specific implementation method: Next, the technical scheme in the embodiment of the present invention will be clearly and completely described in conjunction with the drawings of the embodiment of the present invention. Obviously, the embodiment is only a part of the present invention, not all embodiments. Based on the embodiment of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should be regarded as the scope of protection of the present invention.
[0017] See also Figure 1In an embodiment of the present invention, a Lora environment acquisition system based on ESP32 and STM32 and a control method thereof are provided, including a master control system, a slave control system, a Lora communication module, a sensor module, a display module and a cloud platform. It is characterized in that the master control system is composed of an ESP32 microcontroller and a Lora communication interface; the slave control system is composed of an STM32 microcontroller, a sensor interface and a data acquisition unit; the Lora communication module is used to realize long-distance wireless data transmission between the master control system and the slave control system. In addition, the sensor module includes a temperature and humidity sensor and a combustible gas sensor to monitor environmental changes in real time; the display module uses an OLED screen to display the collected data; and the cloud platform is responsible for data storage and analysis, and supports users to perform remote access and monitoring. Through the collaborative work of the above modules, the present invention can achieve efficient and reliable environmental data acquisition and monitoring.
[0018] The frame format data consists of multiple key fields, including Lora address, Lora channel, frame header, command type, function code, register value, CRC16 check and frame tail. Each field together constitutes a data frame. The host sends the data frame to the slave through the Lora module to realize the collection and transmission of real-time environmental data. Among them, the Lora address is used to uniquely identify each slave to ensure accurate data transmission; the Lora channel specifies the communication frequency to avoid signal interference; the frame header is used to distinguish different types of data frames; the command type indicates the specific operation of the data frame, such as data request or status update; the function code further subdivides the command type to indicate the specific operation content; the register value contains the actual environmental monitoring data; the CRC16 check is used to ensure the integrity and correctness of data transmission to prevent data errors during transmission; the frame tail is used to mark the end of the data frame.
[0019] The host sends data frames to the slave in two ways: fixed-point sending and broadcast sending, to meet the needs of different application scenarios. In the fixed-point sending mode, the host sends data frames to a specific slave through the Lora address. Only when the Lora address of the slave matches the address sent by the host and the channel is consistent, the slave can receive the data, thereby ensuring the accurate transmission and reception of the data. In the broadcast sending mode, the host sets the Lora address to a specific address FFFF, so that as long as the Lora channel of the slave is the same as that of the host, all slaves on the channel can receive the data frame, which is suitable for scenarios where environmental monitoring data needs to be updated synchronously to multiple slaves at the same time. In the broadcast sending mode, the host sets the Lora address to a specific address FFFF, so that as long as the Lora channel of the slave is the same as that of the host, all slaves on the channel can receive the data frame, which is suitable for scenarios where environmental monitoring data needs to be updated synchronously to multiple slaves at the same time.
[0020] The data frame parsing process received by the slave from the host includes multiple steps to ensure the correct reception and parsing of the data. First, after receiving the data, the slave determines whether the first two bytes received are the frame header. If so, it enters the receiving mode and prepares to receive subsequent data. In the receiving mode, the slave will continue to monitor the received data to determine whether it is the end of the frame (also two bytes). If the end of the frame is detected, it means that the data reception is completed and the system enters the end mode.
[0021] The effective data parsing process uses the function code to perform state machine conversion to efficiently respond to different types of requests. The specific steps include: first, after the system receives the data, it extracts the function code and determines its type. According to the different function codes, the system will enter the corresponding processing state. The system state includes query state, setting state and abnormal state. In the query state, if the function code is query, the system will prepare the response of the current environmental data, collect the required data and format it, and then return the response data to the requesting host or slave in time through the sending thread; in the setting state, if the function code is setting, the system will parse the corresponding setting instruction and update the relevant parameters, and return the confirmation information after the update is completed to ensure the effective execution of the command; in the abnormal state, if the function code does not meet the expectations, the system will record the error information and can choose to send an error response to the requester for subsequent troubleshooting. Through this state machine conversion mechanism based on function codes, the system not only improves the processing efficiency of different requests, but also ensures the superior performance of the environmental acquisition system in terms of real-time and reliability.
[0022] The ESP32, as the master control device, communicates with each environmental acquisition slave in real time and remotely through the Lora module. Each slave is equipped with a variety of sensors that can obtain multiple environmental data such as temperature, humidity, and combustible gas concentration. These data are sent in a response frame format to ensure the reliability and accuracy of information transmission. After receiving the slave data, ESP32 not only parses it, but also performs integrity verification to detect data loss or tampering. At the same time, ESP32 will record status information from different slaves to prepare for subsequent data uploads, thereby ensuring the efficiency and stability of the system.
[0023] After the data processing is completed, ESP32 packages and transmits the valid environmental data to the preset cloud platform through Wi-Fi or other network interfaces. This process includes converting the received data into a format that conforms to the cloud platform API and adding necessary authentication information to ensure the security of data transmission. At the same time, ESP32 will periodically check the network connection status and adopt a retry mechanism when the network is abnormal to minimize data loss. In addition, ESP32 can also set a scheduled upload function to adjust the data upload frequency according to actual needs to ensure timely update of real-time monitoring information.
[0024] After receiving the data from ESP32, the cloud platform will store and analyze the data to provide users with visual environmental monitoring information. This process improves data management efficiency and supports intelligent decision-making and early warning functions, allowing users to keep abreast of environmental changes.
[0025] The cloud platform can also generate historical data reports to help users conduct long-term trend analysis, thereby providing a more comprehensive reference for environmental management.
[0026] The ESP32 acts as a key bridge to ensure that the data collected by the slave is efficiently and securely transmitted to the cloud, realizing comprehensive environmental monitoring and management and promoting the development of intelligent environmental management.
[0027] The working principle of the present invention is as follows: First, the ESP32 microcontroller in the master control system performs wireless data transmission with the STM32 microcontroller in the slave control system through the Lora communication module. The sensor module monitors environmental parameters such as temperature, humidity and combustible gas concentration in real time, and sends the collected data to the master control system through the slave control system. Then, the master control system forwards the received data to the cloud platform, which stores and analyzes the data and generates visual environmental monitoring information so that users can intuitively understand the current environmental conditions. In addition, the cloud platform will also regularly generate historical data reports to help users conduct long-term trend analysis and intelligent decision-making. Finally, users can remotely access the cloud platform through a host computer or mobile device, obtain environmental monitoring data and early warning information in real time, and thus achieve comprehensive environmental management. This series of processes ensures the efficient and secure transmission of environmental data, and provides strong support for intelligent environmental management.
[0028] It is obvious to those skilled in the art that the present invention is not limited to the specific details of the above-mentioned exemplary embodiments. The present invention can be implemented in other specific forms without departing from the basic spirit or core features of the present invention. Therefore, these embodiments should be regarded as exemplary rather than restrictive from any perspective. The scope of protection of the present invention is defined by the attached claims, rather than relying solely on the foregoing explanations, so all changes that meet the equivalent content of the claims should be included in the present invention. In addition, any graphical mark in the claims should not be regarded as a limitation on the relevant claims.
[0029] In addition, it should be clear that although this specification is described in terms of implementation methods, not every implementation method involves only one independent technical solution. Such a narrative method is only for ease of understanding. Those skilled in the art should regard the specification as a whole, and the technical solutions in each embodiment can be appropriately combined to form other understandable implementation methods.
Claims
1. A Lora environment acquisition system based on ESP32 and STM32, including an ESP32 microcontroller, a Lora communication module, an STM32 microcontroller, a temperature and humidity sensor, a combustible gas sensor, an OLED screen and a cloud platform, characterized in that: The ESP32 microcontroller is used as the master control, connected to the Lora communication module as the host; the STM32 microcontroller is used as the slave control, connected to the Lora communication module and various sensor modules, including temperature and humidity sensors, combustible gas sensors and OLED screens as slaves; the OLED screen is used to display the collected sensor data in real time; the host communicates with the slave through the Lora module, and sends the acquired data to the cloud platform to achieve remote monitoring and management of the data. The sensor module adopts a modular design, supports a variety of sensor types, and is easy to expand; the data processing unit is responsible for real-time data processing by the STM32 microcontroller to ensure the accuracy of the monitoring results; the data transmission module supports local storage and cloud transmission of data, and users can view environmental data in real time through mobile phones or computers; the Lora communication module is based on low-power wide area network technology, suitable for large-scale environmental monitoring, and can achieve a transmission distance of up to ten kilometers in urban and rural environments.
2. A Lora environment acquisition system based on ESP32 and STM32 according to claim 1, characterized in that: The data frame format includes Lora address, Lora channel, frame header, command type, function code, register value, CRC16 check and frame tail; the host sends data frames to the slave through the Lora module to realize the collection and transmission of real-time environmental data. The Lora address is used to uniquely identify each slave to ensure accurate data transmission; the Lora channel is used to specify the communication frequency to avoid signal interference; the frame header is used to distinguish different types of data frames; the command type is used to indicate the specific operation of the data frame, such as data request or status update; the function code is used to further subdivide the command type and indicate the specific operation content; the register value contains the actual environmental monitoring data; the CRC16 check is used to ensure the integrity and correctness of data transmission; the frame tail is used to mark the end of the data frame.
3. A Lora environment acquisition system based on ESP32 and STM32 according to claim 1, characterized in that: There are two types of ways for the host to send data frames to the slave: fixed-point sending and broadcast sending. In fixed-point sending, the host sends data frames to a specific slave through the Lora address. Only when the Lora address of the slave matches the Lora address sent by the host and the channel is consistent, the slave can receive the data. This method is suitable for scenarios that require point-to-point communication to ensure accurate transmission and reception of data. On the other hand, in broadcast sending, the host sets the Lora address to a specific address FFFF, so that as long as the Lora channel of the slave is the same as that of the host, all slaves on the channel can receive the data frame. This sending method is suitable for scenarios where the same data needs to be sent to multiple slaves at the same time, such as the synchronous update of environmental monitoring data. During the transmission of the data frame, the host will adjust the format of the data frame according to different transmission types to ensure that the slave can correctly parse and process the received data, while considering the integrity and validity of the data to optimize the overall performance and reliability of the system.
4. A Lora environment acquisition system based on ESP32 and STM32 according to claim 1, characterized in that: The data frame parsing process received by the slave from the host includes the following steps: first, determine whether the received data is a frame header (two bytes). If so, enter the receiving mode; then, in the receiving mode, continue to determine whether the received data is a frame tail (two bytes). If so, it indicates that data reception is over and enters the end mode; if the received data is neither a frame header nor a frame tail, it is regarded as valid data, saved and parsed according to the data format.
5. A Lora environment acquisition system based on ESP32 and STM32 according to claim 1, characterized in that: The effective data parsing process uses the function code to perform state machine conversion, which specifically includes the following steps: First, after the system receives the data, it extracts the function code and determines its type. Depending on the function code, the system will enter the corresponding state for processing. The system states include: query state: If the function code is query, the system will enter the query state and prepare the response of the current environmental data; in this state, the system will collect the required data and format it, and then send the response data back to the requesting host or slave through the sending thread; setting state: If the function code is setting, the system will enter the setting state, parse the setting instruction and update the corresponding parameters; after completing the parameter update, the system will return a confirmation message to ensure the effective execution of the instruction; abnormal state: If the function code does not meet expectations, the system will enter the abnormal state, record the error information and optionally send an error response to facilitate subsequent troubleshooting; through this state machine conversion based on function codes, the system can efficiently handle different types of requests and ensure the real-time and reliability of the environmental acquisition system.
6. A Lora environment acquisition system based on ESP32 and STM32 according to claim 1, characterized in that: The effective data parsing process includes the following steps: First, determine whether the received function code is query or setting. If the function code is query, the system will respond; during the response process, the system will prepare the response data according to the current environmental data and format it into the corresponding frame structure. After the preparation is completed, the system will send the data frame through the sending thread to ensure that the data can be transmitted to the requesting host or slave in time; after the data is sent, the system will release the relevant resources to facilitate subsequent operations and data processing. If the function code is setting, the system will update the corresponding parameters according to the setting content, and no reply is required. The whole process ensures the efficiency and real-time performance of the system to meet the needs of environmental collection.
7. A Lora environment acquisition system based on ESP32 and STM32 according to claim 1, characterized in that: The format of the response frame includes fields such as Lora address, Lora channel, frame header, ACK, slave address, function code, register, data 1, data 2 and CRC16 to ensure the integrity and validity of the data. Among them, the Lora address identifies the unique address of the host to ensure that the data can be correctly sent to the target host; the Lora channel specifies the Lora channel used for communication to ensure that the data is transmitted at the appropriate frequency; the frame header is used to identify the beginning of the frame and contains necessary control information to facilitate the receiver to identify the type of frame; ACK is the response identifier, indicating that the frame is a confirmation response frame to ensure reliable data transmission; the slave address identifies the unique address of the slave that sends the request to facilitate the host to confirm the source of the data; the function code indicates the specific operation type, such as query or setting, to facilitate the corresponding processing of the receiver; the register indicates the register address where the data is stored to ensure the corresponding relationship between the data and the register; data 1 and data 2 are specific data contents, which may contain multiple data items to meet different application requirements; CRC16 is a cyclic redundancy check code, which is used to verify the integrity of the data to ensure that the data has not been tampered with during the transmission process; finally, the frame tail identifies the end of the frame to ensure that the receiver can correctly identify the boundary of the frame. Through this response frame format, the system can achieve efficient and reliable environmental data collection and communication, ensuring accurate transmission and processing of information.
8. A Lora environment acquisition system based on ESP32 and STM32 according to claim 1, characterized in that: As the master device, ESP32 communicates data with each environmental acquisition slave through the Lora module to achieve real-time and remote data reception. Each slave is equipped with a variety of sensors that can obtain multiple environmental data including temperature, humidity, and combustible gas concentration. These data are sent in the format of a response frame to ensure the reliability and accuracy of information transmission. After receiving the data from the slave, ESP32 will not only parse the data, but also perform integrity verification to detect whether there is any data loss or tampering. In addition, ESP32 will also record status information from different slaves to prepare for subsequent data uploads, thereby ensuring the efficiency and stability of the system.
9. A Lora environment acquisition system based on ESP32 and STM32 according to claim 1, characterized in that: After the data processing is completed, ESP32 packages and transmits the valid environmental data to the preset cloud platform via Wi-Fi or other network interfaces. This process involves converting the received environmental data into a format that meets the requirements of the cloud platform API and adding necessary authentication information to ensure the security of data transmission. At the same time, ESP32 will periodically check the network connection status so that appropriate retry mechanisms can be adopted when network anomalies occur to avoid data loss as much as possible. In addition, ESP32 can also set a scheduled upload function to arrange the frequency of data upload according to actual needs to ensure timely update of real-time monitoring information.
10. The Lora environment acquisition system based on ESP32 and STM32 according to claim 1, characterized in that: After receiving the data from ESP32, the cloud platform will store and analyze the data to provide users with visual environmental monitoring information. This process not only improves the efficiency of data management, but also supports intelligent decision-making and early warning functions, allowing users to keep abreast of environmental changes. In addition, the cloud platform can also generate historical data reports to help users conduct long-term data trend analysis. In this way, ESP32 acts as a key bridge in the environmental monitoring system, ensuring that the data collected by the slave can be efficiently and securely transmitted to the cloud, achieving comprehensive environmental monitoring and management, and further promoting the development of intelligent environmental management.