An adaptive routing optimization and energy-balancing algorithm in ZigBee hierarchical networks

ZigBee hierarchical tree routing protocol (HRP; ZigBee Alliance, San Ramon, CA, USA) provides a simple but reliable topology. However, the transmission routes are not always efficient, and the links are fixed after they were determined during the network initialization. In this paper, we propose an adaptive routing optimization and energy-balancing algorithm in ZigBee hierarchical networks. In our routing algorithm, the parent node could adaptively maintain its child's links for lower network load, and all the information needed can be obtained from a neighbour table to avoid introducing extra communication overhead. Such algorithm makes ZigBee's hierarchical topology to adaptively maintain and optimize the routing paths during its lifetime, and an address reassignment mechanism is also introduced to ensure that our algorithm follows ZigBee specification. In addition, an energy-balancing algorithm is also proposed to reduce the power cost of low-battery device. Simulation results show that our routing scheme has better performance with lower average transmission hops and network load, and our energy-balancing algorithm could reduce the power consumption of low-battery device.


Introduction
Since the ZigBee (ZigBee Alliance, San Ramon, CA, USA) specification was first released in 2004, the study on the protocol stack and application continuously emerged due to its attractive identities of low power and low cost [1]. ZigBee aims at low power consumption and therefore long-living networks. As the energy cost of transmitter in data transmission process is the primary cost in wireless application, the routing efficiency mostly decides the power and lifetime of wireless networks. However, ZigBee devices have limited processing capabilities, storage, power supplies, and communication bandwidth. They may also move about randomly, which results in topology changes of the network. These constraints make it very difficult to find proper routing mechanisms that ensure high network throughput [2]. ZigBee uses a mixed routing mechanism combined with hierarchical tree routing protocol (HRP) and ZigBee ad hoc on-demand distance vector (Z-AODV) [3]. Nevertheless, current network formation and routing protocols described in the ZigBee specification do not fully address power consumption issues [4].
HRP is an active routing method whose routing information is established when the network is deployed and keeps invariable unless the network structure changes. HRP provides a simple and reliable topology for wireless networks [5]. To each node, if the destination of a data frame is the descendant of itself, it will send the packet to the corresponding child. Otherwise, it will transmit the message to its parent. HRP is efficient from the view of routing acquisition and memory use, but the routing paths in HRP are always inefficient, because the data frames are limited in parent-child link. Moreover, the changeless topology requires it to rebuild the hierarchical structure when nodes move and limits its performance in network extension. Finally, due to the fact that the tree is not dynamically balanced, the possibility that certain installation scenarios, such as long lines of devices, may exhaust the address capacity of the network long before the real capacity is reached exists [6].
Another problem of energy cost in wireless network is the uneven consumption of the nodes. Overall, routing methods only guarantee the better average performance [7]. Due to the network structure and node location, some devices may be overused (e.g. the node at the 'centre' of the network is more likely to receive data and join a routing path). This may lead to potential network segmentation and shorten the lifetime of the whole network [8]. To avoid some node exhausting their power too soon, an energybalancing algorithm is also investigated in this paper.
The rest of this paper is organized as follows. In Section 2, we review the related work. Section 3 briefly introduces the related contents in the ZigBee specification, and the adaptive routing optimization and energybalancing algorithm are proposed in Section 4. And, Section 5 presents the simulation results. Finally, the conclusion is shown in Section 6.

