A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service
Solemnly declare: The following articles are suitable for beginners of ZigBee children's shoes, the great god please skip ...
work has heard of ZigBee technology, just know is a wireless communication technology, specific technical details and use are not very clear. Unexpectedly, a project requires the use of ZigBee technology, which is to take a good look at what ZigBee is. Write down my understanding of ZigBee technology here.
2 What is ZigBee?
ZigBee is a wireless communication technology. Wireless, as the name implies, is through radio waves (like WiFi, mobile phones) as a means of communication information carrier. Communication, that is, a device and another device need to communicate and communicate. People need to communicate, communication requires the use of language, that the language may exist in grammar, that is to say that both sides should understand what the other said, if a only understand Chinese, the other only understand English, then his two communication may need a translation. The same between devices, they need to follow certain rules. Both devices are required to send and receive information according to this rule, which is the agreement. For ZigBee communication technology is the ZigBee protocol. In fact, the computer technology has two big aspects, one is the computer itself (Hardware technology progress), one is the communication between different devices. Analogy to us human beings, one is the human problem, one is a social problem. Said so much nonsense, the following summary: ZigBee communication is a device and equipment to communicate between a way, this way specifies what physical media to transmit information, what kind of information format, who first send information, information transmission process was disturbed how to do, If the other party does not receive what to do and so on a series of questions
Well, let's see what the official definition is: ZigBee is a low-power LAN protocol based on the IEEE802.15.4 standard. According to international standards, ZigBee technology is a short-distance, low-power wireless communication technology.
Also attached is the difference between ZigBee, WIFI, Bluetooth and the contact diagram:
3 and ZigBee Say hello (mixed face cooked)
We make an analogy between ZigBee communication and human communication, and then explain how ZigBee realizes the communication between different devices in a constant questioning way. Said before, ZigBee is generally used for LAN communication (a classmate raised his hand, "What is the LAN ah?") "That classmate, you put your hands down first, holding the strange Tired" "LAN is the local use of the network, that is, a small range of communications, you like your home needs a different device communication, you can use ZigBee technology" "We all use Internet Internet, chat, it is based on the TCP/IP protocol, TCP/IP can form a local area network or make up the Internet "), then we use communication between your family as an example of analogy. The following scenarios are assumed: There are 3 people in your family, you, your father, your mother | There are 3 ZigBee devices in the analogy ZigBee network. Now you probably know how I'm going to talk about this ZigBee.
A -bit MAC address (Global unique address)
Yo, our goal is to allow ZigBee devices to communicate with each other. The first question before us is how to guarantee the uniqueness of ZigBee devices? In your home, you must know father and mother, the same father, mother also want to know you. How do you know Mom and dad? Now give you 1S think time, well, you remember the father, Mother's height, appearance and other characteristics. That is to say, the father, mother has certain appearance characteristic, two person long of completely identical is really rare. Now medicine says that DNA is different, so everyone is different, and to humans it is DNA that is the only sign you have on Earth. What is the ZigBee device to determine its uniqueness of the NA, this say, ZigBee devices are made by our human, we can artificially assign them a unique address. I think so, check the information (wait for 5 minutes .....) ）。 The only physical address that identifies the ZigBee device is a string of 64bit, such as: 000124b00028b679, the front 24bit represents the company code, and then 40bit represents the address segment. These addresses need to be applied to the IEEE Committee.
network address (used to indicate a device inside the ZigBee network)
You may think, I at home, generally only shouted "father", "mother" can distinguish them, not every time to see their height, appearance and so on a series of characteristics I can only determine the person I am looking for. Is there any other way to determine the ZigBee device within a given ZigBee network? I think it should be. After the network is formed between ZigBee devices, each device allocates a short address of 16bit, which can be communicated between devices through this short address. LAN, the range is small, you can use a shorter address to distinguish between different devices.
ZigBee Network setup, device join
in your family, your father, mother and you all have different roles. Have time to find out your family's hukou, the hukou is usually numbered (in the upper left corner of the hukou or upper right corner). Your father may be the head of the household, you are the child of the parents (this is not nonsense?) I just let you know that different people have different roles in the family. So you might ask, what are the roles in the ZigBee device, and what do the different roles do? ZigBee device is divided into coordinator, Router, enddevice three kinds of characters. Coordinator is responsible for establishing the ZigBee network and assigning a unique ID to the ZigBee network (they call this id,panid), router can join the coordinator established network, and it can forward the data, that is, as a data relay, Used to extend ZigBee wireless communication distance. Enddevice is a terminal equipment, joined ZigBee Network, can only receive and send data.
Come to the ZigBee family map:
Figure Two: ZigBee network topology diagram
, your mother called you home for dinner!
you and Mom and dad at home, you play games tired, think of something. You can choose the following ways to communicate with your mom and dad.
1: "I'm hungry, hurry up and make something to eat," shouted the voice directly. In this case, mom and dad heard, may appear the following situation: A, Dad is busy, back to a sentence: "I am busy, looking for your mother", mother back to the sentence "I make you an egg fried rice". B, Mom and dad back together: "Good boy, we will cook for you", then the father and mother to cook together in the loving scene. C, Mom and dad are relatively busy, back to the "bear children, playing games all day, but also the face to say hungry, their own cooking to go, we also want to watch TV drama", of course, in this case, you can consider whether you are not rushed to the phone fee to send. But then again, you're yelling, there's a more professional communication term, broadcast. Yes, one of the ways that ZigBee devices communicate is broadcast, a device broadcast, and other devices in the network can hear.
To popularize the broadcast address provided by ZigBee. Tip:
0xFFFF-This is a broadcast address for all devices in the network
0xFFFD-If the destination address is set to this address in the command, then only the device that opened the receiver will be broadcast
0xFFFC-Broadcast to coordinator and router
0xFFFE-If the destination address is this address, then the application layer will not specify the target device, but instead read the binding table through the protocol stack to obtain the short address of the corresponding target device
In addition, 0x0000 to 0XFFF8 are valid destination addresses. Each address is just a target device.
2: Quietly drops to mother side, alone with mother said: "Mom, I am hungry." In this case, it is very likely that Dad made the meal is really terrible. Think of this, in ZigBee is the point-to-point communication method. In this way, both sides of the communication have to specify the destination address.
3: And father agreed to a signal, a loud cough three sound. This way, you do not have to consider what the original address, the destination address these trivial things. All you have to do is send this code, and dad will know your forehead and know what you want to eat. Brilliant Ah, this trick, but this also depends on how the mood of dad at that time ah. This is called binding (Bonding) in ZigBee. Communication between the two sides of the communication when the two sides do not need too much information, as long as the password, you can complete the corresponding functions.
Knowledge Field VS Endpoint
From the above description, we know that the device short address is used to mark a ZigBee device. It's the same as you, your father, your mother at home, different titles mean different people. However, another problem comes to the surface, that is, children and adults have a life experience and the knowledge of the field is not the same ah, you put your son (6 years old) come over and say to him: "Son, mother is not at home, this afternoon we go to eat KFC, OK?" ”。 "Yes," replied the son happily. Good communication between the two sides. The following scene you think, "Son, do you know that pointer variables in C are a variable that stores memory addresses?" ", the son of a blank face,"??????? ”。 Let the rest of the scene fill the brain. The above story tells us that we can communicate happily, and the content of communication needs to be understood by both sides. In ZigBee communication There is a concept similar to this, called Endpoit, a ZigBee device can exist a lot of endpoit. It's the last picture.
In this example, the left side is two switches (possibly in the corridor), two switches share a ZigBee node "Z1" (equivalent to two keys on the development Board, which should not be difficult to understand), they together control the right three light bulbs (also on the same node-"Z2"). Z1 's Key1 controls the lamp1 of Z2, while Key2 controls Z2 lamp2 with Lamp3.
There are several concepts that have not been seen: Cluster ID, Binding Table, in fact, there is a profile, attribute. Let's take a slow-down and say what these are.
Binding Table the best understanding, said above, in order to facilitate communication, we can establish a binding relationship, the establishment of a binding relationship between the two sides of the short address, endpoit and other information are stored in the binding Table.
Profile ID, this is the application ID number assigned by ZigBee organization, such as wireless switch with 0x0001, smart meter with ox0002, universal remote control with 0x0003 and so on. In this example, this ID number is specifically used to make a light switch. Why did you do it? Here embodies the meaning of "standard", different manufacturers function of equipment, because of this ID can be used with each other, Chint's switch can control Philips lights ...
Endpoint, the name seems easy to misunderstand, think it is the serial number of the device, it is not. In this example, Z1 has key1/key2 two endpoint, doing different things separately. It corresponds to the same "application" in the 0-240 different "sub-applications", of which No. 0 endpoint is "ZDO" reserved, can not occupy. If you are familiar with TCP/IP, you may feel that the Endpoit and port (port number) are somewhat similar.
Cluster ID, what does this call? Call the message cluster ID ... My understanding is, "This is what kind of information", the sending side and the receiver must correspond, but the specific "class" How to divide, we can decide for ourselves. For example, I can fix this: Cluster id=1 represents a switch once, Cluster id=2 stands for continuous flashing ... or define cluster id=1 to represent point-to-point control, while cluster id=2 represents full control, and so on ...
attribute, in the ZigBee protocol stack, each standard profile (e.g. HA, Application layer specification for smart home) defines a lot of cluster IDs, and each cluster The ID has some attribute and actions that are well defined.
What the? It's too hard to understand, okay, let's take a life example.
Take the first year of the university's friendly dormitory as an example:
Male dormitory 8 person constitute development Board a, female dormitory 8 person constitute Development Board B.
Male Dormitory 8 person is the development Board a 8 endpoint.
Male dorm 5 people like to learn, 3 love to play, divided into two groups with different behavioral interests, that is, two profiles.
Female Dormitory 8 people 3 like to learn, 2 love to play, the remaining 4 love to eat, divided into 3 groups, that is, three profiles.
The profile of love learning = 0x0010; Love to play profile = 0x0011; Love to eat profile = 0x0012;
The above definition ends and now looks at the binding process:
A male classmate (love play) make a phone call to the female dormitory said to go out to play, 8 female classmate of 6 because of hobby different (profile value different), direct refusal. The remaining 2 girls have one because hate the male classmate (not registered in the mind of the male classmate of any good), also refused, another girl secretly love the boy (the brain has filled the male classmate of any of the good, ready ...), so the binding succeeds.
In this way, the boy will directly dial the girl's cell phone.
Assuming that the boy ranks old 3, that does not necessarily require the girl also ranked old 3.
I have been blind for a long while, I do not know you crossing can see this place. The above discussion also basically covers the beginner's most puzzled, but also the most want to understand the concept.
5 ZigBee protocol Stack structure
The design of ZigBee protocol stack adopts layered design idea. Or the previous picture:
As you can see, the physical (PHY) layer and MAC layer are defined by IEEE 802.15.4.
In layered mode ZigBee communication:
In the 802.15.4 and ZigBee protocol, the concept of "primitive language" is used to describe the service between adjacent two layers, and the function of inter-layer calling or transmitting information can be expressed in the primitive language. Although, there are many different layers throughout the system, the communication between tiers is very similar. For example, PHY, Mac, and NWK layer both provide data services for their upper level, and the mechanism of requesting data Service is similar: the high level requests the transfer to the subordinate through D-SAP, and the subordinate transmission succeeds and returns the state to the superior.
It is precisely this similarity that makes the "service primitive" approach especially important. Each primitive either executes an instruction or returns the result of a previous instruction. The primitive also takes instructions to run the required parameters.
Describes a general way for a layer to serve its upper layers, with four types of primitives: request, instruction, response, and acknowledgement. In other words, all services in the 802.15.4 and ZigBee standards can be categorized as one of these four primitives. The original pragmatics is described in the following format:
(note: For most of the readers of this article are present or future software engineers, followed by the English name to express four kinds of primitives)
<the Primitive >.indication
First, the n+ Layer 1 to N to request a service using the request primitive, such as the MAC layer requesting a MPDU transport service to the PHY layer, it must request a pd-data.request primitive from the PHY layer.
The N-tier emits a indication primitive to its service user (often the N+1 layer) to indicate an event that is important to the n+1 layer. For example, when the PHY layer receives a set of data that needs to be passed to the MAC layer, it generates a pd_data.indication primitive to the MAC layer to pass the data to.
If the indication primitive requires a response to it, the n+1 layer emits a response primitive. It is important to note that the PHY and NWK layers do not have any response primitives, but only the Mac and the APL layer.
The Confirm primitive is issued by the N layer and is used to finalize the request service for the initial n+1 layer. For example, in the example above, when the data is sent, the PHY layer tells the MAC layer that the transfer has been completed successfully.
Note: This article is only an easy-to-understand way for readers to understand the basic concepts of primitives, and if the reader needs to learn more about the details of the primitives provided at each level, read the protocol documentation for 802.15.4 and ZigBee directly.
ZigBee equipment in the work, a variety of different tasks at different levels of execution, through the layer of services, to complete the tasks to be performed. Each layer of service mainly completes two functions: according to its lower service requirements, to provide the appropriate services for the upper layer, and the other is based on the service requirements of the upper layer to provide corresponding services to its lower layer. Services are implemented through the service primitives. You can think of the primitive as the API function is the most basic operation of ZigBee, the general Protocol has a program implementation of the original language in its own development system, only need to call, set parameters just fine. If you want to implement the underlying details yourself, you must go deep into the level of the primitive in the open source protocol stack. In other words, we just need to understand the original language, the real development program only know what parameters we give the system on the line.
With the above basis, we can do experiments according to the actual experimental platform. We generally understand what is the ZigBee protocol, of course, this is only understood from the application layer, if you just use ZigBee technology to achieve the user needs of your project, then you based on the actual protocol stack (such as Z-stack, TI provides the ZigBee development platform) to provide the API to carry out the application layer development is possible. If you want to delve into the ZigBee protocol stack or want to learn the ZigBee protocol stack design idea, we suggest reading the source code of the Open Source ZigBee protocol stack (FREAKZ protocol stack, TinyOS, etc.).
Remember to read ZIGBEE Specification Oh.
Official Information: Zigbee specification
ZigBee Communication (first meeting)
Start building with 50+ products and up to 12 months usage for Elastic Compute Service