ZigBee,ZStack

ZigBee Application Guide

1. Device Type

write picture description here

Zigbee networking equipment is divided into three categories:

1.Coordinator (the black node in the figure). Initiating the network and determining the PAN ID of the device. There is one and only one in a network. After the networking is completed, it degenerates into a router.

2.Router (the red node in the figure). To manage several child nodes, it must be online all the time.

3.End-device (the white node in the figure). Can sleep.

As can be seen from the figure, the zigbee network is a mesh structure. From the perspective of graph theory, the End-device is equivalent to a leaf, and the Router is equivalent to a branch. The Coordinator is equivalent to the root node when networking, but once the networking is completed, the entire network has no center, and data exchange does not need to go through the Coordinator. It can also be seen from the figure that, from one node to another, the data will be exchanged by multiple relay nodes in the middle, so there is a problem with the routing algorithm.

2. Stack configuration type

Simply put, networking is usually only possible between devices with the same stack type. Also divided into three categories:

1.Zigbee。

2.Zigbee PRO。

3. Customize.

3. Address

Device addresses are divided into 64-bit MAC addresses and 16-bit logical addresses. The former is globally unique, while the latter is unique in the entire network. The uniqueness of the latter is guaranteed by the relevant address allocation algorithm and address conflict mechanism.

In addition, for applications, there is an EndPoint that needs to be specified, which is equivalent to the port number of ordinary TCP/IP. The afRegister function is used to specify the EndPoint.

4. Packet Type

There are three categories according to the destination:

1. Unicast . to a separate device.

2.Multicast. to a group of devices. Knowledge point: Group Addressing

3. Broadcast. Broadcasting all over the web.

The following broadcast addresses exist:

0xFFFF - This is a broadcast address that broadcasts to devices in the entire network

0xFFFD - If the target address is set to this address in the command then only broadcast to devices with reception turned on

0xFFFC - broadcast to coordinators and routers

0xFFFE - If the destination address is this address, the application layer will not specify the target device, but 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. where the coordinator is 0x0000.

According to the different ways of destination assignment, it can be divided into two types: direct and indirect. The latter finds the logical address of the destination by looking up the Binding Table. Knowledge points: The meaning of Binding, and the implementation of Binding Table.

5. Routing

  1. Route discovery, selection and maintenance related rules.

  2. Routing table storage and maintenance

6. Others (all of the following can be used as research points)

  1. The replacement of the parent node due to the movement of the End-device .

  2. Resolution of PAN ID conflicts, and implementation of cross-PAN communication.

  3. Selection of wireless channels. Knowledge point: Detect the environment and determine the channel with the least noise .

7.Profile ID与Cluster ID

In addition to defining the physical layer and link layer of the ZigBee protocol, the ZigBee Alliance also makes some unified regulations for the application layer. Among them, Profile ID is used to distinguish the application field of the device, such as light or sensor. The Cluster ID is used to subdivide the operations under the same Profile, such as whether the light is brightened or dimmed.

Z-Stack

Z-Stack is a Zigbee protocol stack introduced by Texas Instruments. The source code is not public, only the interface documentation on how to use it.

1. Message

The messages of Z-Stack are divided into two categories: system messages SYS_EVENT_MSG and custom messages. The former can be divided into three categories:

1. Hardware news. For example KEY_CHANGE

2. AF messages. Mainly messages related to the exchange and routing of data. For example AF_DATA_CONFIRM_CMD, AF_INCOMING_MSG_CMD.

3. ZDO message. Messages related to the application of a specific device. For example ZDO_STATE_CHANGE, ZDO_CB_MSG.

2. Networking

1. You can set the Channel and Pan ID used by the Coordinator for networking, otherwise the Channel and Pan ID will be randomly generated.

2. In the case of specifying a Channel or Pan ID, if a network has already used the Channel or Pan ID, the Coordinator will re-select a Channel or Pan ID. However, the matching Router and End Device cannot detect this change, so they will join the existing network instead of the newly created network by the Coordinator. (After doing experimental tests, it was found that the coordinator will indeed replace a PANID, but after the next time it is still the replaced PANID, there is no saying that the PANID is replaced every time, such as OXFF00 at the beginning, and then randomly replaced by 0x0001, After that each download is 0x0001, no longer replaced)