Related works
So far, although most researches on ZigBee routing have focused on the Z-AODV [9], some progress on routing performance optimization in hierarchical networks has also been made in the field of protocol improvement, beacon slot distribution, hybrid routing algorithm and so on. A modified tree routing mechanism with the introduction of neighbour table is given in [10]. The transmission cost (e.g. hops) via each neighbour device is estimated and compared to improve the routing path. It has a better performance with less power consumption per packet transfer and a long life cycle. But, this algorithm is based on the two-hop neighbour information; it may lead to severe energy and memory overhead in ZigBee networks. In [11], the reuse pattern of beacon slots in ZigBee hierarchical networks is investigated. It is concluded that beacon slots can be reused judiciously, especially when the risk of beacon collision caused by such reuse is low. On that basis, ZigBee-compatible, distributed and risk-aware probabilistic beacon scheduling algorithm is proposed. By the algorithm, one can easily assess the risk of slot reuse to decide whether the reuse is allowed and thus reduce the transmission latency. However, one key parameter in the algorithm is the estimated range of node transmission which may rapidly change in wireless channel. This may degrade the performance and cause collision in beacon slot reuse. In [12], a hybrid routing algorithm without flooding is proposed. The hierarchical topology information is utilized to optimize the routing request broadcasting to reduce the overhead. And, the residential energy of nodes is considered as one routing metric to balance the energy consumption. Nevertheless, the optimized links are based on hierarchical topology, the coverage of routing request; thus, the routing efficiency remains questionable. The authors in [13][14][15] propose several similar routing algorithms for hierarchical topology; the information in neighbour table was used to get shorter paths. However, the links in their methods were still invariable. HRP in ZigBee does not need nor allow any communication to maintain the routing path for the purpose of low power consumption. In ZigBee specification, all ZigBee devices are required to maintain neighbour tables, which record the information of the nodes in their one-hop neighbourhood. The contents in the table include each neighbour's address, device type, status of receiver and link quality [16]. This information in the tables reflects the topology of the network and can be used to improve the performance. Furthermore, this procedure will not incur extra cost in the networks. Thus, an adaptive routing optimization scheme is proposed in this paper. The neighbour table which is required in the ZigBee specification is utilized to improve the routing performance; thus, the algorithm does not need any extra communication. The adaptive routing optimization focuses on maintaining routing paths. The topology optimization is considered when a node deciding its parent and the links can be changed if there are better options. So, the routing performance can be improved during the network lifetime without extra communication.
Considering the energy balance method, it should be simple enough to be carried out by ZigBee devices. Some similar work may be learnt as references. In [17], an energy-aware routing algorithm considering sensor node mobility and channel quality was proposed. A topology considering distance to the cluster head and battery level was proposed in [18]. An energy-efficient protocol for UWB sensor network was proposed in [19] based on a cross-layer design. Although the works mentioned above cannot be transplanted directly due to the limited resources in ZigBee devices, the algorithms could significantly balance the power consumption in different networks. As references, the algorithm design, power indicator and topology-maintaining method in these works made a solid foundation for our work. In addition, there are also some papers focusing on the energy issue in ZigBee networks. In [20], an improved ZigBee tree routing algorithm based on energy awareness and energy balance is proposed. To minimize the energy consumption, the packets are transmitted in a tree topology by default. For low-battery devices, as the link cost takes account of the remaining energy, new paths are found by routing request. However, the algorithm makes the packets be forwarded within the devices with sufficient power; it is not a solution for global topology optimization. Moreover, the algorithm introduces extra routing request and response which may aggravate the energy insufficiency. In [21], an optimized ZigBee tree routing algorithm based on energy balance is proposed. The optimized algorithm imports neighbour table and the depth of nodes to make sure the local optimum routing in routing hops. The algorithm also considers the residual energy of nodes to avoid selecting low-battery nodes in routing selection. Nevertheless, the threshold of entering power saving is maintained by the ZigBee coordinator (ZC); thus, the maintenance of global topology may lead to much extra data exchanges, which may occupy the limited bandwidth. The maintaining cost and implementability may need further studies.
3 ZigBee specification and routing methods

