1 Introduction

Agriculture is the basic industry in China. Our country attaches increasing importance to agricultural output value, and it is very important to continuously implement new technologies in agriculture, especially to develop water-saving irrigation under the condition of water resources shortage. The soil moisture monitoring system is one of the agricultural environment monitoring. Water-saving irrigation means precise irrigation, and the basis of precise irrigation is to monitor and locate soil moisture in irrigated areas. At present, the technologies used in agricultural environment include GPS (Global positioning system), WSN (Wireless sensor networks) and UAV (Unmanned aerial vehicle), et al. Restricted by the cost and environmental conditions, GPS is not easy to realize alone in the wireless sensor networks for soil moisture monitoring [1]. In recent years, some scholars have proposed many positioning algorithms, but the application conditions of these algorithms are harsh, that is, each positioning algorithm is aimed at positioning problems in different applications.

WSN can perceive, collect and wirelessly transmit the environmental information in the monitoring area in a self-organized and multi-hop manner [2]. It has become one of the data processing platforms with significant development and application potential, which is applied in many fields such as agricultural environment monitoring and soil moisture content [3]. The hardware composition of a sensor network system usually includes sensor nodes (End nodes), aggregation nodes (Router nodes), and management nodes (Coordinator). Positioning is an important supporting technology of WSN, and it is widely used in industry, agriculture, medical treatment and other fields. The most commonly used wireless communication protocol for building a WSN network is ZigBee, which is a close-range, low-power consumption, low-data transmission rate, low-cost bi-directional wireless communication technology, and can be embedded in various devices, while supporting the geolocation function. The application of ZigBee technology to WSN is a focus of current research, and the research and application of related positioning technology has also attracted wide attention. In practical application, we can also use the cruise UAV technology based on ground-air collaboration, which takes the UAV loading ZigBee coordinator as the gathering node, collect environmental information from the WSN nodes on the ground, and transmit the data back to the remote server in time [4]. The advantages of UAV are high efficiency, high coverage rate and intelligence, which are conducive to the realization of agricultural modernization. In recent years, many scholars have carried out relevant scientific research [5].

Whether using the WSN of the surface network, or the ground-air collaborative cruise UAV technology, the position coordinates of unknown nodes are an important feature of sensor acquisition information, so it is necessary to monitor node positioning. The features, such as rapid unfolding, robust fault tolerance, and long working life, make the application of WSN in the field of soil moisture monitoring develop very quickly, and many scholars have carried out relevant scientific research [6].

Range-based and distance-free positioning are the two widely used types of positioning methods [7]. The Range-Free way does not need to measure the distance or the angle, but it cannot meet the application requirements of high accuracy due to the more significant error. The Range-Based method requires information such as distance or angular orientation. Commonly used ranging algorithms include receiving signal strength indication (RSSI) [8,9,10], time of arrival (TOA) [11, 12], time difference of arrival (TDOA) [13, 14], angle of arrival (AOA) [15, 16], etc. The latter three require additional equipment and high cost.

In [17], the author first explained the principle of the received signal strength indicator (RSSI) and the factors affecting the positioning accuracy, including the number and location of sensors of the factors, the quality of the received signal, the arrival Angle (AOA), and the arrival time difference (TDOA). Then the authors used the beacon nodes and the arrival distance for the sensor positioning. The simulation results showed that the system obtains lower mean estimation error when using RSSI because of temporal synchronization, which indicated that RSSI-based measurements achieve higher accuracy and accuracy during localization. However, because the RSSI values are different in different regions or directions in the environment, the adverse effect is mainly reflected in the path loss factor. The fixed empirical value of path loss will reduce the range accuracy due to the change in the signal propagation area; and the solution is to use multiple measurements and cycle refinement to increase the range precision [18].

