*4.2. Server Design*

The data acquired by the sensor device were finally transmitted to the server for storage and user access. The LPWAN system was composed of a sensor device loaded with the AHS as a node. Its network structure diagram is shown in Figure 5.

**Figure 5.** Overall system network structure.

Although a server built based on a private cloud can control all resources, such as computing and storage resources, and enjoy exclusive use rights, it also faces high design, installation, deployment, and upgrading costs, and cannot meet the connection requirements of an increasing number of sensor devices and the managemen<sup>t</sup> requirements of data for multiple future applications [27]. Therefore, this paper used the operator's IoT platform (OneNet) based on a PAAS as the service end, which was efficient, stable, and safe; could adapt to a variety of network environments and common transmission protocols; provided a fast access scheme, a managemen<sup>t</sup> service, and data storage capacity for terminal devices; facilitated data storage and querying; and had flexible on-demand payments and controllable costs [28]. Its architecture is shown in Figure 6.

**Figure 6.** IoT platform architecture based on a PaaS.

In this paper, the sensor node used TCP-based transparent communication to access the IoT platform of the server. We customized the protocol content, wrote the protocol analysis script in the Lua scripting language, and uploaded the analysis script to complete the protocol analysis. The application interface is shown in Figure 7.

#### **5. System Test and Analysis**

*5.1. Actual Energy Consumption Test and Analysis*

The physical object of the AHS and the encapsulated soil moisture sensor loaded with the AHS are shown in Figure 8.

**Figure 7.** Server application interface.

**Figure 8.** Hardware of the system. (**a**) Physical object of the AHS; (**b**) Soil moisture sensor after loading the AHS.

Energy consumption is a major problem for battery-powered devices. Once the power is exhausted, the device will "strike". Although the system minimized the energy consumption of device selection and algorithm design at the beginning of the design process, there needed to be a gap between the actual energy consumption and the theoretical value [29]. To analyze the actual energy consumption performance of the system, the energy consumption of the sensor device after loading the AHS was tested by connecting a highprecision multimeter in series in the system; the real current of the system in each state was measured, and its single service life was estimated according to the battery capacity. When designing the hardware circuit of the AHS system, a special current test interface was reserved so that the jumper would be used for the short circuit during operation, and the multimeter could be directly connected in series during measurement. In this experiment, the DC micro-ampere mode of a Fluke (18B+) multimeter was used. The interrupt timing cycle was set to 250 ms, the system was initialized within the initial 2 s, and the MCU entered the low power consumption mode after configuring the LoRa module. At the 4th second, the MCU exited the low power consumption mode, the ADC started sampling the battery voltage, and the MCU entered low power consumption mode again after sampling. At the 10th second (COUNT1), the MCU turned on the 12 V power supply of the sensor, the MCU exited low power consumption mode and woke up the LoRa. At the 13th second (COUNT2), the sensor started working, the MCU acquired the sensor data, and LoRa started sending and receiving data. At 15 s (COUNT3), the sensor power supply was forcibly turned off, the MCU entered low power consumption mode, and the LoRa entered sleep mode.

The energy consumption of each main state of the system is shown in Table 2. If the sampling period T was 2 h, i.e., 2 × 3600 s, the energy consumption in one cycle can be expressed as E0 = 2.99 J. If the battery capacity P1 = 3500 mAh, then the single battery energy was E = P1 × 3.6 V = 45,360 J, and the battery life was 2 × E/E0 = 30,340 h; approximately 3.46 years. When working with ultralow power consumption, if effective data

were acquired every two hours, a single-battery power supply could work for more than 3 years without considering natural attenuation, thus meeting the requirements of general applications. Additionally, flame-retardant epoxy resin could be used for integral molding and pouring; this would make the system more compact as a whole, with high mechanical strength, strong heat resistance, and easy deployment, as well as being maintenance-free, waterproof, and anti-corrosion.


**Table 2.** Energy consumption of each main state of the system.

#### *5.2. Channel Characteristics and Gateway Capacity Analysis*