Overview of ZigBee
Based on the IEEE 802.15.4 protocol, the ZigBee specification defines the standard of higher layers. Three device types are defined in ZigBee: ZC, ZigBee routers (ZR) and ZigBee end devices (ZED). ZC is responsible for starting a new network. ZigBee coordinator and routers are routing capable, while the ZigBee end devices cannot participate in routing and have to rely on their corresponding ZigBee parent routers for that functionality [22].
ZigBee network layer (NWK) provides functionality such as dynamic network formation, addressing, routing and discovering one-hop neighbours. The network address is recommended to be assigned in a hierarchical tree structure. The deployed ZigBee devices automatically construct the network and then changes such as joining/ leaving the devices are automatically reflected in the network configuration [23].

Link quality indication
ZigBee devices support the function of testing the link quality indication (LQI) measurement every time they receive a frame. The LQI measurement is a characterization of the strength and/or quality of a received packet. The measurement may be implemented using receiver energy detection (ED), a signal-to-noise ratio estimation or a combination of these methods. The use of the LQI result by the network or application layers is not specified in the IEEE 802.15.4 standard.
The LQI measurement shall be performed for each received packet, and the result shall be reported to the MAC sub-layer. The minimum and maximum LQI values (0x00 and 0xff) should be associated with the lowest and highest quality IEEE 802.15.4 signals detectable by the receiver, and link quality (LQ) values in between are uniformly distributed between these two limits. The LQI information of every single received packet can be simply acquired according to the standard with no more extra calculation and communication [23].

Address allocation and HRP
In ZigBee specification, it is recommended to use a distributed address allocation mechanism (DAAM) for address assignment to form a tree structure. The parameter Cm represents the largest number of children nodes, Rm means the number of children nodes which can be a router and Lm decides the maximum depth in the network. And for the same network, different nodes usually have constant Cm and Rm. Every potential parent is provided with a finite sub-block of the address space, which is used to assign network addresses to its children. Given Cm, Lm and Rm, we can compute the function Cskip(d) as the size of the address sub-block distributed by each parent at depth d as in (1) [23]: The network addresses A d+1,rn and A d+1,el shall be assigned to the nth router child and lth end device child at depth d + 1 in a sequential manner, respectively, as shown in (2): where A parent represents the address of the parent and 1 ≤ n ≤ Rm.
The hierarchical topology in ZigBee network is based on DAAM. In this tree shape structure, if the destination address is in the address space that a node is managing, the node forwards the packet to one of its children nodes. Otherwise, it forwards the packet to its parent.

Neighbour table
Each ZigBee device maintains a neighbour table which has all its neighbours' information in a one-hop transmission range. The contents for a neighbour entry are the network's personal area network (PAN) identifier, node's extended address, network address, device type, relationship, LQI, etc. Optionally, additional information such as depth can be included. Entries in the table are created when the node joins an existing network. Conversely, the neighbour entry is removed when the neighbour node leaves the network. Since the information on the neighbour table is updated every time a device receives any frame from the some neighbour node, the information of the neighbour table can be said to be up-to-date all the time.

Adaptive routing optimization and energy-balancing algorithm
In this section, the improved architecture based on link quality in ZigBee networks for smart grid application and the corresponding modification in ZigBee stack are described below. The hierarchical tree structure in ZigBee provides a simple and reliable topology for wireless networks. However, the data transmission always needs more hops than the ones in Z-AODV. This is mainly caused by two factors: firstly, HRP could only use parent-child link, while Z-AODV is allowed to send data to all the neighbour nodes; secondly, as an adaptive routing method, HRP would not update the transmission path as long as the current link is available. The former is the corollary of the tree structure. Nevertheless, the latter could be overcome for better routing performance. On that basis, a simple energy-balancing scheme in ZigBee hierarchical network is proposed. In the ZigBee specification, a node will only try to find new links when current ones failed by broadcasting rejoining request in HRP. There are three defects in this course: the large consumption of communication and node energy, the non-optimal paths restricted by current topology and the constraint condition on when to initialize. The proposed scheme may try to improve the network from the above as following.

