Intelligent soil monitoring system based on STM32
By implementing localized operation and closed-loop update of personalized models on an STM32 microcontroller, the problems of low prediction accuracy and poor real-time performance in existing soil monitoring schemes are solved, achieving high-precision and real-time soil condition prediction.
Patent Information
- Application Number
- CN202510777923.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-11
- Publication Date
- 2025-10-28
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing soil monitoring solutions suffer from low prediction accuracy due to the use of general-purpose models, poor real-time performance due to complete reliance on cloud computing for prediction functions, and insufficient long-term model effectiveness due to the lack of localized model validation and closed-loop update mechanisms.
A smart soil monitoring system based on STM32 is adopted, including a data acquisition terminal, a cloud processing module, an edge computing module, and a state prediction module. The system enables localized operation and closed-loop updating of personalized models on the STM32 microcontroller, and combines Kalman filters for state prediction and model verification.
It achieves high-precision soil condition prediction, improves the real-time performance of the prediction and the long-term effectiveness of the model, and ensures the accuracy and reliability of the prediction.
Smart Images

Figure CN120848280A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of soil monitoring technology, specifically to an intelligent soil monitoring system based on STM32. Background Technology
[0002] Real-time monitoring of key soil parameters is the technological foundation of precision agriculture. With the development of Internet of Things (IoT) technology, acquiring soil parameters through sensor networks and then analyzing and predicting their dynamic changes has become an important research direction in this field.
[0003] Currently, mainstream soil monitoring solutions typically employ sensor nodes based on microcontrollers such as STM32 for data acquisition, followed by uploading the data to a cloud server for centralized processing and analysis. In this architecture, the cloud platform utilizes its powerful computing resources to run data models to predict soil conditions, while the STM32 on the terminal side only undertakes simple data acquisition and forwarding tasks, and its computing power is not fully utilized.
[0004] However, the above-mentioned technical solutions have shortcomings. First, the general-purpose models deployed in the cloud ignore the significant spatial heterogeneity of soil, resulting in insufficient prediction accuracy for specific plots. Second, the prediction function relies entirely on the cloud, which not only suffers from communication delays but also has poor reliability when the network is weak. Third, the models are usually static and lack a mechanism to verify their effectiveness on the terminal side and trigger model updates based on environmental changes, causing the models to become ineffective over time and the prediction information to become inaccurate.
[0005] Therefore, this invention proposes an intelligent soil monitoring system based on STM32 to address the shortcomings of existing technologies. Summary of the Invention
[0006] To address the shortcomings of existing technologies, this invention provides an intelligent soil monitoring system based on STM32, which solves the problems of low prediction accuracy due to the use of general-purpose models, poor real-time performance due to complete reliance on the cloud for prediction functions, and insufficient long-term model effectiveness due to the lack of localized model verification and closed-loop update mechanisms.
[0007] To achieve the above objectives, the present invention provides the following technical solution: a smart soil monitoring system based on STM32, comprising: The data acquisition terminal includes a sensor array, which is used to acquire real-time soil parameters; The cloud processing module is used to receive the real-time soil parameters uploaded by the data acquisition terminal, and to learn online based on the real-time soil parameters to optimize the preset soil dynamic state space model, thereby generating a personalized model corresponding to the data acquisition terminal. An edge computing module, located in the data acquisition terminal and including an STM32 microcontroller, is used to receive and load the personalized model from the cloud processing module. The state prediction module is used to calculate the predicted state at future times based on the loaded personalized model and the current soil parameters collected by the sensor array. The model validation module is used to compare the predicted state at the future time with the actual soil parameters collected by the sensor array to generate prediction residuals.
[0008] Preferably, the sensor array includes at least two of the following: a pH sensor, a humidity sensor, a conductivity sensor, and a heavy metal sensor.
[0009] Preferably, the soil dynamic state-space model includes state equations and observation equations: The state equation is: ; The observation equation is: ; In the formula, for The state vector at any given time; for The sensor observation vector at any given time; This is the state transition matrix; This is the observation matrix.
[0010] Preferably, the cloud processing module employs an identification algorithm or an optimization algorithm to iteratively solve for the personalized model with the goal of minimizing the error between the predicted output of the soil dynamic state space model and the real-time soil parameters.
[0011] Preferably, the edge computing module receives the personalized model from the cloud processing module via the LoRa wireless communication protocol and loads the personalized model into the memory of the STM32 microcontroller.
[0012] Preferably, the state prediction module includes: Based on the state equations defined in the personalized model and the current state vector As input, the predicted state at the future time is calculated.
[0013] Preferably, the steps of the state prediction module before calculating the predicted state at the future time include: Based on the current soil parameters collected by the sensor array, and using a Kalman filter, the state vector at the current moment is estimated. .
[0014] Preferably, the model verification module includes: Based on the observation equations in the personalized model The predicted state at the future moment is converted into the corresponding predicted soil parameters; The difference between the predicted soil parameters and the actual soil parameters collected by the sensor array at the future time is calculated to generate the prediction residual.
[0015] Preferably, the predicted residual is compared with a preset threshold, and when the predicted residual is greater than the preset threshold, a request to update the personalized model is sent to the cloud processing module.
[0016] This invention also provides a smart soil monitoring method based on STM32, comprising the following steps: Real-time soil parameters are collected through a sensor array set up in the data acquisition terminal; The real-time soil parameters are uploaded to the cloud processing module, which then learns online based on the real-time soil parameters to optimize the preset soil dynamic state space model, thereby generating a personalized model corresponding to the data acquisition terminal. The personalized model is received and loaded from the cloud processing module through the edge computing module; The edge computing module calculates the predicted state for future moments based on the loaded personalized model and the collected current soil parameters. The predicted state at the future time is compared with the actual soil parameters collected by the sensor array at the future time to generate a prediction residual.
[0017] This invention provides a smart soil monitoring system based on STM32. It has the following beneficial effects: 1. This invention achieves high-precision personalized modeling of soil conditions by deeply collaborating cloud processing with an edge computing module based on an STM32 microcontroller. The cloud generates a personalized model that accurately reflects the characteristics of the plot based on soil parameters uploaded from a specific terminal. Crucially, this personalized model is distributed and directly loaded into the STM32 microcontroller at the core of the data acquisition terminal. This solution fully leverages the computing power of the STM32 at the edge, enabling each monitoring point to run its own model, thus overcoming the problem of insufficient prediction accuracy in traditional general-purpose models and fundamentally ensuring the specificity and accuracy of condition prediction.
[0018] 2. This invention integrates a state prediction module into the data acquisition terminal and runs it on the core STM32 microcontroller, enabling local future state prediction on the device. The STM32 utilizes a pre-loaded personalized model and combines it with current soil parameters collected by sensors to estimate the current state using a Kalman filter, and then efficiently calculates the predicted future state based on the state equation. This design, which decentralizes the prediction task to the STM32 edge, allows the device to quickly generate predictions without relying on a cloud network, greatly improving the real-time performance of the prediction.
[0019] 3. This invention constructs a closed-loop feedback and adaptive update path from the edge to the cloud by setting up a model verification module that also runs on an STM32 microcontroller. Locally on the terminal, the STM32 compares the model's prediction results with subsequent actual measurements to generate prediction residuals. When the residuals calculated by the STM32 exceed a preset threshold, the terminal automatically sends an update request to the cloud. This closed-loop mechanism of autonomous verification and triggered updates based on STM32 ensures that the personalized model iterates with environmental changes, continuously maintaining its effectiveness, solving the problem of information inaccuracy caused by model aging, and enhancing the long-term reliability of the solution. Attached Figure Description
[0020] Figure 1 This is a system architecture diagram of the present invention; Figure 2 This is a flowchart of the method of the present invention. Detailed Implementation
[0021] The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0022] Please see the attached Figure 1 This invention provides an STM32-based smart soil monitoring system, comprising: The data acquisition terminal includes a sensor array, which is used to collect real-time soil parameters; In this embodiment, the data acquisition terminal, as a physical entity that directly interacts with the soil environment to be tested, undertakes the key function of accurately capturing multi-dimensional state information of the soil and performing localized intelligent computing.
[0023] The overall architecture of the data acquisition terminal is built around a low-power, high-performance 32-bit microcontroller (MCU). The STM32 microcontroller (a 32-bit microcontroller with an ARM Cortex-M core) is not only the brain of the terminal device, responsible for coordinating the orderly operation of various electronic components within the terminal, but more importantly, it performs tasks such as periodic data acquisition, preliminary digitization processing, local data caching, and bidirectional communication with the remote cloud processing module.
[0024] To achieve a comprehensive and multi-dimensional characterization of soil conditions, thereby providing rich data support for the subsequent establishment of accurate dynamic models, this data acquisition terminal integrates a composite sensor array. This array is not a simple aggregation of single sensors, but rather a sensing system optimized based on key soil science evaluation indicators. In a specific implementation of this invention, the sensor array includes at least two of the following: a pH sensor, a humidity sensor, a conductivity sensor, and a heavy metal sensor, forming a multi-parameter monitoring combination.
[0025] The selection of these sensors is based on their importance in soil science: pH sensor: It is used to measure the acidity and alkalinity of soil. This parameter directly affects the chemical availability of various nutrients in the soil as well as the population and activity of beneficial microorganisms. It is a basic indicator for evaluating soil health and fertility potential.
[0026] Humidity sensor: It is used to quantify the volumetric or mass moisture content in the soil, which is one of the most direct environmental factors affecting crop growth and development. Its accurate measurement value provides a direct basis for subsequent water-saving irrigation decisions.
[0027] Electrical conductivity (EC) sensors: By measuring the electrical conductivity of the soil solution, they can effectively reflect the total concentration of soluble salt ions in the soil. This parameter can be used to indirectly characterize the soil salinity level, preventing soil salinization, and can also reflect the soil fertility status to some extent.
[0028] Heavy metal sensor: Preferably, an ion-selective electrode technology or an electrochemical voltammetric analysis sensor can be used to monitor the concentration of specific heavy metal pollutants (e.g., lead, cadmium, chromium, etc.) in soil online. This is a key technical link in soil environmental risk assessment and pollution remediation.
[0029] During actual operation of the terminal, the firmware program set in the STM32 microcontroller executes a complete data acquisition process at a preset sampling period (for example, this period can be set to several minutes to several hours depending on the dynamic change rate of the monitored target). When the process starts, the microcontroller supplies power to each sensor module in the sensor array or sends a wake-up signal through its general purpose input / output (GPIO) pins.
[0030] Each activated sensor makes full contact between its probe portion and the soil, and converts the detected physical or chemical quantities into raw analog electrical signals, such as a voltage signal that varies linearly with pH, or a resistance or capacitance value that varies with soil moisture.
[0031] These raw, weak analog signals pass through a signal conditioning circuit before being processed by the STM32 microcontroller. This circuit is crucial for ensuring measurement accuracy. Its functions include multi-stage filtering to effectively remove noise interference introduced by power supply fluctuations or spatial electromagnetic fields. Simultaneously, the circuit amplifies or attenuates the signal as necessary, ensuring that its voltage amplitude precisely matches the optimal operating range of the analog-to-digital converter (ADC) set by the STM32 microcontroller, thereby maximizing the effective resolution and accuracy of subsequent digitization.
[0032] Subsequently, the STM32 microcontroller utilizes its on-chip integrated high-precision, multi-channel analog-to-digital converter (ADC) to sample and quantize the well-conditioned analog voltage signals from different sensors in a time-division or synchronous manner, converting them into discrete digital values that the program can recognize and process. These quantized and calibrated values constitute the real-time soil parameters.
[0033] At each sampling time The STM32 microcontroller will organize and encapsulate the multiple digital parameter values acquired from all selected sensors in the sensor array in an ordered manner according to a predefined data structure in its internal memory (RAM), thereby constructing a multi-dimensional column vector. This vector is the sensor observation vector defined in the core mathematical model of this invention—the soil dynamic state space model. For example, if a specific implementation of a terminal is equipped with pH, humidity, and conductivity sensors simultaneously, then in The observation vector generated after real-time acquisition and processing can be represented as: ; In the formula, Indicates in At any given time, the soil pH value is measured by a pH sensor and obtained after signal conditioning and analog-to-digital conversion; Indicates in The soil moisture value at any given time is obtained by measuring the moisture content using a moisture sensor and then digitizing and calibrating it. Indicates in The soil conductivity value is measured by a conductivity sensor at a given time and obtained after digitization and calibration.
[0034] Through this conversion process from physical induction to electrical signals and then to digital vectors, the data acquisition terminal successfully abstracts and maps the complex and continuous physical world of soil into discrete and structured digital information. This provides accurate, reliable, and uniformly formatted data input for subsequent state estimation at the edge and model training in the cloud, forming a solid foundation for the realization of the entire intelligent monitoring method.
[0035] To ensure long-term stable operation of the equipment in unattended environments such as the field, all electronic components of the data acquisition terminal are encapsulated in a weather-resistant and corrosion-resistant shell with a high industrial protection rating (preferably IP67 or higher). Its power supply solution is preferably a combination of a solar panel and a high-capacity rechargeable lithium battery, with a fine-grained power management strategy executed by an STM32 microcontroller. During task breaks, the terminal and its peripherals enter a deep sleep mode, thereby significantly reducing average power consumption.
[0036] The cloud processing module is used to receive real-time soil parameters uploaded by the data acquisition terminal, and to learn online based on the real-time soil parameters to optimize the preset soil dynamic state space model, thereby generating a personalized model corresponding to the data acquisition terminal. In this embodiment, the cloud processing module is typically deployed on a remote server or cloud computing platform with powerful computing capabilities and massive storage resources. The function of the cloud processing module is not simply information storage and display, but rather it undertakes the crucial task of building and dynamically maintaining a unique predictive model for each front-end data acquisition terminal, thus providing the technical guarantee for realizing the adaptive and personalized monitoring functions of this invention.
[0037] The cloud processing module first has a stable and reliable data receiving interface, which is used to continuously receive real-time soil parameters uploaded by one or more data acquisition terminals via a wireless communication network. This uploaded data is precisely the sensor observation vector sequence collected and packaged by the aforementioned sensor array. To personalize the model, the cloud processing module identifies the received data stream, processing each observation vector... Each monitoring point is strictly bound to a unique identifier (ID) of the data acquisition terminal from which it originates and stored in partitions, thereby establishing its own exclusive and continuous time series database.
[0038] The core function of the cloud processing module lies in generating personalized models through online learning based on these continuously collected historical and real-time data. The fundamental purpose of this is to overcome the challenge of traditional fixed models failing to adapt to the vast differences in soil physicochemical properties across different regions. Soil state evolution is a highly complex and geographically specific dynamic process; therefore, tailoring a model to accurately describe the unique dynamic characteristics of each monitoring point is a prerequisite for achieving high-precision predictions.
[0039] In this invention, the personalized model is based on a pre-defined linear time-invariant (LTI) soil dynamic state-space model. The mathematical structure of this model specifically includes two core equations: The state equation is: ; The observation equation is: ; In the formula, for The state vector at a given time is an abstract vector that is difficult to measure completely directly by sensors. It contains deep-level state variables such as nutrient migration rate, water osmotic potential, and microbial community activity. for The sensor observation vector at any given time is a vector composed of specific parameters such as pH and humidity values actually measured and uploaded by the data acquisition terminal. State transition matrix. Describes the internal state of the soil The inherent laws governing natural evolution over time, that is, the inherent transmission characteristics from the current moment to the next moment. Observation matrix. This establishes an invisible internal state. Compared with sensor readings that can be directly measured The mapping relationship between them. Therefore, this specific set of matrices... This fully defines the dynamic characteristics of the soil in a specific plot. The so-called "personalized model" mathematically corresponds to a set of optimal matrices specific to a particular data acquisition terminal. .
[0040] To solve for this optimal matrix, the cloud processing module preferably employs a system identification algorithm or a related optimization algorithm. The specific implementation process is as follows: This module extracts a sufficiently long sequence of historical sensor observation vectors from a database containing specific terminal IDs. Its core optimization objective is to find a set of matrices. This ensures that the model defined by this set of matrices can best fit the actual observation sequence in terms of its predicted output.
[0041] In other words, this module uses minimizing the error between the model's predicted output and the real-time soil parameters as the objective function, and solves iteratively. For example, the error can be defined as the sum of the norms of the differences between the predicted and actual values at all times, i.e., minimizing... .
[0042] In the formula, For the summation operator, let f(x) = ... The errors at all times within the historical data window are accumulated. For at any time The sensor observation vector represents the actual measurement value at that moment. The value calculated by the state-space model at time 10:00 The predicted observation vector. The prediction residual vector between the actual value and the predicted value. This is used to calculate the square of the L2 norm of the vector, which is used to quantify the magnitude of the prediction residual at a single time step. To achieve this optimization goal, the cloud processing module can employ various advanced algorithms. A preferred approach is to use subspace identification methods, such as the N4SID algorithm. These algorithms do not require strict statistical assumptions about process and measurement noise and can robustly identify the order and matrix of the state-space model directly from the observed data sequence. and .
[0043] Another approach is to use a gradient-based iterative optimization algorithm. This method first randomly initializes matrices A and C, and then repeatedly performs the following steps: based on the current... Calculate the prediction error for the entire sequence; calculate the loss function with respect to the matrix based on the error. and The gradient of each element in the matrix; the gradient along the opposite direction of the gradient on the matrix. and Make small updates. Repeat this process until the value of the loss function converges to an acceptable minimum.
[0044] Once the above identification or optimization process has converged, a set of optimal matrices is obtained. This is identified as the "personalized model" of the data collection terminal. The model is stored in the cloud and associated with the terminal's ID.
[0045] It is worth noting that this learning process is "online." This means that the cloud processing module continuously receives new observational data and can periodically (e.g., daily or weekly), or upon receiving an update request from the front-end model validation module, rerun the learning process using the latest dataset to update and fine-tune the existing personalized model. This mechanism ensures that the model can continuously track and adapt to the slow drift of soil dynamics caused by seasonal changes, climate change, or human activities, guaranteeing the effectiveness of its long-term predictions. Ultimately, the generated personalized model... The data will be sent to the corresponding data acquisition terminal for real-time status prediction at the edge.
[0046] An edge computing module, located in the data acquisition terminal and including an STM32 microcontroller, is used to receive and load personalized models from the cloud processing module. In this embodiment, the edge computing module is not a separate physical hardware component, but rather logically located inside the data acquisition terminal, with all its functions handled by the terminal's core controller—the STM32 microcontroller. The purpose of the edge computing module is to effectively decouple the complex model training in the cloud from the real-time prediction tasks on the terminal itself. By bringing the intelligent model generated in the cloud down to the source of data generation, it empowers the front-end device to perform fast and efficient state prediction locally.
[0047] The core task of the edge computing module is to retrieve a customized model for the monitoring point from the remote cloud processing module and effectively deploy it locally. This process is a crucial bridge connecting macro-level intelligence in the cloud with micro-level applications at the edge, and is a prerequisite for achieving closed-loop adaptive optimization of the entire device.
[0048] Specifically, the implementation of this module's functionality involves the following aspects: Firstly, regarding the selection of communication protocols and methods, to adapt to the objective requirements that soil monitoring scenarios are typically located in remote, field areas where cellular network coverage may be unstable and device power consumption needs to be strictly controlled, the edge computing module receives personalized models from the cloud processing module via the LoRa wireless communication protocol. In the specific implementation of this invention, this module performs this task by controlling a LoRa wireless communication module connected to an STM32 microcontroller. The STM32 microcontroller sends instructions or data packets to the LoRa module through its on-chip serial communication interface (preferably, a UART or SPI bus), driving the module to establish a communication link with the cloud server gateway. Due to its characteristics of long-distance transmission, high receiving sensitivity, and extremely low operating power consumption, the LoRa communication protocol can ensure that even in complex terrains within a range of several kilometers, the data acquisition terminal can stably receive personalized model data from the cloud with extremely low energy consumption.
[0049] Secondly, in the personalized model reception process, after the cloud processing module successfully generates or updates a personalized model based on the historical data uploaded by the terminal, it serializes the core parameters of the model, that is, converts them into a structured byte stream suitable for transmission in bandwidth-constrained wireless channels. In terms of data content, the personalized model is the aforementioned optimal matrix pair that accurately describes the dynamic characteristics of the soil at the monitoring point. After receiving the command from the cloud, the edge computing module (i.e., the STM32 microcontroller) activates the LoRa module to enter data receiving mode, and receives the string of data containing the matrix through the air interface. and The STM32 microcontroller receives a byte stream of all floating-point parameter information. To ensure the integrity and accuracy of the personalized model data during transmission, the communication process may include a data verification mechanism, such as a Cyclic Redundancy Check (CRC) code. After receiving the data, the STM32 microcontroller performs an integrity check on the data packet. If the check fails, it actively requests a retransmission from the cloud via the uplink until it receives the correct personalized model data.
[0050] The most crucial step is loading the personalized model. After successfully receiving and verifying the complete personalized model data byte stream, the edge computing module performs a loading operation. This operation converts the received linear byte stream into a two-dimensional array or structure format that can be directly called by the local prediction algorithm for matrix operations, and reliably loads it into the memory of the STM32 microcontroller. Here, "memory" preferably includes two types of memory to collaboratively achieve reliable storage and efficient computation of the personalized model: Non-volatile memory (Flash Memory): The STM32 microcontroller first processes the parsed and reconstructed matrix... sum matrix The data is written to the on-chip Flash memory. Storing the personalized model in Flash ensures that the downloaded model will not be lost even if the data acquisition terminal experiences an unexpected power outage or system reset. This provides a fundamental guarantee for the long-term autonomous and stable operation of the device, avoiding the overhead and delay of having to retrieve the personalized model from the cloud every time power is restored.
[0051] Random Access Memory (RAM): When the device needs to perform a state prediction calculation according to its operating cycle, the edge computing module will store the personalized model parameters (i.e., matrices) in Flash memory. and The model is completely copied or loaded into high-speed static random access memory (SRAM). Since RAM has a much faster read and write speed than Flash, placing the personalized model in RAM for subsequent mathematical operations such as matrix multiplication can significantly shorten the execution time of the prediction algorithm, ensure real-time computation, and meet the requirements of rapid response.
[0052] The edge computing module successfully and reliably deployed the cloud-based intelligence—a personalized model that accurately reflects the intrinsic laws of soil evolution in a specific plot—to front-end devices at the network edge. Subsequently, the data acquisition terminal possessed local prediction capabilities independent of high-frequency real-time communication with the cloud, providing direct, efficient, and persistent model support for the subsequent state prediction and model validation modules to perform their respective functions.
[0053] The state prediction module is used to calculate the predicted state for future moments based on the loaded personalized model and the current soil parameters collected by the sensor array. In this embodiment, the state prediction module is also a core functional unit logically located within the data acquisition terminal, and its specific computational tasks are undertaken by the firmware program running on the STM32 microcontroller. The function of the state prediction module is key to the leap from "perception" to "prediction" in this invention. It utilizes a locally deployed personalized model to perform real-time future state projections directly at the edge of data generation, thereby providing forward-looking decision-making basis for precision agriculture management.
[0054] The operation of the state prediction module is a crucial step closely following data acquisition and personalized model loading. Its core objective is to determine the internal state of the soil at the next or several future time points based on the actual soil parameters at the current moment.
[0055] However, the state equation of the personalized model Based on internal state vector It is done recursively, and this As an abstract variable encompassing deep soil properties such as nutrient availability and water permeability potential, soil parameters are difficult to measure directly and completely using a sensor array. The current soil parameters collected by the sensor array can only form an observation vector. Therefore, in order to obtain the input necessary for state prediction—that is, the state vector at the current moment— —In a preferred embodiment, the state prediction module's workflow begins with a crucial state estimation step.
[0056] Specifically, the steps of the state prediction module before calculating the predicted state at future times include: estimating the current state vector based on the current soil parameters collected by the sensor array and using a Kalman filter. The Kalman filter is a highly efficient recursive optimal estimation algorithm, well-suited for handling state estimation problems in linear dynamic processes. In this scenario, the Kalman filter algorithm executed by the STM32 microcontroller optimally fuses two pieces of information: one is the state estimate based on the previous time step. and the state transition matrix in the loaded personalized model Prior predictions made about the current state On the other hand, it utilizes the observation matrix. This prior prediction is then converted into a prediction of the sensor readings. ), and compare it with the sensor observation vectors that are currently being collected. The prior prediction is compared. By calculating the difference (i.e., the innovation) between the two, the filter corrects the prior prediction, thus obtaining a more accurate posterior estimate of the current state in a statistically significant sense. This is the desired state vector at the current moment. .
[0057] By using the aforementioned state estimation algorithm, we obtain the state at the current time. Reliable estimation of the internal state After that, the state prediction module can execute its core prediction function.
[0058] This module calls the customized model that has been loaded into the STM32 microcontroller's memory, especially the state equations defined therein. It uses the state vector obtained at the current moment, which was just estimated. As input, a matrix-vector multiplication operation is performed. The physical meaning of this operation is to determine the current internal state of the soil. By performing a linear transformation on its inherent state transition matrix A, which reflects the characteristics of the land parcel, the natural evolution process of the state under conditions unaffected by external abrupt changes can be mathematically simulated.
[0059] The result of this calculation is the predicted state for the future time. This is related to A vector with the same dimension, where each element represents a predicted value of a soil internal state parameter after a future sampling period. For example, if... It includes an estimate of the current available nitrogen content in the soil, so... The corresponding element is the prediction of the effective nitrogen content at the next moment.
[0060] The entire calculation process, including the iteration of the Kalman filter and the recursion of the state equation, is implemented in the firmware of the STM32 microcontroller. This is thanks to the relatively simple computational form of the state-space model and the Kalman filter algorithm, which mainly involves basic matrix operations and can be executed efficiently on microcontrollers with relatively limited resources, without relying on powerful external computing resources.
[0061] The state prediction module transforms the complex, non-obvious dynamic evolution of soil into a deterministic computational process that can be autonomously and cyclically executed on edge devices. This transforms the data acquisition terminal from a passive data recording and uploading tool into an intelligent agent with preliminary cognitive and predictive capabilities, capable of generating real-time predictions of future soil trends locally.
[0062] The model validation module is used to compare the predicted state at future time points with the actual soil parameters collected by the sensor array to generate prediction residuals. In this embodiment, the model validation module is a key support unit logically located inside the data acquisition terminal, used to implement the closed-loop adaptive function of this invention. Its calculation and judgment tasks are also carried out by an STM32 microcontroller. The core mission of the model validation module is to continuously and online evaluate the predictive performance of the currently deployed local personalized model, acting as a "quality supervisor" to ensure that the model can accurately reflect the dynamic changes of the real soil environment over a long period.
[0063] The model validation module is designed to address a core technical issue: soil properties are not static; they change slowly but continuously due to seasonal changes, climate change, or human activities such as fertilization and irrigation. This can cause a personalized model that performs well initially to gradually lose its predictive accuracy over time. This module establishes a localized feedback mechanism, enabling the data acquisition terminal to autonomously identify such instances of model "failure" or "inaccuracy."
[0064] In a complete prediction and verification cycle, the workflow of this module follows immediately after the state prediction module, and the specific implementation is as follows: First, the model validation module needs to convert the abstract prediction results output by the state prediction module into specific physical quantities that can be directly compared with actual sensor readings. The state prediction module at the previous time step... The future time was calculated. Predicted state vector However, this This is a state vector describing the deep internal characteristics of the soil. Its physical dimension differs from sensor measurements, making direct comparison difficult. Therefore, the first step in the model validation module is based on the observation equations in the personalized model. The predicted state at future moments This is converted into corresponding predicted soil parameters. Specifically, it retrieves the observation matrix from the loaded personalized model in the memory of the STM32 microcontroller. For the predicted state Performing a matrix-vector multiplication operation, i.e., calculating... This calculation result That is, the model for future moments. The theoretical predictions of the sensor observation vectors have dimensions and physical meanings (e.g., pH value, conductivity value, etc.) that are completely consistent with the actual output of the sensor array, thus making the two comparable.
[0065] Then, as time actually progresses to the next moment... At that time, the sensor array will perform a routine periodic measurement to obtain the actual soil parameters at that moment, i.e., the true sensor observation vector. .
[0066] At this point, the model validation module has two key data points for comparison: the model's predicted soil parameters. and the actual soil parameters of the sensor Subsequently, the module performs its core comparison and residual generation steps, namely, calculating the difference between the predicted soil parameters and the actual soil parameters collected by the sensor array at future moments, to generate the prediction residual. This prediction residual... We obtain it through vector subtraction: This residual vector Each element directly quantifies the magnitude of the model's prediction deviation on the corresponding physical quantity.
[0067] To facilitate quantitative judgment, in a preferred embodiment, the model validation module further calculates the magnitude of the predicted residual vector, for example, by calculating its Euclidean norm. This scalar value comprehensively reflects the overall prediction error of the personalized model at that moment.
[0068] Finally, to achieve true closed-loop adaptation, the model validation module of this invention further includes a decision-making and triggering mechanism. Specifically, it predicts the residuals (e.g., their norm values). The error is compared with a threshold preset in the non-volatile memory of the STM32 microcontroller. This preset threshold represents the maximum prediction error of the model that can be tolerated by those skilled in the art based on the accuracy requirements of the application scenario.
[0069] The comparison will guide the device to make different responses: If the predicted residual is less than or equal to the preset threshold, it indicates that the prediction accuracy of the current personalized model is still within an acceptable range, and the model remains effective. In this case, the module does not perform any special operations, and the device continues its normal monitoring-prediction-verification cycle.
[0070] Conversely, when the prediction residual exceeds a preset threshold, it indicates that the model's predictive performance has significantly deteriorated and it can no longer accurately describe the current dynamic characteristics of the soil. At this point, the model validation module will automatically trigger a crucial action: sending a request to the cloud processing module to update the personalized model. This request is reported to the cloud via wireless communication methods such as LoRa, serving as a clear signal to the cloud processing module that the personalized model currently deployed on this terminal has become invalid and needs to be re-run using the latest historical data recently uploaded by this terminal to generate a new version of the personalized model that better reflects the current soil conditions, which will then be redeployed to this terminal.
[0071] The model validation module not only quantifies the model's predictive performance, but more importantly, it empowers edge devices to proactively identify model failures and trigger retraining in the cloud. This forms a complete and automated closed loop for model maintenance and iteration, ensuring the long-term effectiveness and accuracy of the entire monitoring solution.
[0072] This invention also provides a smart soil monitoring method based on STM32, comprising the following steps: Real-time soil parameters are collected through a sensor array set up in the data acquisition terminal; The real-time soil parameters are uploaded to the cloud processing module, which then learns online based on the real-time soil parameters to optimize the preset soil dynamic state space model, thereby generating a personalized model corresponding to the data acquisition terminal. The personalized model is received and loaded from the cloud processing module through the edge computing module; The edge computing module calculates the predicted state for future moments based on the loaded personalized model and the collected current soil parameters. The predicted state at the future time is compared with the actual soil parameters collected by the sensor array at the future time to generate a prediction residual.
[0073] The method in this embodiment can be used to execute the above system embodiment, and its principle and technical effect are similar, so it will not be described again here.
[0074] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A smart soil monitoring system based on STM32, characterized in that, include: The data acquisition terminal includes a sensor array, which is used to acquire real-time soil parameters; The cloud processing module is used to receive the real-time soil parameters uploaded by the data acquisition terminal, and to learn online based on the real-time soil parameters to optimize the preset soil dynamic state space model, thereby generating a personalized model corresponding to the data acquisition terminal. An edge computing module, located in the data acquisition terminal and including an STM32 microcontroller, is used to receive and load the personalized model from the cloud processing module. The state prediction module is used to calculate the predicted state at future times based on the loaded personalized model and the current soil parameters collected by the sensor array. The model validation module is used to compare the predicted state at the future time with the actual soil parameters collected by the sensor array to generate prediction residuals.
2. The intelligent soil monitoring system based on STM32 according to claim 1, characterized in that, The sensor array includes at least two of the following: a pH sensor, a humidity sensor, a conductivity sensor, and a heavy metal sensor.
3. The STM32-based intelligent soil monitoring system according to claim 1, characterized in that, The soil dynamic state-space model includes state equations and observation equations: The state equation is: ; The observation equation is: ; Where, for The state vector at any given time; for The sensor observation vector at any given time; is the state transfer matrix; This is the observation matrix.
4. The intelligent soil monitoring system based on STM32 according to claim 1, characterized in that, The cloud processing module employs an identification algorithm or an optimization algorithm to iteratively solve for the personalized model by minimizing the error between the predicted output of the soil dynamic state space model and the real-time soil parameters.
5. The intelligent soil monitoring system based on STM32 according to claim 1, characterized in that, The edge computing module receives the personalized model from the cloud processing module via the LoRa wireless communication protocol and loads the personalized model into the memory of the STM32 microcontroller.
6. The intelligent soil monitoring system based on STM32 according to claim 1, characterized in that, The state prediction module includes: Based on the state equations defined in the personalized model and the current state vector As input, the predicted state at the future time is calculated.
7. The STM32-based intelligent soil monitoring system according to claim 6, characterized in that, The steps taken by the state prediction module before calculating the predicted state at the future time include: Based on the current soil parameters collected by the sensor array, and using a Kalman filter, the state vector at the current moment is estimated. .
8. The STM32-based intelligent soil monitoring system according to claim 1, characterized in that, The model validation module includes: Based on the observation equations in the personalized model The predicted state at the future moment is converted into the corresponding predicted soil parameters; The difference between the predicted soil parameters and the actual soil parameters collected by the sensor array at the future time is calculated to generate the prediction residual.
9. A smart soil monitoring system based on STM32 according to claim 8, characterized in that, The predicted residual is compared with a preset threshold, and when the predicted residual is greater than the preset threshold, a request to update the personalized model is sent to the cloud processing module.
10. A smart soil monitoring method based on STM32, applied to a smart soil monitoring system based on STM32 as described in any one of claims 1-9, characterized in that, Includes the following steps: Real-time soil parameters are collected through a sensor array set up in the data acquisition terminal; The real-time soil parameters are uploaded to the cloud processing module, which then learns online based on the real-time soil parameters to optimize the preset soil dynamic state space model, thereby generating a personalized model corresponding to the data acquisition terminal. The personalized model is received and loaded from the cloud processing module through the edge computing module; The edge computing module calculates the predicted state for future moments based on the loaded personalized model and the collected current soil parameters. The predicted state at the future time is compared with the actual soil parameters collected by the sensor array at the future time to generate a prediction residual.