The key parameter settings of the node are shown in Table 3. When setting the parameters of radio device, on the basis of meeting the radio managemen<sup>t</sup> specifications, we optimized the LoRa modulation and demodulation technology through designing the key parameters, such as modulation spread factor, modulation bandwidth, and error correction coding rate, to make the system reach an optimal state, as far as possible [30,31]. The spread spectrum LoRa modulation is performed by representing each bit of the payload information using multiple chips of information. The rate at which the spread information is sent is referred to as the symbol rate; while, the ratio between the nominal symbol rate and chip rate is the spreading factor and represents the number of symbols sent per bit of information. Spread spectrum transmission can reduce the bit error rate; that is, the SNR, as shown in Table 4. Under the condition of a negative signal-to-noise ratio, the signal can be received normally, which improves the sensitivity, link budget, and coverage of the LoRa receiver, but reduces the actual data that can be transmitted under the condition of the same amount of data [32]. Therefore, the larger the spread spectrum factor, the smaller the number rate (bit rate) of the transmitted data. In this paper, we set the spreading factor (SF) as 12 to maximize the signal coverage, under the condition of meeting the transmission rate. The LoRa modem employs cyclic error coding to perform forward error detection and correction. Such error coding incurs a transmission overhead, but it can further improve the robustness of the link. Therefore, we set the coding rate (CR) as 4/5. An increase in signal bandwidth (BW) permits the use of a higher effective data rate; thus, reducing transmission time at the expense of a reduced sensitivity improvement [33]. Apparently, there are regulatory constraints in most countries on the permissible occupied bandwidth. As it is stipulated in China that the power in 470~ −510 mHz frequency band shall not exceed 50 mW (17 dBm (ERP)) and the occupied bandwidth shall not exceed 200k [34], we set the bandwidth to 125 k; considering the cable loss and air path loss, we set the transmission power of the node to 20 dBm. In short, these parameters were closely related to the range and robustness of radio communication links. Changing the BW, SF, and CR would change the link budget and transmission time. It was necessary to have a trade-off between battery life and distance.

For large-scale LoRa connection applications, gateway capacity is an important characteristic [35,36], especially in a typical suburban farming environment; and whether the gateway is sufficient for the determined number of nodes is an important concern. In the same application scenario, for a certain gateway, the maximum number of packets that can be received per day is also determined. However, different packet forms and sending rates will change the total number of packets. The LoRa standard data frame format is shown in Figure 9.


**Table 3.** The key parameter settings of the node.

**Table 4.** Range of spreading factors.


Note that the spreading factor must be known in advance on both transmit and receive sides of the link, as different spreading factors are orthogonal to each other.


**Figure 9.** LoRa packet structure.

The data frame includes a preamble byte, a header byte, a payload, and an optional CRC byte for synchronization. Although the number of preamble bytes can be programmable, the number of remaining bytes depends on the coding rate and spreading factor used in other parameters. The number of preamble symbols is generally set to *Mpreamble* = 4.25 + Nprog, where Nprog is the programmed preamble length. The total number of bytes of the physical layer data frame is calculated using Equation (2) [37].

$$\mathcal{M} = \left[ M\_{preamblc} + 8 + M\_{SF} \* (CR + 4) \right] \tag{2}$$

$$M\_{SF} = \max\left( \left[ \frac{8PL - 4SF + 28 + 16CRC - 20IH}{4(SF - 3DE)} \right], 0 \right) \tag{3}$$

Equation (3) gives *MSF*, which mainly gives the number of payload symbols, where *CR* ∈ {1, 2, 3, 4} represents the coding rate of 4/(*CR* + 4); PL is the MAC layer, including MAC header and application data payload (in bytes); *SF* is the spread spectrum factor. If the optional function *CRC* is enabled, *CRC* = 1; *IH* = 1 indicates that the implicit header function is enabled (i.e., the physical layer header is not transmitted); and *DE* = 1 indicates that the data optimization function is activated. For a given combination of spreading factor (*SF*), coding rate (*CR*), and signal bandwidth (*BW*) the total on-the-air (*ToA*) transmission time of a LoRa packet can be calculated using Equation (4), where *Ts* is the transmission time of one symbol, which is calculated using Equation (5).

$$ToA = \text{Ts} \ast M\tag{4}$$

$$\text{Ts} = \text{2}^{SF} / \text{BW} \tag{5}$$

For a LoRa gateway with eight channels, Equation (6) calculates the channel capacity (i.e., number of nodes) without LBT (listen before talk) [38].

$$\mathbf{S} = 8\mathbf{T}/(2\mathbf{e} \ast \,\, \text{To}\mathbf{A})\tag{6}$$