3. The device can be automatically connected to the network when it is turned on, or it can be manually connected to the network later. After successful network access, you can save the network access information.

3. Bind vs Lookup

Binding is when the sender specifies the receiver. A lookup is where the receiver registers an acceptable sender.

4. Event Handling

Design Principles:

1. The SYS_EVENT_MSG message needs to be processed all at once.

2. While other messages are best processed one at a time.

sentTransID can be used to identify the message. Each time a message is sent, it is automatically incremented by 1.

5.FLASH driver

From the chip manual, CC2530 uses NOR FLASH. The storage scheme it uses is actually similar to a patent I filed last year: its implementation is more general, but less performant than mine.

6. Processing flow

1) Main process

main—the main function

->osal_init_system

–>osalInitTasks—Initialize the task structure, each task will be assigned a global task ID, which will be used when sending messages.

->osal_start_system—task scheduling infinite loop

–>osal_run_system

—>tasksArr—task processing callback

2) Customized event handling

Coordinator_ProcessEvent—event processing entry, which can be defined as a task

->KEY_CHANGE - key processing

–>Coordinator_Net_PermitDeviceToJoinNet

—>ZDApp_NetworkInit—Network not established OR NLME_PermitJoiningRequest—Network established

->AF_INCOMING_MSG_CMD - message received data

->AF_DATA_CONFIRM_CMD—returns the result of sending data (the result includes whether it was successfully sent, etc.)

3) Network construction and network access

Initiator:

ZDOInitDevice

->ZDApp_NetworkInit

–>ZDO_StartDevice

receiver:

ZDO_JoinIndicationCB

4) Exit the network

NLME_LeaveReq

5) Customize the process

If the standard process of ZStack cannot meet the needs, you need to use the ZDO_RegisterForZdoCB function to register the corresponding callback function to change the standard process.

7. Configuration files

source/Tools/CC2530DB/f8wConfig.cfg - can configure PAN ID etc.

8. Important functions

Long and short address translation: AddrMgrExtAddrLookup and AddrMgrNwkAddrLookup.

Get long address: NLME_GetExtAddr.

9. Reboot

The restart of Zstack is divided into the following categories:

1)SystemReset

The mechanism of this restart is to close the interrupt and loop in an infinite loop, and then the WatchDog times out, resulting in a restart. is for a "hard reboot".

2)SystemResetSoft

This restart, resets the PC pointer to 0, where the code started at power-up. is for "soft restart".

3)ZDO_DEVICE_RESET

In addition to function-call-style restarts, there are also message-style restarts. The message processing finally calls SystemResetSoft to restart.

10. First and second networking

The difference between the two is that during the second networking, the networking information of the last startup is stored on the FLASH of the device. Therefore, there is no Beacon request handshake process during the first networking.

The program uses the ZDApp_ReadNetworkRestoreState function to determine whether there is the last networking information.

11. Automatic and manual networking

HOLD_AUTO_START

Packet Sniffer

In order to facilitate the debugging of the zigbee protocol, TI also provides the CC2531 USB Dongle. This Dongle hardware cooperates with TI's Packet Sniffer software to monitor and analyze the surrounding zigbee network communication. That is to say, it monitors not a single Zigbee module or device, but all Zigbee signals in an area.

When using, first need to set the Zigbee Channel to monitor. Then you can turn on the capture button.

The following uses Packet Sniffer to make a simple analysis of the data packets in the Zigbee networking process.

Networking (that is, the process of zigbee capturing packets)

1.EndDevice continuously sends Beacon request packets.

2.Coordinator sends its own MAC address and PAN ID to EndDevice. In addition, the information includes the node depth, the maximum number of child nodes and so on. Based on this information, EndDevice will select a node with spare capacity and proceed to the next step.

3.EndDevice sends an Association request to Coordinator, which contains the MAC address of EndDevice.

4.Coordinator returns a response packet.

5.EndDevice sends Data request to Coordinator.

6.Coordinator returns a response packet.

7.Coordinator sends Short addr to EndDevice.