The large consumption of communication and energy
In rejoining process, the local node asks all its neighbours to be new parents, and all the neighbours who are able to accept a new child will respond to the request. The requesting node will choose the neighbour with the best link quality as a new parent. It can be seen that the node along with all its potential parents may send messages during this course and occupy the wireless channel, and the only info it needs, in essential, is the link quality of potential parents. As mentioned in Section 3.4, a node will update its neighbour table when receiving data from neighbours, and the LQ value could be measured by any single packet. In our scheme, we add a 1-bit-long space in the NWK frame head to represent whether the node is able to accept new children. Thus, all the necessary information needed in rejoining could be acquired in maintaining daily neighbour table. When a node tries to update its parent-child link, it only needs to send a joining request to the proper candidate node directly.

The non-optimal paths restricted by current topology
In HRP, the nodes join the network sequentially, and the links keep invariant in data transmission. The joining process only chooses the node with the best LQ to be a parent; however, it cannot guarantee that it is also the global optimum for the whole network. As shown in Figure 1, node 8 is the child of node 7 in the original ZigBee network. Though it provides a better link quality to its parent, the data-to-coordinator link may have three hops. As the number of hops in HRP is mainly influenced by the depth of source and target nodes, the node will choose its parent based on the depth along with LQ in the proposed routing optimization algorithm.
The priority of the ith candidate parent node, PPr i , is calculated as (3) where LQ i is the link quality value of ith node, D i is its depth, maxLQ and maxD are the maximum values available in the network (0XFF for maxLQ and Lm for maxD), and LQ i À and D i À are the normalized values. k is a preset constant to adjust the weight of LQ and depth. A node will choose the candidate with the maximum PPr i value to be its parent. By the above principle, node 8 was the child of node 2 in our method, and it improved the global routing performance, since the data transmission from it to ZC only needs two hops.
It is assumed that the maximum number of routingcapable children, Rm, was four in the network shown in Figure 1. When node 5 tried to join the network, ZC already had four router children, so node 5 cannot be the child of ZC. This is because the ZigBee hierarchical topology tries to avoid extra communication caused by network maintenance, and it is not able to change existing link. However, thanks to the data transmission mechanism in HRP, some improvement could be made with little cost. In our scheme, a parent node could maintain and change its children when receiving a joining request from other nodes or a command from an upper layer. For a parent node in depth d, its candidate children nodes are all its neighbours, including current children, whose depth is more than d. The parent node will choose the new children based on the priority of ith candidate child node, CPr i , which is shown in (4): where LQ i is the link quality value of ith node, Nd i is the number of its descendants, LDP i is the lowest depth of other potential parents for candidate node i and D parent represents the depth of the parent node. LQ i À , Nd i À and δD À i are the normalized value of link quality, child node number and the difference between the current and potential parent, respectively. α and β are two constants to adjust the weight of each term. Nd i À indicates the importance of the candidate. The more descendants a parent has, the more nodes may benefit from its lower depth. This may lead to less transmission hops for all the nodes in the subtree where the parent node is the sub-root. Every router in the ZigBee network can sum the number of its children by checking the address allocation, and this value is required to be broadcasted as a command frame when the value changed so that the neighbours could update their neighbour table. As to ZigBee end device, the Nd i is 1. By the above principle, the value of Nd i can be easily calculated for each node. LDP i predicts the depth of the candidate's parent if it is rejected by a local one. Because the routers may announce if it is able to accept new children in its frame header as we have modified in the last sub-section, a node may find the lowest depth of potential parents through neighbour entries. δD À i shows the importance of the parent node to the child. When the node has a higher depth if it disconnects with a current parent, it should have a higher priority to be reserved.
A parent node could maintain its children based on the methods mentioned above. The related parameters cannot wholly describe the topology but reflect it in some level, because the information is acquired by updating neighbour tables, and it is not expected to introduce any extra communication to go against the idea of simplicity and low cost in ZigBee specification. Thus, the improvement may not result in the best option, yet it is good enough and very efficient considering its cost. For example, in Figure 1, node 5 might definitely be the child of ZC; node 8 was the child of node 2 in the proposed scheme, and the network depth and load were reduced. The details of the simulation will be shown in Section 5.