At present, some scholars have carried out research from different perspectives or applications, and have proposed many positioning algorithms based on RSSI ranging. Before positioning, the RSS distance measurement needs to be conducted first, and then the distance model is established. In order to improve the ranging accuracy of RSS distance, in [19], the authors proposed a distribution positioning method based on RSSI, which can achieve high positioning accuracy without dense deployment of nodes, and also analyzed the distribution attributes of different nodes under fine-grained distance and constructed a unit positioning model. The results showed that the localization accuracy is improved by 50% compared with the existing methods, and the error is less than 1.5 m. RSSI-based ranging accuracy depends on environmental and weather conditions, so the authors in [3] analyzed and evaluated RSSI-based ranging and adaptive techniques in outdoor wireless sensor networks to improve ranging quality. In this article the authors highlighted the impact of path loss index estimation error and temperature variation on RSSI ranging and proposed an RSSI-based adaptive ranging algorithm to improve ranging quality under changing outdoor conditions. The algorithm includes link RSSI estimation, temperature compensation, PLE estimation, and inter-node distance estimation, better localization effects were obtained by evaluating the performance of the proposed algorithm. In [20], aiming at the common non-line-of-sight (NLOS) problem, considering the actual dynamics of ultra-low power indoor wireless channel environment, the authors proposed an indoor positioning algorithm that can automatically adapt to the environmental dynamics in real time. In [21], the authors proposed a fingerprint technology based RSS to achieve indoor wireless positioning, which uses a machine learning algorithm to take the RSS measurement as a location-related signal parameter to estimate the location of the target. In this method, the estimation is divided into two phases, the offline phase and the online phase. In the offline phase, RSS measurement vectors are first collected and generated from the radio frequency (RF) signal received at the fixed reference position, and then RSS radio maps are constructed. In the online stage, the reference location is searched by the radio map to find the instantaneous location of the indoor target. However, the factors such as multipath, diffraction, and obstacle occlusion in the practical application environment often bring errors to the RSSI-based range.

By establishing the RSS filtering model, Ranjan et al. [22] applied the Gaussian average filtering technology to locate the estimation, which can better suppress the measurement noise, reduce the estimation error, and obtain a satisfactory positioning effect. By installing the measuring equipment, Katwe et al. [23] and Tomic et al. [24] adopted a hybrid ranging positioning scheme, and also obtained good positioning results based on the effective estimation algorithm. Under the RSS measurement condition, Ahmad et al. [25] achieved a good balance of positioning speed and algorithm quality by selecting the number of sensors involved in positioning calculation, but this algorithm comes at the cost of economy. Moreover, they made practical tests of the proposed positioning algorithms from the perspectives of calculation complexity, ranging, and positioning error, conducted a detailed analysis, and made the positioning performance evaluation. The re-search on the above positioning algorithms has a positive significance. Although these algorithms have a good positioning effect to a certain extent, the common problems are that they have high computational costs and high communication requirements. Therefore, these algorithms are difficult to popularize in soil moisture monitoring.

To overcome the shortcomings encountered by the above positioning algorithm, on the premise of not increasing the hardware facility and meeting the positioning accuracy of the monitoring system, we should deeply explore the application requirements of the RSSI positioning methods and monitoring systems. Under the needs of the positioning system, we should adopt a feasible scheme to reduce the positioning cost on the premise of preserving the positioning function. Our proposed algorithm assumes distance weighting and coordinate correction, reducing the system power consumption and prolonging network life. Moreover, the software cost is relatively small, and its positioning function is suitable for the application requirements of the soil moisture monitoring system.

2 RSSI ranging modeling

2.1 Wireless channel modeling

In the soil environment, there are different soil textures and other organisms with dense and uneven distribution, which will lead to multiple paths, diffraction, and obstacle shielding, complicating the RF signal transmission model. The monitoring node itself can provide RSSI measurements without adding additional hardware devices. Since the path-loss of radio wave transmission has a significant impact on the RSSI measuring precision, a log-normal topology model is used in this system. RSSI values are expressed as follows:

$$P_{r} (l) = P_{t} + K_{t} - P_{{{\text{loss}}}} (l)$$
(1)

