# Design of Wireless Sensor Network for Agricultural Greenhouse Based on Improved Zigbee Protocol
## 2 Design and Implementation of the Wireless Sensor Network
### Routing Protocol Design  
The transmission delay and the successful reception rate of data packets in the ZigBee network will be affected by the routing protocol to a large extent. In order to make the network more stable, this study proposes an improved ZigBee-based routing protocol EMP-ZBR after combining the designed WMN network topology, thereby reducing energy loss and reli  
Figure 1: Zigbee wireless network topology. Figure 2: Network address distribution of each device in the WMN network. First, the cross-layer mechanism is introduced on the basis of the original Zigbee routing protocol, in which the routing layer can obtain the queue buffer packets in the MAC (Media Access Control Address) layer and use the length of the cache queue in the node to determine the load of the node, defined as the queue cache group occupancy, according to the protocol built on an agricultural information monitoring system; the energy consumption of the node is determined against the total energy in the node and the energy consumed [16], and is defined as the energy consumption occupancy ratio. The algorithm description: \(Q_{cr}\) and \(E_{cr}\) is defined to represent the cache packet occupation ratio and energy consumption ratio of the node, respectively. \(Q_{cr}\) and \(E_{cr}\) values are defined as Equations (2) and (3):  
\[Q_{cr}=Q_{le}/Q_{max} \tag{2}\]  
\[Q_{cr}=\left(E_{int}-E_{left}\right)/E_{int} \tag{3}\]  
Among them, \(Q_{le}\) represents the length of the cache queue at the moment of the node, and \(Q_{max}\) refers to the maximum cache queue length that the node can accommodate. \(E_{int}\) represents the total energy of the node at the beginning, \(E_{left}\) represents the remaining energy of the node after working for a period of time and \(E_{int}\)\(E_{left}\) represents the total amount of energy consumed by the node during work. The routing update criterion for the Zigbee routing protocol was then improved accordingly. In the original Zigbee protocol, the shortest hop count is applied as the routing update criterion; while MP-ZBR (Multi-Link Zone Border Router) is the routing protocol, the new routing update criterion cost is applied. The value of cost will be calculated following certain rules through the energy consumption ratio of intermediate nodes, cache packet occupation ratio and link quality. When the RREQ (Route Request Packet) packet arrives at the intermediate node [20], the \(E_{cr}\) (the energy consumption ratio in the node), \(Q_{cr}\) (cache packet occupancy ratio) and the link quality LQI value are first calculated. \(Q_{cr}\) and \(E_{cr}\) are calculated in Equations (4) and (5). The LQI value can be obtained by calculating the received signal strength RSSI value, which is an integer from 0 to 255. The larger the LQI value, the better the link quality. The \(Q_{cr}\), \(E_{cr}\) and LQI values are added to \(Q_{csum}\) (the sum of the node load ratio), \(Q_{csum}\) (the sum of the energy consumption ratio) and L_sum (link quality sum). To unify the rules, the L_sum value is defined as the reciprocal of the sum of the actual link quality, and the cost value is calculated with the following rules:  
\[Q_{csum}=\sum Q_{cr} \tag{4}\]  
\[E_{csum}=\sum E_{cr} \tag{5}\]  
\[\text{L\_sum}=1/\sum LQI \tag{6}\]  
\[\text{cos}\ t=\alpha\frac{Q_{csum}}{hop\_count}+\beta\frac{E_{csum}}{hop\_count }+\lambda\frac{\text{L\_sum}}{hop\_count} \tag{7}\]  
where \(\alpha\), \(\beta\) and \(\lambda\) are the weight value and satisfy \(\alpha+\beta+\lambda=\)1. The greater the weight value, the greater the influence of the node energy condition or the node's buffer queue length and link quality condition on the routing update criterion. Since this research studies the impact of congestion on the network, after multiple experimental verifications, \(\alpha\) the value of \(\alpha\) is 0.4 and the values of \(\beta\) and \(\lambda\) are 0.3.