The constraint condition on when to initialize
The rejoining command is only carried out when a node finds that a parent-child link has failed. It is used to solve the disconnection for single node, and it focuses on the usability, but not on improving the performance. In the proposed method, this request could be part of the means of optimizing the routing. So, when a node wishes to update its link, it also can initialize a rejoining process.

The adaptive routing optimization
Some modifications have been made upon the ZigBee specification to achieve routing maintenance; they are listed as following: ♦ In the header of frames, 1 bit is used to denote whether this source device was able to accept new children nodes. In the ZigBee NWK specification, as the 13th to 15th bits in the format control field are reserved, the 13th is used as the flag. ♦ When a node tries to rejoin the network, it will send a rejoining request and wait for responses. If it receives more than one rejoining confirmation, it chooses the candidate with the highest priority to be its new parent based on Equation 3. ♦ Every ZigBee router, including ZC, is required to announce the number of its children when the value is changed by a network status command frame. ♦ Every ZigBee router, including ZC, is allowed to maintain its children when receiving a joining or rejoining request from other nodes or a command from an upper layer. ♦ In the adaptive routing optimization algorithm, the following terms were required in neighbour table entries: 16-bit network address, 64-bit IEEE address, depth, link quality, the lowest depth of other potential parents, device type, relationship for all neighbours, the capability of accepting new children, the number of its descendants for routers and ZC. ♦ When a router or ZC is maintaining its children, it may decide to acquire new children based on Equation 4; for a parent node in depth d, its candidate children nodes are all its neighbours, including current children, whose depth is more than d. ♦ In the maintenance, if a parent decides a new child, it will send an unsolicited rejoin response command frame to inform the child of the new address and parent; if a parent is going to abandon a related child, it will unicast a network report command to announce the child and make it to rejoin the network.