where \(P_{t}\) and \(K_{t}\) are the transmit power and the antenna gain, respectively. \(P_{{{\text{loss}}}} (l)\) is the path loss after the distance (l).

$$P_{loss} (l) = P_{loss} (l_{0} ) + 10\rho lg\left( {\frac{l}{{l_{0} }}} \right)$$
(2)

where \(P_{loss} (l_{0} )\) is the consumed power after the ranges \(l_{0}\). \(\rho\) is the path loss index. \(l_{0}\) is the referred range, and its value usually is 1 m. Substituting formula (2) into formula (1), there is

$$P_{r} (l) = P_{t} + K_{t} - P_{loss} (l_{0} ) - 10\rho lg\left( {\frac{l}{{l_{0} }}} \right)$$

set

$$P_{t} + K_{t} - P_{loss} (l_{0} ) = P_{r} (l_{0} )$$
(3)

thus, \(P_{r} (l)\) is given by

$$P_{r} (l) = P_{r} (l_{0} ) - 10\rho lg\left( {\frac{l}{{l_{0} }}} \right)$$
(4)

where \(P_{r} (l_{0} )\) is the RSS (Received Signal Strength) value at l0. The larger the \(P_{r} (l)\) value measured by the monitoring node is, and the closer the distance is, the smaller the error caused by the \(P_{r} (l)\) deviation is.

After the referred ranges l0, \(P_{loss} (l_{0} )\) is given by

$$P_{loss} (l_{0} ) = - 10lg\left[ {\frac{{K_{t} K_{r} \lambda^{2} }}{{4\pi^{2} l_{0}^{2} L}}} \right]$$
(5)

The meaning of Kt is given as described in formula (1), Kr is the aerial receipt enhancement. L is the disadvantage factor, and λ is the wireless signal wavelength.

2.2 Internode distance estimation

It is assumed that the positioned nodes are deployed uniformly and randomly in the wireless monitoring region. Each node has the same transmission range, and the transmission range can be represented as a regularly rounded region. If we take \(l_{0} = 1\) m, by formula (3), then \(P_{r} (l)\) is given by

$$P_{r} (l) = P_{r} (1) - 10\rho lg(l)$$
(6)

If enough nodes are located within the transmission range of the monitoring node, according to the interrelation between \(P_{r} (l)\) and the distance l, we assume that the minimum received signal intensity is \(P_{rmin}\) corresponds to the maximum distance \(l_{max}\), then

$$P_{rmin} = P_{r} (1) - 10\rho$$
(7)

so,

$$\rho = \frac{{P_{r} (1) - P_{rmin} }}{{10\lg \left( {l_{max} } \right)}}$$
(8)

The symbol lmax is considered to be the transmission radius. Among the multiple RSSI values obtained in monitoring the unknown nodes, the minimum RSSI value is \(P_{rmin}\), corresponding to lmax = R; thus, we can get the l value from the unknown node to the beacon point. The search method of \(P_{rmin}\) is to put all the RSSI values received by the monitoring node to be positioned together with all the RSSI values obtained by the neighbor node, ranking from large to small and taking the smallest RSSI value as \(P_{rmin}\).

2.3 Distance ranging correction between nodes

To obtain the measurement error of RSSI values, the case of a beacon node with the known location is first considered. By measuring the \(P_{r} (l)\) value of the beacon node with the known sites in the network, we use the RF signal attenuation modeling to calculate the measured distance value and then calculate the actual distance between the beacon nodes according to the exact coordinates of the beacon node, and compare the measured length with the exact length, thus obtain the measurement error of the beacon node \(P_{r} (l)\) measurement value. When ranging the unknown monitoring node, considering the measurement error of the \(P_{r} (l)\) value, the adverse effects of various random factors in the monitoring network on the RSSI ranging results can be decreased.