8.EndDevice returns a response packet.

9.EndDevice sends an application layer broadcast packet. The content of this packet is the long and short address of the device, which is used to notify the network of the correspondence between its long and short addresses. This data packet is of the application layer, that is, sent using AF_DataRequest, and the data packets of the previous steps are all of the link layer.

The structure of a normal packet

The data packet sent and received by the application layer consists of three parts:

1. MAC layer. This layer includes PAN ID, direct source address and destination address.

2. NWK layer. This layer includes indirect source and destination addresses.

3. APS layer. This layer includes source EndPoint, target EndPoint, Cluster ID, Profile ID and general data.

The following takes the data interaction in the case of multi-hop as an example to explain the meaning of direct address and indirect address.

Suppose there are three devices A, B, and C. The routing relationship is A->B->C. Now send a packet from device A to device C, the steps are as follows:

1.Route Request and Route Reply, determine the route.

2. A sends a data packet to B, the MAC layer address of the data packet is A->B, and the address of the NWK layer is A->C.

3.B determines according to the address of the NWK layer that this packet is not for itself, but for C, so it forwards a data packet. The MAC layer address of the data packet is B->C, and the NWK layer address is A->C.

4.C determines according to the address of the NWK layer that although this packet is sent by B, the source of the data is A.

Multi-hop networking test

1. Condition preparation

At least 3 devices can form a ZigBee network with a depth of 2.

2. Modify the configuration

In the default configuration, a Zigbee network node can mount a total of 20 devices, including 6 routing nodes. Therefore, if the configuration is not modified, many devices are required to simulate the multi-hop networking.

The modification steps are as follows:

1)

#define STACK_PROFILE_ID NETWORK_SPECIFIC

2)

Cskipchldrn array and CskipRtrs array in nwk_globals.c file. The values ​​of these arrays consist of MAX_CHILDREN and MAX_ROUTER.

MAX_CHILDREN determines the maximum number of child nodes that a router or a coordinator node can handle.

MAX_ROUTER determines the maximum number of routing-capable child nodes that a router or a coordinator node can handle. This parameter is a subset of MAX_CHILDREN, the end node uses (MAX_CHILDREN - MAX_ROUTER) the remaining address space.

refer to

TI ZigBee FAQ Frequently Asked Questions

http://www.deyisupport.com/question_answer/wireless_connectivity/zigbee/f/104/t/75525.aspx

Problems encountered in engineering practice and answers

NLME_PermitJoiningRequest

NLME_PermitJoiningRequest only cares whether the node allows other devices to join, but not the entire network. Therefore, when there are many multi-level networking or devices, not only the Permit of the coordinator needs to be opened, but also the Permit of the router below, otherwise, once the device and the coordinator cannot communicate directly, or the number of devices directly mounted by the coordinator has reached The maximum value will cause the device to fail to connect to the network. Similarly, when the device is withdrawn from the network, it is also necessary to turn off the Permit of the entire network. Otherwise, once the device is withdrawn from the network, if a network access request is sent, it will be added back.

Use of P2.1 and P2.2

P2.1 and P2.2 are special GPIOs. Since they are multiplexed with JTAG, they cannot be used as GPIO inputs in debug mode, but they work normally in normal mode.

Zigbee transfer speed

ZigBee resides on IEEE 802.15.4 transceivers, which in the 2.4 GHz space communicate at 250 kilobits per second (kbps), but by the time retries, encryption/decryption, and the fully acknowledged mesh protocol is applied, the actual through- put is closer to 25 kbps.

This is the statement of TI's official technical support, and the baud rate converted to the corresponding serial port is about 38400. That is to say, the serial port speed exceeding this speed cannot be handled by Zigbee devices.

ICE

When I was a graduate student, I studied middleware technologies such as CORBA, EJB, and COM. However, after work, there is no chance to use it again. I usually pay attention to it occasionally, but I only know that CORBA has never been popular. Under the siege of Struts, Hibernate, Spring and other frameworks, EJB has few users. Until recently, because the project required exposure to ZeroC's ICE framework.

The official website address of the ICE framework:

https://zeroc.com/downloads/ice

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325545072&siteId=291194637