Address reassignment
By the mechanism in Section 3.4, the network could optimize the topology in the ZigBee hierarchical structure. Considering the situation in Figure 1, Cm, Rm and Lm are assumed to be 7, 4 and 4, respectively, as the coordinator has the address of 0, and the Cskip(0) is 148 according to (1). If nodes 1 to 4 are the children routers of ZC when the network was initialized, their network address should be 1, 149, 297 and 445, respectively; the addresses of nodes 5 and 10 are, respectively, 446 and 590. After optimization, node 5 substitutes 4 being the router child of ZC, and the addresses of 4 and 5 could be reassigned by the unsolicited rejoin response and rejoin command. However, if the parent-child relationship between nodes 5 and 10 keeps invariant, node 10 should also modify its address to 593, since the parent address has changed. This address reassignment could certainly be achieved by a rejoin command, but it may occupy more bandwidths.
Furthermore, the sub-network topology may be changed if more than one child device is involved.
Considering the address of kth router in depth d, according to (2), they can be represented as The A parent is the address of its parent, which is also a router. And, the common ancestor of all devices in the network is the ZC whose address and depth are both 0. So, (5) can be inducted recursively as In which Cskip is a 1 × d array of sub-address space managed by the parent in each depth; it can be calculated since the Cm, Rm and Lm are constant in the network. K is a d × 1 array which implies the hierarchical structure and determines the network address; we call it address coefficient array. For a given device with the address of A x , each coefficient k i in depth i can be calculated by (7): Where A parent,i is the parent address in depth i. When a router in depth p, Rp, tends to change its network address (by rejoining or address reassignment) in an adaptive routing optimization to its descendant router device in depth q (p < q), Rq, assuming that the origin address of Rq is A q and the corresponding address coefficient array is K, the optimized address is A q ′, the address coefficient array is K′. K can be represented as [K parent , K p , K child ], and K′ is [K parent ′, K p ′, K child ′]. K parent is determined by the parent address of Rp; K p is the sequential number of routers in depth p and K child indicates the relationship in a depth higher than p. If this process is only caused by the address assignment of Rp, which means that the sub-tree structure from Rp to Rq (Rp is the sub-root) keeps invariant, comparing the two arrays, we may find that K child = K child ′. As the K parent and K p can be calculated by the address of the parent and the new address range of Rp, the optimized address A q ′ can be easily acquired.
If the node is an end device, the jth end device in depth d, its address can be represented as The address conversion of the end device in the optimization is similar to that of the router. The values of K child and j are kept constant, while the K parent ′ and K p ′ are decided by the new parent and the address block being distributed.
Based on the method above, a router may notify all its descendants about the new address based on DAAM when its own address is reassigned. And, the children nodes do not have to initialize the rejoining process to get the new address. Moreover, by this method, the topology of the network changes in the minimum. The details of the optimization for nodes 4 and 5 in Figure 1 are shown in Figure 2. For clarity, all the other nodes whose depths are higher than 1 are removed, and more descendant nodes of nodes 4 and 5 are shown. This mechanism gives a lot of benefits, but it may also introduce some interferences. The two most important ones are the address confliction and the extra communication for updating the binding information between the devices and network address. Firstly, we will analyse the address confliction. Such as the circumstance for nodes 4 and 5 described above, it can be regarded as the interchange of their original addresses and may cause two series of address reassignment in their own sub-tree. Due to the CSMA/CA mechanism in physical channel, the changes of address for all related nodes have to be sequential, and it may lead to an address confliction. To solve this problem, we make all the devices involved in an address reassignment procedure forbid the data transmission during this course. When a node receives a corresponding command from its parent, it may transmit the command to its children and suspend the data transmission until the address reassignment response is received from every child device. When the device is able to send packets again, it also has to modify the source and destination address in a data frame based on new addresses. Secondly, the binding information between the network address and devices should be updated after optimization. To reduce the traffic in the network, the updating information is only sent once by the sub-root device, and all the other changes of binding could be calculated based on the address reassignment.

Energy-balancing algorithm
Energy saving and balancing strategies in wireless network are always cross-layer methods. The proposed algorithm is based on the modifications for adaptive routing optimization above. In the hierarchical structure, assuming that all the nodes have the same probability to send (and receive) a data frame for a certain node, the power consumption in communication is only related to (nearly proportional to) the total number of its descendant nodes. So, the greater depth a node is at, the less power cost it has in data transmission. The maximum number of descendant nodes in depth d, Dn(d), can be calculated as (9); from which, it may be concluded that as the node depth decreases, the increase of the number of descendants is exponential approximately: Therefore, based on the battery levels (BL k ), the algorithm may limit the minimum depth (minDk) as a router when the low power devices rejoin the network. It is shown in Algorithm 1:

Algorithm 1 Energy-balancing algorithm
The algorithm begins to function when the node battery drops down to a certain critical value which is pre-set. The while statement decides the balancing level based on remaining power. The first On may categorize the response nodes; the ones which could make the current device have a qualified depth are in the optimum group, and the others are backup to maintain the network structure in case no optimal options were found. The second On statement describes the principle of a deciding parent node when the response process is over. As this algorithm tries to eliminate the extra communication, the adjustment of depth would wait for the rejoining process. At most, the rejoining process will be initiated when a pre-set maximum number, N, of messages has been sent in the current topology.