For the 2-D situation, we assume that the beacon node is marked as \(B_{j} \left( {x_{j} ,{ }y_{j} } \right)\), \(j = 1,{ }2, \cdots ,M\), M is the total number of beacon nodes participating in the correction process. \(B_{0} (x_{0} ,{ }y_{0} )\) represents the beacon node to be revised. The physical distance between \(B_{0} (x_{0} ,y_{0} )\) and \(B_{j} \left( {x_{j} ,{ }y_{j} } \right)\) is recorded as \(d_{j}\). The lengths obtained by \(P_{r} (l)\) are recorded as \(l_{j}\). The RSSI distance-measured relative error is recorded as:

$$\eta_{j} = \frac{{d_{j} - l_{j} }}{{l_{j} }}$$
(9)

Then the correction coefficient for the relative error of weighted distance at the beacon node \(B_{j} \left( {x_{j} ,{ }y_{j} } \right)\) is recorded as:

$$\eta_{w} = \mathop \sum \limits_{j = 1}^{M} \frac{{d_{j} - l_{j} }}{{l_{j}^{2} \mathop \sum \nolimits_{j = 1}^{M} \frac{1}{{l_{j} }}}}$$
(10)

The coefficient \(\eta_{w}\) indicates the RSSI measuring deviation of the beacon node. Considering the weighting occupied by the various \(P_{r} (l)\), the smaller the range among the monitoring nodes, the smaller the range inaccuracy induced by the deviation of \(P_{r} (l)\), and the larger the weighting to the compensation quotient. Then the compensation range of the beacon node is given by

$$l_{uj}^{c} = l_{uj} (1 + \eta_{j} )$$
(11)

where \(l_{uj}\) is the measured range between node \(B_{0}\) and the beacon node \(B_{j}\), \(l_{uj}^{c}\) is the corresponding compensation range between two nodes.

3 Unknown node coordinate estimation

3.1 Weighted centroid localization

According to the RF signal transmission modeling discussed above, the larger the RSSI value is, the closer the distance between the monitoring nodes is, the farther the space is, and vice versa. As the node to be measured is closer to the beacon node, the measured RSSI value leads to a higher ranging accuracy, that is, the higher the confidence. When the distance is more significant than a particular threshold value, the ranging error caused by the RSSI value will increase, and the credibility of the RSSI value will decrease. Therefore, it is pretty reasonable to propose a centroid positioning method on the basis of RSSI distance weighting.

The algorithm achieves the weight of each beacon node to the centroid coordinates by the size of the weighted coefficients. The larger the RSSI value is, the smaller the distance between nodes is, the higher the confidence of the RSSI value is at this time, and the greater the weight of the centroid coordinates is. Therefore, we can choose the appropriate weighting coefficient to perform the RSSI weighting calculation to improve the positioning accuracy.

Assuming that the unknown node U1 receives the RSSI values of the three beacon nodes B1, B2, and B3 within the communication range of the node U1, these values are marked as R1, R2, and R3, and we have obtained the path loss index \(\rho\), which can be calculated from formula (8), in the monitoring range of the node U1. After considering the RSSI value and the distance weighting factor, the coordinate (x, y) calculation formula of the node U1 can be given by

$$x = \frac{{\frac{{x_{1} }}{{l_{1}^{k} }} + \frac{{x_{2} }}{{l_{2}^{k} }} + \frac{{x_{3} }}{{l_{3}^{k} }}}}{{\frac{1}{{l_{1}^{k} }} + \frac{1}{{l_{2}^{k} }} + \frac{1}{{l_{3}^{k} }}}}, y = \frac{{\frac{{y_{1} }}{{l_{1}^{k} }} + \frac{{y_{2} }}{{l_{2}^{k} }} + \frac{{y_{3} }}{{l_{3}^{k} }}}}{{\frac{1}{{l_{1}^{k} }} + \frac{1}{{l_{2}^{k} }} + \frac{1}{{l_{3}^{k} }}}}$$
(12)

