What is a turnip?
Goldfish need another net!Actually, I was going to continue the series of topics devoted to the work of the RTLS -
real-time positioning system . Namely, talk about the wireless infrastructure of the system based on ZigBee networks. But suddenly I was surprised to find that there are no publications on Habrahabr on the IEEE 802.15.4 standard and the ZigBee specification. There are only a few mentions associated with this or that application. I will try to fill this gap as much as I can.
Recently, wireless sensor networks have become increasingly common and important. Networks, which in their purpose, parameters, specifications differ significantly from communication networks - WiFi, GSM, LTE, etc. Among others used in sensor networks, the ZigBee specification stands out - the most advanced add-on to the IEEE 802.15.4 standard.
This year marks 10 years since the founding of the ZigBee Alliance, and in October 5 years have passed since the approval of the current ZigBee Pro Feature Set Set 2006 specifications. So, the publication can be considered a jubilee one.
')
Those wishing to get acquainted with the self-organizing self-regenerating sensor network that does not require a special frequency resolution, please ask for cat.
I'll start with the headline questions:
What for?
Many applications require wireless communication networks that do not have high transmission speeds, but reliable, robust (self-healing), easy to deploy and operate. It is also important that the equipment of such networks allowed long-term operation from autonomous power sources, had a low cost, and was compact. An example of such an application is “smart home”.
Even 10 years ago, none of the network standards met this combination of requirements, which led to the creation of IEEE 802.15.4 and ZigBee standards that describe robust scalable multi-step wireless networks that are easy to deploy and support a variety of applications.
Why choose ZigBee?
ZigBee networks, unlike other wireless data networks, fully satisfy the requirements listed above, namely:
a) thanks to the mesh topology of the network and the use of special routing algorithms, the ZigBee network provides self-healing and guaranteed packet delivery in cases of disconnection between individual nodes (appearance of an obstacle), overload or failure of some element;
b) the ZigBee specification provides for cryptographic protection of data transmitted over wireless channels and a flexible security policy;
c) ZigBee devices are characterized by low power consumption, especially end devices for which a “sleep” mode is provided, which allows these devices to work for up to three years from one conventional AA battery and even AAA;
d) ZigBee network is self-organizing, its structure is set by the configurator’s stack profile parameters and is generated automatically by attaching (reconnecting) to the network of its devices, which ensures ease of deployment and easy scaling by simply attaching additional devices;
e) ZigBee devices are compact and relatively inexpensive.
Communication over the ZigBee network is accomplished by sequentially relaying packets from the source node to the destination node. The ZigBee network provides several alternative routing algorithms that are automatically selected.
The standard provides for the possibility of using channels in several frequency bands. The highest transmission speed and the best noise immunity are achieved in the 2.4 to 2.48 GHz range. In this range, there are 16 channels of 5 MHz.
The price that had to be paid in ZigBee networks for minimizing power consumption, compactness and cheapness is a relatively low data transfer rate.
"Gross" speed (including service information) is 250 kbps. The average data transfer rate, depending on the network load and the number of retransmissions, is from 5 to 40 kbit / s.
The distance between network workstations is tens of meters indoors and hundreds of meters outdoors. Due to retransmissions, the area covered by the network can be quite significant: up to several thousand square meters in a room and up to several hectares in open space. Moreover, the ZigBee network can be expanded at any time by adding new elements or, on the contrary, divided into several zones by simply assigning the appropriate number of new network configurators. This is useful to reduce the load and increase the data transfer rate accordingly.
A bit of history
ZigBee Alliance was established in 2002. Now it includes more than 300 companies. The goal of the alliance is to develop efficient wireless network protocols and ensure compatibility of devices from different manufacturers. The first standards were “born” in 2003 and were actively improved and expanded.
Stochastic addressing, Many-to-One and Source Routing routing mechanisms were introduced, as well as the ability to detect asymmetric relationships, which increased the efficiency of ZigBee networks for a number of specific applications.
Standard application profiles and a library of standard clusters have been developed. This greatly simplified the development of applications, facilitated and accelerated the introduction of new solutions using hardware from different manufacturers.
Introduced a number of new mechanisms that increase the security and reliability of the network.
There is an automatic transition to the "clean" frequency channel in the event of interference.
The current ZigBee Pro Feature Set 2006 specification was adopted in October 2007.
ZigBee Devices
ZigBee networks are built from base stations of three main types: coordinators, routers, and end devices.
The coordinator starts the network and manages it. It forms the network, performs the functions of the network control center and trust center (trust center) - sets the security policy, sets the settings in the process of connecting devices to the network, controls the security keys.
The router transmits packets, performs dynamic routing, restores routes in case of network congestion or the failure of any device. When forming a network, routers join the coordinator or other routers, and can connect child devices — routers and end devices. Routers operate in continuous mode, have a stationary power supply and can service “sleeping” devices. The router can serve up to 32 sleeping devices.
The end device can receive and send packets, but does not translate and route them. End devices can connect to a coordinator or router, but cannot have child devices.
End devices can be put into sleep mode to conserve battery power. It is the end devices that deal with sensors, local controllers and actuators.
Network formation
The ZigBee network is self-organizing, and its work begins with the formation. The device assigned during the design by the personal network coordinator (PAN coordinator) determines the channel free of interference and waits for connection requests.
Devices attempting to join a network broadcast a request. While the PAN coordinator is the only device on the network, it responds to the request and provides only one to join the network. In the future, also joined to the network routers can provide accession to the network.
The device that received the reply to the broadcast request exchanges messages with the connecting device to determine the possibility of the connection. The ability is determined by the ability of the connecting router to service new devices in addition to those previously connected.
Joining the network (joining)There are two ways to join: MAC association and re-network attachment (NWK rejoin).
MAS AssociationThe MAC Association is available to any ZigBee device and is implemented at the MAC level. The MAC mechanism of the association is as follows:
The device that allows you to join it, puts on the MAC level permission to join.
A device joining the network issues a join request at the MAC level and broadcasts a beacon request.
Having received a beacon from devices that are ready to connect the device being connected, the latter determines which network and device it wants to join, and sets the MAC entry level requirement with the “reattachment” flag set to FALSE.
Then, the incoming device sends an attach request to the device selected for connection and receives a response with the network address assigned to it.
With the association MAS, the data is not encrypted, so the association is not secure.
Repeated network connection Repeated network connection contrary to the name can also be used during the primary connection. It runs at the network level. However, if the incoming device knows the current network key, the packet exchange can be secure. The key can be obtained, for example, when setting up.
When reconnecting, the joining device issues a join request at the network level and exchanges the "join request" - "reply to join request" packet with the connecting device.
Network dynamicsExcept when new devices are connected, the network structure also changes in cases when devices leave the network and re-join in other places (this happens, for example, in the case of a device reboot).
The figure below is an example of reconnection. The device with the address “0E3B” is reconnected as “097D” and then as “0260”. Each time it joins a different router and obtains an address from the address range available to the connecting router.

Reconnect the end device in the tree
Network protocols
The protocols regulated by the IEEE 802.15.4 and ZigBee 2007 Specification standards ensure the formation and operation of a wireless sensor network.
The IEEE 802.15.4 standard defines the physical and MAC layers, and the ZigBee specification defines the network layer and application layer. The figure shows the ZigBee protocol stack.

ZigBee protocol stack
I apologize, but in this place I am forced to interrupt due to the late time. Description of the protocol stack can be found here:
http://www.rtlsnet.ru/technology/view/3 .
If habravchane express interest in the topic, I undertake to describe the stack profile, network topology options, routing algorithms, application profiles, clusters, endpoints, bindings, and security. That is, to tell how, in fact, the topology is formed, routes are built and restored, how external devices are connected and programmed in a standard way - sensors, controllers, actuators.