Simulations
The performance of the proposed adaptive routing optimization and the efficiency of energy-balancing algorithm will be shown and analysed in this section. The simulation was implemented in Matlab with Simulink (The MathWorks, Inc., Natick, MA, USA). Some parameters in the simulation were set as following: time duration was 300 s; the simulation area was 20 m × 20 m; Cm, Rm and Lm were set as 4, 4 and 5, respectively; the data packet size was 100 bits; and the packet interval time was 1 s. The source and destination of transmission were randomly chosen. The parameters in the routing optimization, k, α and β are set as 0.4, 0.4 and 0.6, respectively. We also made a mapping from the LQI received data to the transmitter power when a local device will send frames to the node. In our simulation, the LQI was based on the signal power received by the nodes, and the channel followed Rayleigh fading. Thus, we mapped the transmitter power to the best LQI of 0xff (255) and zero to 0x00 (0); the values in between were uniformly distributed.
Each simulation was carried out 1,000 times to average randomness. All the nodes are uniformly deployed in random in the simulation area. The node number in the simulation varied from 10 to 100. We compared the performance of the adaptive routing optimization and the original ZigBee hierarchical routing protocol. Considering that ZigBee networks may update the routing by re-initialization, we also took this strategy as a comparative term. The re-initialization procedure was carried out 10 s after the simulation started.

Simulation of adaptive routing optimization
Firstly, the performances of the different routing mechanisms in the static network, in which all nodes would not change their physical position after deployment, were simulated. Figure 3 shows the result. It is shown that the adaptive routing optimization can effectively reduce the average hops in data delivery. In the networks with fewer devices, the performances of three methods are similar; as the node number increases, the differences between the different nodes become more obvious. It seems that the more candidates are in the optimization, the better improvement the algorithm could achieve. In the case of a 100-node network, the average hops in the ZigBee routing is 10.11, while in the adaptive routing optimization algorithm, the value is 9.68; the improvement was about 4.25% better than the specification. From the figure, we may also find that the re-initialization could also reduce the hops to some extent; furthermore, it does not need any modification in the stack. It may be an optional scheme in the static networks.
However, in practical application, the devices may move randomly. The network could not keep static during its lifetime. The performance of an adaptive routing optimization in a dynamic network was also simulated in this paper. In a dynamic network, the nodes in the network had a probability to change their position to simulate the unexpected interference in real application. Each node had 10% chance to move during the simulation, and the time it moved was uniformly random. The new position of a moving node followed a two-dimensional normal distribution centred with origin coordinates with a mean of 5. Also, the re-initialization need adjustment; this operation has to be implemented periodically since the network topology would be changing in real time. In the simulation, the network might be reset every 100 s. Figure 4 shows the average hops in data transmission for different routing schemes in the dynamic network. It could be seen that the adaptive routing optimization could also reduce the average hops with greater effect. ZigBee routing had most hops because it was not able to change its transmission links during the lifetime of the network. If the network updated the topology by re-initialization, the average hops may slightly decrease. But, the optimization is not in real time due to the 100-s interval between each operation. Moreover, the parent-child links in the original ZigBee specification were only decided based on the link quality; its improvement was limited. On the contrary, the adaptive routing optimization was nearly real time, and the information in the neighbour table was considered during the determination of routing. So, it had the best performance in our simulations. In the 100-node network, the average hops may be improved from 10.15 to 9.28, with about 8.57% improvement.
Based on the simulations described above, it can be noticed that the ZigBee routing with re-initialization could also reduce transmission hops with no cost in the algorithm design. However, the initialization will introduce more traffic. As the communication in the network may indicate the efficiency of routing methods, the network load for the different routing methods in the dynamic network is illustrated in Figure 5. It can be seen that the price of re-initialization is huge; the network load is much higher than the other routing schemes. From the graph, we could also conclude that the adaptive routing optimization also improved the efficiency. Initializing the network may introduce a lot of extra frames; thus, it had the worst performance. Compared with the original ZigBee routing, the proposed method could maintain the routing path and use the knowledge in neighbour table for global optimization; this resulted in the lowest network load from the three approaches.
In the adaptive routing optimization, there are three parameters, k, α and β. The effects of these arguments on communicating performances are also measured and quantitatively analysed. Figure 6 illustrates the average hops and average link quality in received frames in the network with 100 nodes. It can be seen that as the k value added, the average hops in the data transmission kept reducing; the absolute value of the slope also decreased. It means that the higher k value may benefit the links, but the effect is diminishing. On the other hand, a high k value also led to a poor link quality. And, the bigger the parameter, the faster the link quality declined. From the figure, we may find that the value from about 0.3 to 0.8 is an acceptable compromise for the algorithm.
For the parameters α and β, Figure 7 shows their influence on the communication performance. Both of them had similar effect on average hops and link quality with that of k which is discussed above. The greater the argument, the lesser the hops and the poorer the link quality in data transmission. As the values added, the improvement on retransmission times gradually declined, while the link quality got worse faster and faster. Besides, compared with Figure 7a,b, it is shown that the network is more sensitive to α. As the link quality is closely related to bit error rate and transmitter power, the algorithm prefers lower values for α and β. It is shown that the extent from  0.2 to 0.5 for α and 0.5 to 0.8 may be reasonable, since within these ranges, the number of hops drops faster and the link quality has not yet seriously fallen.