where 8 represents eight channels, T represents the transmission interval, which is related to the packet length and rate. While, 1/2 e is the maximum throughput of the basic Aloha algorithm and e is a constant, equal to 2.718. Under the premise of 10-byte preload, the

relationship between different *SF* and *BW* and their theoretical gateway capacity are shown in Figures 10 and 11.

**Figure 10.** When BW = 125 kHz, T = 3600 s, the gateway capacity at different *SF*.

**Figure 11.** When *SF* = 12, T = 3600 s, the gateway capacity at different bandwidths.

If different algorithms are adopted, this will also lead to a change of maximum throughput, resulting in a change of theoretical capacity. For example, if the precondition is modified so that each node has a LBT function and the slot Aloha algorithm is used instead of the previous basic Aloha algorithm, the maximum throughput is different, due to different algorithms. At this time, the maximum throughput is 1/e, so the theoretical capacity of the channel will be doubled. It can be seen that under the condition of setting parameters as shown in Table 3, a single LoRa gateway can theoretically connect 5345 nodes. In practical applications, the gateway can receive SF7–SF12 signal data at the same time.

Due to the limited demodulation and coverage capacity of a single gateway, in reality, it is actually difficult to meet the requirements of the theoretical capacity, but it can be deployed with multiple gateways to maximize the network capacity.

#### *5.3. Communication Test and Discussion*

In principle, a wireless communication gateway should be deployed at the highest possible position, such as a communication operator's iron tower or the roof of a high-rise building, to improve the communication distance and signal quality. In practical applications, the site environment, operating conditions, economic cost, and other factors need to be fully considered [39]. This test took the farms around the Red Azalea Agricultural Ecological Park (RAAEP) in the Baguazhou area as the test site, to evaluate the communication distance and signal coverage between the gateway and the nodes in a typical suburban natural farmland environment. No tower or high-rise building was available for the operators in the area, no advantageous terrain was available, and certain obstacles were contained in the communication space. The test took the RAAEP as the starting point, and considering the implementation difficulty and cost control, the LoRa gateway device was deployed on a billboard approximately 2.5 m above the ground (Figure 12c), while the mobile power supply was used to power the LoRa gateway (Figure 12b). A communication test route diagram is shown in Figure 13. The AHS was specially programmed for the data transmission test as a terminal node (Figure 12a). We drove along the lane with the terminal node for the communication test, and several test points were placed in the southwest direction. Tall and dense trees were located on both sides of the road, but there were relatively open road areas at 450–500 m and 750–800 m in front of the starting point. The system started to enter a village at 1000 m, passed through the village at 1100 m, and entered woods on the two sides of the road at the same time. A highway bridge was located at 2200 m, and the test route crossed under the highway bridge.

**Figure 12.** Communication test: the LoRa gateway was placed on a billboard 2.5 m above the ground. (**a**) LoRa terminal node; (**b**) LoRa gateway with the DTU; (**c**) Gateway placement location.

At each test location, the terminal node sent a group of sequentially numbered data every 3 s, for a total of no less than 20 groups. The gateway received the data, printed the received signal strength indication (RSSI) and signal-to-noise ratio (SNR) information of the data, and uploaded this information to the cloud through a data transfer unit (DTU). We calculated the average RSSI and SNR of the test points at the same distance, which are shown in Figure 14.

**Figure 13.** Communication test route for each designated test location, and the node used to send data in the simulations. The red star symbol indicates the starting point of the test.

Figure 15 shows the data packet loss rate. As seen from the figure, with the increase in the communication distance, the RSSI and SNR gradually decreased, and the packet loss rate gradually increased. At 500 m and 800 m from the test point, the area was relatively open, the influence of tree shielding was small, and the received signal improved. Although signals were still received at 1100 m, the packet loss rate was too high, and the communication accuracy was lost. Therefore, in practical applications, the communication quality evaluation should focus on more than the RSSI, and the packet loss rate was the prerequisite for the evaluation of communication quality.

**Figure 15.** Packet loss rate.

In a communication system, if the signal power value in the communication link is equal to, or greater than, the sensitivity of the receiver, the receiver can normally obtain the information contained in the transmitted signal; the communication is successful. On the contrary, if the signal power is lower than the sensitivity, the quality of information obtained will be far lower than the specified requirements [40].