l1, l2, and l3 are the measured distances from U1 to B1, B2, and B3, respectively, and k is the weighted adjusting coefficient. In practical application, we can adjust the level of the weighting calibration by regulating the value of k, so that the localization system can achieve optimal effectiveness. The algorithm is characterized by a small computational amount and no additional communication overhead, which reduces the adverse effects of random noise in RF signal modeling and thus improves the positioning accuracy of the monitoring nodes.

We then consider the angle information when selecting beacon nodes to form a weighting, which can further save computational resources and reduce positioning error. When using the three-sided measurement method to calculate the node position, it is required to keep the three points not in a straight line as far as possible; that is, to achieve a good positioning effect, the three angles are controlled as sharp as far as possible. Therefore, we consider setting the confidence degree; the greater the confidence degree, the better the positioning effect. For each of the \(C_{M}^{3}\) combinations of beacon nodes, let its confidence be \(CL_{ABC} (i)\). We have

$$CL_{ABC} (i) = 1 - \frac{{\theta_{max} - \theta_{min} }}{{\theta_{{A_{i} }} + \theta_{{B_{i} }} + \theta_{{C_{i} }} }}$$
(13)

where\(\theta_{{A_{i} }}\),\(\theta_{{B_{i} }}\), and \(\theta_{{C_{i} }}\) are the three inner angles of the triangle formed by the three beacon nodes, then