Simulation of energy-balancing algorithm
In the simulation of the energy-balancing algorithm, we set the parameters BLi and minDi to BL 1 = 10%, minD 1 = 3, BL 2 = 30% and minD 2 = 2. It means that if the remaining battery of a certain device was below 30%, its minimum depth was 2 as a router, and if the power was less than 10%, its depth was no less than 3. Firstly, the balancing performance was tested. The node number in the network was fixed to 50; the number of low-battery device was changing for the different simulations. And, the nodes in BL 1 and BL 2 were equal. Since the transmitter power contributes most of the node energy cost, the average load was used to evaluate the performance. The result was shown in Figure 8. As the percentage of the low-battery devices added, the average load for all nodes was also increasing slightly. It meant that the cost of low power for some certain devices was that all the nodes had to take more communication on average. When the rate of the low-battery devices was 10% less, the balancing algorithm performs best. Compared with the average load for all nodes, the balanced nodes in BL 1 and BL 2 only had 9.5% and 37.2% energy cost on communication, respectively. However, the rates increased to 40.2% and 51.6%, respectively, when there were more than a quarter of low-battery nodes. In the proposed algorithm, the balancing was on the basis of the integrity of the topology. A node could add to the depth of the network only when there is another device which could be used as an alternative in the hierarchical structure. Otherwise, it had to keep the current depth even it had inadequate battery. If the percentage of low-battery nodes reached 40%, the nodes in BL 1 and BL 2 only had 67.9% and 76.1% node load of the total average, respectively. For the situation of more than half low devices, the effect of energy balancing was very limited. Based on the simulation, it can be concluded that the energy-balancing algorithm was able to limit the power consumption of low-power devices when they were less than 10% to all nodes in the network.

Conclusions
ZigBee hierarchical network provides a simple and reliable solution for short-range, low data rate and low-cost communication. However, the invariant topology due to the devices deployed limits the efficiency of the routing. In this paper, an adaptive routing optimization in ZigBee hierarchical ZigBee network is proposed. When a node attempts to join/rejoin a network, a compromise of link quality and depth is used to decide the priority in the algorithm. By this method, the ZigBee hierarchical structure can be updated in real time. Several  modifications have been made to meet the requirement in the proposed mechanism.
An energy-balancing algorithm based on adaptive routing optimization is also designed in our work. In the algorithm, the low-battery device will try to rejoin the network with a greater depth to reduce the number of its descendants. This will consequently lessen the data transmission and energy consumption of balanced nodes. The simulation results show that the adaptive routing algorithm could effectively lower the average transmission hops in both the static and dynamic networks simulated. And, the effects of the parameters in the algorithm are also tested and analysed. The simulation on energybalancing scheme indicates it would control the power cost in low-battery devices.
For future work, the noise and interferences in the wireless channel should be considered, simulated and tested before the algorithm is applied in real application. The compatibility of adaptive routing optimization and ZigBee specification needs further analysis and testing.