Figure 16 shows the obtained signal strength distribution. We selected a set of test data under relatively poor test conditions (such as antennas without enhanced gain), where the analyzed system performance would have more redundancy space. There were 135 received signal strength data points in total. During the test, the distance between the node and the gateway ranged from 300 m to 1300 m. Among the valid data points obtained, there were 18 at 300 m, 22 at 500 m, 19 at 650 m, 26 at 800 m, 19 at 1000 m, 5 at 1100 m, and 26 at 1300 m. The signal strength of these data ranged from −142.5 dBm to −119.8 dBm, including 1 data point greater than −120 dBm, 57 data points less than −120 dBm and greater than −130 dBm, 66 data points less than −130 dBm and greater than −140 dBm, and 11 data points less than or equal to −140 dBm. From the signal strength analysis, 92% of the test signals were greater than −140 dBm, while the received signal sensitivity of LoRa gateway was −142 dBm. Therefore, the RSSI of this test was within the acceptable range. However, when combined with the packet loss rate data analysis, the coverage radius of a single gateway should not exceed 1100 m.

**Figure 16.** Signal strength distribution.

Compared with the theoretical parameters, the actual test data parameters, especially the communication distance, had large gaps. Many factors restrict wireless communication distance.

In an ideal environment, wireless communication satisfies the Friis transmission equation [41,42]. After considering the loss of the free space path, the Friis transmission equation can be transformed into the following Equation (7):

$$\text{Pt}-\text{Pr} + \text{Gt} + \text{Gr} = 20 \text{lg} \frac{4\pi fd}{c} + Lc + L0 \tag{7}$$

where Pt is the transmission power of the transmitter, Pr is the sensitivity of the receiver, Gt is the transmitter antenna gain, Gr is the receiver antenna gain, *f* is the carrier frequency, *d* is the distance between the receiver and transmitter antennas, *c* is the speed of light, *Lc* is the feeder loss of the transmitter antenna at the base station, and *L*0 is the air propagation loss. Here, *π* and *c* are constants; therefore, Equation (7) can be easily converted into the following Equation (8):

$$\text{Pt}-\text{Pr} + \text{Gt} + \text{Gr} = 20\text{lg}(f) + 20\text{lg}(d) + L\text{c} + L0 - 147.56 \text{(dB)}\tag{8}$$

Equation (8) can be converted to Equation (9) to calculate the distance:

$$\mathbf{d} = 10 \frac{\text{Pt} - \text{Pr} + \text{Gt} + \text{Gr} - 20 \lg(f) - lz - l.0 + 14 \text{".56(dB)}}{20} \tag{9}$$

Therefore, according to the theoretical calculation formula, the factors affecting the wireless communication distance include the system's own factors, such as receiving sensitivity, transmission power, transmitter, and receiver antenna gain, as well as environmental conditions such as obstacles, transmitter and receiver antenna height, electromagnetic interference and weather influence. In the system parameter setting designed in this paper, considering the data transmission rate and battery life, we set the maximum SF and transmission power to maximize the sensitivity of the node. Therefore, the main factors affecting the communication distance of the system came from the antenna gain and the air propagation loss caused by the obstacles between the sensor node and the gateway. In our system, we chose an antenna with high gain as much as possible; however, due to the consideration of the overall waterproof and anti-corrosion properties of the sensor node, the transmitting antenna was encapsulated inside the node, which led to increased propagation loss. As mentioned in the previous communication test section, the LoRa gateway was deployed on a billboard about 2.5 m above the ground. The sensor node test location passed through the village, and there were tall and dense trees on both sides of the test route. These test conditions well simulated the low-cost deployment mode in a typical suburban farming environment, but objectively caused the propagation loss of wireless communication and greatly reduced the wireless communication distance. Due to the implementation environmental conditions, deployment difficulty, and cost, we did not deploy the LoRa gateway at a higher position for testing, but from the calculation formula, we could show that by deploying the gateway at a commanding height over the environment, we could reduce the obstacles between communications, reduce the air propagation loss, and improve the communication distance exponentially.

Overall, when a sensor device is designed as the node of an LPWAN, the transmission power, reception sensitivity, and carrier frequency are subject to the node power consumption and chip performance factors. In practical applications, considering the implementation environmental conditions, economic cost, and deployment and maintenance difficulty, we cannot blindly pursue the ideal communication transmission distance; thus, we need to find a balance and deploy the network reasonably [43].