$$\left\{ {\begin{array}{*{20}c} {\theta_{max} = max\left\{ {\theta_{{A_{i} }} ,\theta_{{B_{i} }} ,\theta_{{C_{i} }} } \right\}} \\ {\theta_{min} = min\left\{ {\theta_{{A_{i} }} ,\theta_{{B_{i} }} ,\theta_{{C_{i} }} } \right\}} \\ \end{array} } \right.$$
(14)

The coordinates (\(\hat{x},{ }\hat{y}\)) of the node U1 after weighting are calculated as

$$\left\{ {\begin{array}{*{20}c} {\hat{x} = \frac{{CL_{ABC} i}}{{\sum CL_{ABC} i}}x} \\ {\hat{y} = \frac{{CL_{ABC} i}}{{\sum CL_{ABC} i}}y} \\ \end{array} } \right.$$
(15)

In the above three formulas, \(i = 1, 2,{ } \cdots ,C_{M}^{3}\), M represents the total number of beacon nodes.

3.2 Node location correction

The ranging correction coefficient \(\eta_{w}\) can improve the accuracy of RSSI ranging, but it is unable to monitor the coordinate errors caused by various random factors, such as measurement equipment and emergencies. Therefore, we should also make full use of the known location information of the beacon nodes to correct the node positioning coordinates to improve the positioning accuracy further. Assuming that the beacon node location is unknown, the integrated weighted centroid localization algorithm proposed in this paper is used to calculate the beacon node coordinates and then to find the difference with the actual coordinates of the beacon nodes; thus, the error information of the beacon node coordinate is obtained. We must consider such coordinate error information to reduce further the influence of various random factors in the monitoring network on localization accuracy.

The assumptions made here are the same as those made in Sect. 2.3. Assuming a beacon node \(B_{0} (x_{0} ,y_{0} )\), whose location is unknown, and the other beacon nodes be recorded as \(B_{j} \left( {x_{j} ,{ }y_{j} } \right)\), where \(j = 1,{ }2, \cdots N\), N is the number of beacon nodes participating in the calculation of positioning error. The position of \(B_{0} \left( {x_{0} ,{ }y_{0} } \right)\) is calculated as \(B_{r0} \left( {x_{r0} ,{ }y_{r0} } \right)\) based on the distance between \(B_{j} \left( {x_{j} ,{ }y_{j} } \right)\) to \(B_{0} \left( {x_{0} ,{ }y_{0} } \right)\), and the coordinate errors are obtained when compared with their actual coordinates. Then the coordinate error of the beacon node \(B_{0} \left( {x_{0} ,{ }y_{0} } \right)\) is expressed as

$$\left\{ {\begin{array}{*{20}c} {e_{x0} = x_{0} - x_{r0} } \\ {e_{y0} = y_{0} - y_{r0} } \\ \end{array} } \right.$$
(16)

The position error of the jth beacon node is expressed in the following standard form

$$\left\{ {\begin{array}{*{20}c} {e_{{x_{j} }} = x_{j} - x_{{r_{j} }} } \\ {e_{{y_{j} }} = y_{j} - y_{{r_{j} }} } \\ \end{array} } \right.$$
(17)

Weighted position errors within the monitoring region are the statistical mean of the position errors of the N beacon nodes and can be expressed as

$$\left\{ {\begin{array}{*{20}c} {e_{{w_{x} }} = \mathop \sum \limits_{j = 1}^{N} \frac{{e_{{x_{i} }} }}{{l_{jc} \mathop \sum \nolimits_{j = 1}^{N} l_{jr}^{ - 1} }}} \\ {e_{{w_{y} }} = \mathop \sum \limits_{j = 1}^{N} \frac{{e_{{y_{j} }} }}{{l_{jc} \mathop \sum \nolimits_{j = 1}^{N} l_{jr}^{ - 1} }}} \\ \end{array} } \right.$$
(18)

where \(l_{jc}\) is the correction distance of the jth beacon node. The weighted coordinate errors \(e_{{w_{x} }}\) and \(e_{{w_{y} }}\) within the monitored region are the weighted average of the beacon node coordinate errors, reflecting the regional localization capability of the system. Let \(\left( {x_{r} ,{ }y_{r} } \right)\) be the coordinate values calculated by the weighted centroid localization algorithm for the unknown nodes; therefore, the coordinates \(\left( {\hat{x}_{r} ,{ }\hat{y}_{r} } \right)\) of the unknown nodes in the positioning system after being corrected by the regional positioning error coefficient are

$$\left\{ {\begin{array}{*{20}c} {\hat{x}_{r} = x_{r} + e_{{w_{x} }} } \\ {\hat{y}_{r} = y_{r} + e_{{w_{y} }} } \\ \end{array} } \right.$$
(19)

4 Experimental verification

4.1 Simulation and the analysis

In simulation research and analysis, to reflect the influence of the quantity, density, and communication radius of beacon nodes on the positioning error of unknown nodes, we take the average positioning error of unknown nodes as the primary evaluation standard in the execution of the positioning algorithm. In the monitoring region, the positioning error of the jth node is expressed as \(E_{j}\).

$$E_{j} = \frac{{\sqrt {(x_{rj} - x_{j} )^{2} + (y_{rj} - y_{j} )^{2} } }}{{R_{j} }}$$
(20)

where, j = 1, 2, …, \(M_{U}\), \(M_{U}\) is the quantity of unknown locations nodes in the monitoring region, and the communication radius of the nodes is \(R_{j}\), \(p_{j} = \left[ {\begin{array}{*{20}c} {x_{rj} } & {y_{rj} } \\ \end{array} } \right]^{T}\) is the final estimated position of node j, and \(z_{j} = \left[ {\begin{array}{*{20}c} {x_{j} } & {y_{j} } \\ \end{array} } \right]^{T}\) is the actual position of node j. The mean of the positioning error for all nodes of unknown locations is marked as Ea

$$E_{a} = \frac{1}{{M_{U} }}\mathop \sum \limits_{j = 1}^{{M_{U} }} \frac{{\sqrt {(x_{rj} - x_{j} )^{2} + (y_{rj} - y_{j} )^{2} } }}{{R_{{\text{j}}} }}$$
(21)

Obviously, the smaller the value of \(E_{a}\), the higher the localization accuracy.

4.1.1 Network environment

MATLAB 2020a is selected as the simulation test platform, and the simulation environment is set to a rectangular area of 80 m \(\times\) 80 m. In this paper, the log-normal model is used as the RF communication ranging model between nodes, shown in formula (2). In the ranging model, the RSSI values and distance l are the inputs and outputs of the model, respectively. Various random disturbances in the actual monitoring environment lead to some ranging errors. For the simulation, the inter-node spacing superimposed on the Gaussian noise was used as the RSSI input in the wireless communication model. Inter-node spacing is calculated from the actual coordinates of the monitoring nodes. The standard deviation of the Gaussian noise is \(\sigma_{i}\), and its expression is shown in formula (22),

$$\sigma_{j} = \frac{{R_{max} }}{{R_{j} }}\eta_{j}$$
(22)

where, j = 1, 2, …, \(M_{U}\),\(R_{max}\) indicates the furthest propagation range of the monitored node, \(R_{j}\) indicates the propagation range of the jth monitored node, \(\eta_{j}\) indicates the distance-measured relative error of the jth monitored node, which is defined as in formula (9). We can imitate different ranging errors by regulating the value of \(\eta_{j}\).

In the following simulation experiments, the localization effects of three algorithms are listed. Where algorithm A indicates the presented algorithm, algorithm B indicates the LS (Least Square) method and algorithm C indicates the standard centroid positioning (SCP) method. The positioning accuracy of the three algorithms in different ranging errors, the number of varying beacon nodes, and the communication radii of other nodes are compared and analyzed by simulation.

4.1.2 Relationship between position accuracy and ranging error

We set the number of beacon nodes to \(M\)=15 and the total number of nodes to 300. The obtained simulation results are shown in Fig. 1.

Fig. 1
figure 1

Effects of distance measurement error on localization accuracy

According to Fig. 1, the localization precision of three algorithms decreased with the increasing variance of ranging error. The ranging error has the most significant influence on algorithm C, and when the variance of range error is significant, the localization precision decreases more. Algorithm B is less affected by range error, but in contrast, the proposed algorithm A suppresses the range error very well, thus achieving a higher localization precision.

When the variance of ranging error is \(\sigma_{j}^{2} = 0.1\), the positioning accuracy of algorithm B is about 0.21, and that of algorithm C is about 0.26; when the variance \(\sigma_{j}^{2}\) increases, the localization precision of the three algorithms begins to decrease, while the localization precision of algorithm A is invariably superior to that of the other algorithms. The reason is that when the variance of ranging error \(\sigma_{j}^{2} = 0.1\), the localization precision is mainly caused by the ranging error; after the ranging correction, the node localization precision has been dramatically improved. When the variance of the ranging error \(\sigma_{j}^{2}\) increases, \(\sigma_{j}^{2}\) significantly weakens the localization accuracy. The ranging correction of algorithm A acts as an inhibitory error and a significant improvement in localization accuracy.

4.1.3 Relationship between the localization accuracy and the number of beacon nodes

We set up the emulation environment of 80 m × 80 m, and eighty nodes presented with a random distribution. The communication distance of the node is 40 m. The obtained simulation results are shown in Fig. 2.

Fig. 2
figure 2

Effect of the number of beacon nodes on the positioning precision

It can be seen from the curve trend shown in Fig. 2 that the positioning accuracy of the three algorithms increases with the number of beacon nodes, which is because the coordinate information provided by multiple beacon nodes can be verified and supplemented by each other, reducing the inaccurate positioning caused by errors in a single anchor node. And under the same conditions, the proposed algorithm (Algorithm A) outperforms the other two algorithms.

4.1.4 Relationship between the positioning precision and the communication radius of the nodes

We set the simulation environment as in the previous case, where 80 nodes are stochastically distributed in the 80 m × 80 m region and set that the quantity of beacon nodes is 10. The simulations yielded the results shown in Fig. 3.

Fig. 3
figure 3

Relationship between node communication radius and positioning precision

Figure 3 illustrates that the positioning precision also gradually increases as the node communication radius increases. Because the more prominent the distance between the nodes communicates, the amount of information between the unknown node and the beacon node increases, and the distance error between the unknown node and the beacon node decreases. At the same time, due to the increased communication distance of the nodes, the beacon nodes around the unknown nodes also begin to grow, so the unknown nodes can use more beacon node distance to correct their space to the beacon node. Therefore, as the node communication distance increases, the positioning accuracy is also gradually increasing. Figure 3 shows that the positioning accuracy of algorithm A is higher than the other two algorithms under the same network conditions.

4.2 Experiment verification

To verify the localization effect of the proposed algorithm, in the about 15 m × 15 m area of the laboratory building, we built a small WSN experimental system using CC2530 nodes. Although the experimental area is limited compared with the actual scale of soil moisture monitoring applications, the experimental results can still be of great significance, and high-quality data can be obtained in a small range, which can be statistically extended to a larger range, provided that the corresponding assumptions are met. Here we assume that the node density per unit area is the same, so the node positioning performance is basically independent of the area size, while considering the uniform ductility of the region selected by the validation experiment, its size basically does not affect the validity of the results. There are five beacon nodes in the design, which are evenly arranged within the observed region. In addition, nine unknown nodes and one convergence node are manually set. The minimum communication distance of these nodes is about 10 m, and the nodes are placed directly on the ground and are about 0.1 m from the ground height. The data is transmitted every 10 s, and the mean of 20 tests is taken as the experimental results. The node to be positioned is considered an unknown node and is measured and placed after the specific location of the deployment setting. The resulting data are shown in Table 1.

Table 1 Test results

The Ej in the table can be calculated from formula (20). We know from Table 1 that the minimum localization deviation of the algorithm in this paper (algorithm A) is 0.09, the maximum localization deviation is 0.21, and the average value is 0.16 in the actual monitoring environment. If the conditions are the same, the average localization deviation obtained by the simulation was 0.12. The reason why the actual positioning effect is inferior to the simulation effect is that the RF signal in the actual environment is blocked by indoor walls and electrical equipment, and the signal transmission loss and multipath reduce the measurement accuracy of RSSI, thus increasing the positioning error. In comparison, these interference factors are not considered in the simulation. In conclusion, we experimentally verified the feasibility of algorithm A for localization accuracy requirements.

We use the localization algorithm proposed in this paper to analyze 15 series of test data, where the Gaussian random variable is set as \(\xi_{\sigma } \left( {0,10} \right)\), eighty nodes are randomly placed within the 80 m × 80 m region, and the communication radius of the nodes is 40 m, and the number of beacon nodes n = 20. To minimize the random deviation, 100 simulation experiments were done under the same conditions, averaging the results of 100 times, and obtaining 15 localization errors for 15 sets of corresponding unknown nodes, as shown in Fig. 4.

Fig. 4
figure 4

Positioning error of the test data

In Fig. 4, the maximum value of the positioning error is 0.35, the minimum value is 0.19, and the overall positioning effect is good. Because the 20 beacon nodes are evenly deployed in the laboratory test area, the positioning error of the area edge is slightly larger. If we deploy more beacon nodes at the edge of the test area, the localization effect will improve.

5 Conclusions

In this paper, we propose a weighted centroid localization algorithm applied to wireless monitoring systems of soil moisture. When designing the algorithm, we firstly used the signal propagation attenuation to build the model, obtained the range information by measuring the RSSI value, then selected the relative error correction coefficient of weighted distance to correct the measured range, and finally designed an integrated weighted centroid localization algorithm with less computation to reckon the location coordinates of the nodes to be tested. The advantage of this algorithm is that it can meet the accuracy of soil moisture wireless monitoring without adding hardware equipment. Simulation experiments indicate that the algorithm can efficiently suppress Gaussian noise with small transmission overhead. Simulation shows that the proposed algorithm is better than LS method and SCP method in positioning accuracy because of the distance error correction measure of RSSI level in the ranging stage, which reduces the measurement error and improves the positioning accuracy. Therefore, the proposed algorithm in this paper has a certain reference function for the practical application of soil moisture monitoring.

The research direction of positioning algorithm in agricultural environment monitoring is diversified, aiming at improving monitoring accuracy, reducing cost, enhancing system adaptability and intelligence level. Our future research direction is still the positioning algorithm with high precision and cost-reduction.