Disclosure of Invention
The invention aims to overcome the defects in the traditional Zigbee networking communication technology, and aims to solve the technical problem of providing an improvement of a Zigbee device communication method which is applicable to a situation of dense uplink period, numerous terminals and high-frequency position mobile application.
In order to solve the technical problems, the technical scheme adopted by the invention is that the Zigbee device communication method based on beacon transmission and time slot allocation comprises the following steps:
s1, a router to be accessed to a network finishes registration through a device management platform of a server, a Zigbee gateway reads registration information of the router, receives a router access request and finishes router access to the network;
s2, the Zigbee gateway initiates route discovery requests to all registered routers one by one, each time route discovery determines a unique path, the router submits path information step by step according to the path and establishes a route linked list based on a B tree data structure, and beacon time slots are distributed to all sub-tree node routers of the B tree linked list through non-recursion first traversal of the B tree linked list;
S3, the Zigbee gateway generates a beacon, sends the beacon in a starting time slot of a beacon period, and a child node router receiving the beacon synchronizes own time information according to a time stamp in a beacon load and transmits a new beacon to a next-stage child node router in a time slot determined by the beacon load;
s4, the Zigbee terminal equipment is randomly distributed in the area covered by the router signal, receives the beacons transmitted by routers nearby the Zigbee terminal equipment, synchronizes the time information of the Zigbee terminal equipment according to the time stamp of the beacons, determines the transmission time slot of uplink data according to the equipment ID, broadcasts and transmits the uplink data in a time slot mode through the MAC layer interface, and the downlink data is buffered by the router and transmitted along with the beacon load, and reaches the target Zigbee terminal equipment along with the transmission of the beacons.
The device registration step of the router to be accessed in the step S1 is as follows:
the method comprises the steps that communication is established between a router to be accessed and an equipment management platform of a server, the equipment management platform reads a 64-bit MAC address of the router to be accessed, and a 16-bit network short address is designated for the router to be accessed to generate an equipment information table;
the device management platform transmits a device information table of the registered router to the Zigbee gateway, and the device information table is stored in a nonvolatile mode in the Zigbee gateway until the device is restored to factory setting;
After receiving the network access request of the router equipment, the Zigbee gateway compares the MAC addresses in the equipment information table, filters the network access request of the non-registered router, and completes the network joining process of the registered router.
The step of constructing the route linked list in the step S2 is as follows:
The Zigbee gateway initiates route discovery requests to all registered routers one by one through a route discovery function provided by a Z-Stack protocol Stack;
The target router receiving the route discovery request extracts a route discovery table in a Z-Stack protocol Stack, further obtains a network short address of a previous-stage routing node, and unicast-transmits path information containing the self node to the previous-stage routing node;
The router of the previous stage adds the received path information into a route linked list based on a B tree data structure, and gradually perfects the route linked list along with the route discovery process one by one until all path information taking the self node of each stage router as a root node is constructed;
Along with the step-by-step submission of the path information, the Zigbee gateway receives the path information of all the routing nodes in the system and establishes a routing chain table containing all the system routers.
The steps of beacon generation and transmission in the step S3 are as follows:
the Zigbee gateway distributes equipment IDs to all sub-tree node routers of the B-tree routing chain table according to the traversing sequence by traversing the non-recursion precedent sequence of the internal B-tree routing chain table, and the equipment IDs uniquely determine time slots of new beacon transmission moments generated by the sub-tree node routers;
the beacon frame load comprises a network short address and a device ID of a Zigbee gateway sub-node router, and also comprises a time stamp of the sending time;
after the Zigbee gateway generates a beacon, a 0 th beacon is sent in the initial time slot of a beacon period, the beacon is received by a child node router of the Zigbee gateway, and the child node router receiving the beacon sequentially performs the following operations:
① Synchronizing self-time information according to the time stamp in the beacon payload;
② Determining a sending time slot of a new beacon according to the equipment ID corresponding to the own network short address;
③ Then, through traversing the non-recursion first order of the internal B-tree routing chain table, beacon time slots are distributed to all sub-tree node routers of the B-tree routing chain table according to the traversing order, and a new beacon is generated;
④ The new beacon is sent in the sending time slot determined by the device ID and is received by the next level sub-node router;
Similarly, beacons are delivered layer by all nodes in the B-tree routing chain table until the endmost router node.
One beacon period is 41943mS, namely 65536 x2 MacTimer periods, divided into 32 communication periods, one communication period 1310mS, each communication period is divided into 256 time slots, and each time slot is 5.12mS, namely 16 MacTimer periods;
The first 2 slots (slot id=0-1) of each communication cycle are used for beacon transmission, the next 2 slots (slot id=2-3) are idle for standby, the next 250 slots (slot id=4-253) are used for uplink data communication, and the last 2 slots (slot id=254-255) are idle for standby.
The step of determining the uplink data slot of the Zigbee terminal device in step S4 is as follows:
the uplink data time slot of the Zigbee terminal device is determined by a dynamic device ID distributed to the Zigbee terminal device by a sign-in router, the dynamic device ID value is 0-249, and the corresponding time slot ID=4-253;
in a time period, a batch of Zigbee terminal devices establish uplink communication with a check-in router in a competitive manner, a migration request is sent, dynamic device IDs are sequentially and incrementally distributed from 0 to 249 in the sequence of receiving data packets by the check-in router, the distributed device IDs are in an active state, and when all available device IDs are in an active state, newly migrated devices are refused to migrate;
in the next time period, the last group of Zigbee terminal devices sequentially send an migration request, the next group of Zigbee terminal devices sequentially send an migration request, the device ID of the migration device is changed from an active state to an inactive state, and the device ID of the inactive state is dynamically allocated to the migration device, thereby implementing dynamic allocation of an uplink timeslot.
The Zigbee device communication system based on beacon transmission and time slot allocation comprises a server, a Zigbee gateway, a Zigbee router, a Zigbee sign-in router and Zigbee terminal devices;
The server is used for equipment management, equipment data display and man-machine interaction;
The Zigbee gateway establishes wired or wireless serial port or network connection with the server, and is used for establishing a Zigbee network, storing and managing a route discovery function and a device information table, generating a beacon and distributing a beacon time slot;
The Zigbee router establishes wired or wireless serial port or network connection with the server and is used for submitting path information step by step, managing a lower-level route linked list, transmitting a beacon, receiving uplink data of Zigbee terminal equipment and caching and sending downlink data;
the Zigbee sign-in router establishes communication with an upper computer, does not participate in beacon transmission, and is used for generating a dynamic ID of Zigbee terminal equipment;
and the Zigbee terminal equipment is used for acquiring, caching and sending the uplink data, receiving the downlink data in the beacon load and executing the downlink command.
The server adopts a single machine device with RS-232, RS-485, USB and network port communication interfaces or a network server connected with the Internet.
The Zigbee gateway and the Zigbee router are respectively provided with one or more of communication interfaces such as RS-232, RS-485, USB, network ports and the like.
Compared with the prior art, the method for communication of the Zigbee equipment based on beacon transmission and time slot allocation has the advantages that the novel beacon transmission algorithm and time slot allocation strategy are adopted, so that the bandwidth utilization rate of Zigbee signals is effectively improved, the uplink concurrency of terminal equipment is increased, and the Zigbee network can be suitable for industrial environments requiring higher data stability and instantaneity.
Detailed Description
As shown in fig. 1to 9, in order to overcome the defects of the conventional Zigbee networking communication technology, the present invention provides a Zigbee device communication method based on a beacon transmission algorithm and a slot allocation policy, where the method includes the following steps:
the router to be accessed to the network finishes registration through the equipment management platform, the Zigbee gateway reads registration information, receives a router access request and finishes equipment access;
The Zigbee gateway initiates route discovery requests to all registered routing devices one by one, routers submit path information step by step and establish a routing chain table based on a B tree data structure, and each level of router distributes beacon time slots to all sub-tree node routers of the Zigbee gateway through non-recursion preface traversal of the B tree chain table;
The Zigbee gateway generates a beacon and sends the beacon in the initial time slot of a beacon period, and a child node router receiving the beacon synchronizes own time information according to a time stamp in a beacon load and transmits a new beacon to the child node router of the child node router in the time slot determined by the beacon load;
The Zigbee terminal devices are randomly distributed in the area within the signal coverage of the router, receive beacons sent by nearby router devices, synchronize self time information according to the time stamp of the beacons, determine the sending time slot of uplink data according to the dynamic device ID of the beacons, broadcast and send the uplink data in a time slot mode through an MAC layer interface, and the downlink data is cached by the router and is sent together with the beacon load, and reaches the target terminal device along with the transmission of the beacons.
In one embodiment, the device registration method of the router to be logged in, see fig. 2, includes:
the method comprises the steps that communication is established between a router to be accessed and an equipment management platform of a server, the equipment management platform reads a 64-bit MAC address of the router to be accessed, and a 16-bit network short address is designated for the router to be accessed to generate an equipment information table;
the device management platform transmits a device information table of the registered router to the Zigbee gateway, and the device information table is stored in a non-volatile mode in the gateway until the device is restored to factory setting;
after receiving the network access request of the router device, the Zigbee gateway compares the MAC addresses in the device information table, filters the network access request of the non-registered device, and completes the network joining process of the registered router device.
It should be specifically noted that, in the present invention, only the router device performs the network access operation, and the router joins the network established by the Zigbee gateway as a precondition for the subsequent route discovery process;
The terminal equipment communicates uplink data through the MAC layer interface of the Z-stack protocol, and does not execute network access operation, so that occupation of network layer data generated in the network access stage by a router under the condition of high-frequency position movement can be avoided, the certainty of uplink data time slot allocation is ensured, and channel conflict in the network is strictly avoided.
In one embodiment, the method for constructing the route linked list, see fig. 3, includes:
The Zigbee gateway initiates route discovery requests to all registered routing devices one by one through a route discovery function provided by a Z-Stack protocol Stack;
the target router receiving the route discovery request extracts a route discovery table in the Z-Stack protocol Stack to further obtain a network short address of a route node at the upper level, and unicast transmits route information containing the self node to the route node at the upper level;
The upper-level routing equipment adds the received path information into a routing chain table based on a B-tree data structure, and the routing chain table is gradually perfected along with the route discovery process one by one until all path information taking own node as a root node is constructed;
Along with the gradual submission of the path information, the Zigbee gateway can receive the path information of all the routing nodes in the system and establish a routing chain table containing the routing equipment of the whole system.
It should be noted that constructing a route link table is a precondition for the generation and delivery of the beacon. The beacon transmission algorithm based on the non-recursion preface traversal of the B-tree data structure can enable the beacon to be transmitted in a unique time slot in a non-competing mode, obviously reduces the time window of receiving the beacon by the terminal equipment, and reduces the power consumption of the terminal equipment.
In one embodiment, the method of generating and delivering beacons, see fig. 4, includes:
the Zigbee gateway and other routers have built a routing chain table based on a B tree data structure with own node as a root node, and equipment IDs are distributed to the router equipment according to the traversing sequence by a non-recursion first-order traversing algorithm, wherein the equipment IDs are the basis for distributing beacon time slots to each router equipment;
For a gateway or router, its neighboring routing node is its child node, and its generated beacon frame payload contains the network addresses and device IDs of its own node and all child nodes, and the timestamp of the beacon transmission time;
after generating a beacon, the Zigbee gateway transmits a 0 th beacon in a starting time slot of a beacon period, and the beacon is accepted by a child node router of the Zigbee gateway;
The child node receiving the beacon firstly synchronizes own time information according to the time stamp in the beacon load, then traverses all sub-tree router nodes under the root node based on the equipment ID of the own node, and distributes the equipment ID to the router equipment according to the traversing sequence;
next, the above-mentioned child node adds the device information of its child node to the payload of its new beacon;
Then, the child node calculates the sending time slot of the new beacon according to the device ID of the self node in the beacon load, updates the time stamp of the new beacon, and then sends the new beacon in the new time slot;
Similarly, beacons are delivered layer by all nodes in the B-tree routing chain table until the endmost router node.
In one embodiment, the definition of the beacon period, see fig. 5-6, includes:
One beacon period is 41943mS (65536 x 2 MacTimer periods), divided into 32 communication periods, one communication period 1310mS, each communication period being divided into 256 time slots, each time slot being 5.12mS (16 MacTimer periods);
One beacon period may also include more communication periods, so that the maximum number of routers supported in the system is increased, and one communication period may also include more time slots, so that the maximum number of terminals in the same time period supported in the system is increased, but at the same time, lengthening the beacon period may put a higher requirement on the accuracy of the real-time clock crystal oscillator of the routers.
The invention can be used for a sensor data acquisition system based on Zigbee wireless transmission in industrial occasions, and the minimum acquisition period is 1.31S. The invention aims to apply the Zigbee system in industrial occasions, in order to reduce the uncertainty of data delay and wireless channel occupation caused by a Zigbee multi-hop mode, a Zigbee gateway and a Zigbee router are connected with an Internet network which is in wired or wireless connection with a server on hardware, and Zigbee data of terminal equipment are uploaded to the server nearby through the Zigbee router, which is a precondition for the system composition of the invention and a precondition for the basic method of the invention.
The Zigbee terminal device does not make a network access request after power-on, and data via it is all sent or received through the MAC layer interface, which is also a precondition of the basic method of the present invention.
1. Transmission method for data frame
The transmission of the path information is transmitted and received through the related program interfaces of the AF layer or the ZCL layer of the Z-Stack protocol Stack;
The beacon frame and the uplink data packet are transmitted without passing through the AF layer or the ZCL layer of the Z-Stack, but the MAC layer data request interface provided by the Z-Stack is transmitted by adopting a transmission function of a time slot version, and the data frame is extracted by utilizing DataIndicationEvent events in the MAC layer event callback interface provided by the Z-Stack.
2. Method for synchronizing self time information according to beacon
Beacons are transmitted using a transmission function of the slot version, so beacons are always transmitted when macTimer count value is 0. After the device receives the beacon, macTimer count value is adjusted to be the beacon frame air transmission time, and the timestamp is adjusted to be the value of the beacon frame timestamp.
3. As for a method of constructing the route link table, the following is described with specific examples, referring to fig. 7:
the network short address Addr of the router is distributed by the equipment management platform in the equipment registration link, so that the router is distributed in batches in a specific embodiment for facilitating system debugging;
① The first batch is laid out with gateway, addr=0x0001, addr=0x0003, addr=0x0004, addr=0x0006;
② The gateway initiates route discovery for addr=0x0004, route discovery requests are routed along addr=0x0000, addr=0x0001, addr=0x0004 paths to addr=0x0004;
③ The path information 0x0004 is submitted to addr=0x0001 by addr=0x0004, addr=0x0001 adds a new child node addr=0x0004 under its own node;
④ The path information 0×0001×0004 is submitted to addr=0x0000 by addr=0x0004, addr=0x0000 adds a new child node addr=0x0001 under its own node, and adds a new child node addr=0x0004 under the node addr=0x0001;
⑤ The gateway initiates route discovery for addr=0x0003, the route discovery request is routed along addr=0x0000, addr=0x0001, addr=0x0003 paths to addr=0x0003;
⑥ The path information 0x0003 is submitted to addr=0x0001 by addr=0x0003, addr=0x0001 adds a new child node addr=0x0003 under its own node;
⑦ The path information 0x0001 x0003 is submitted to addr=0x0000 by addr=0x0003, addr=0x0000 adds a new child node addr=0x0003 under the node addr=0x0001;
⑧ The gateway initiates route discovery for addr=0x0006, the route discovery request is routed along addr=0x0000, addr=0x0001, addr=0x0004, addr=0x0006 to addr=0x0006;
⑨ The path information 0x0006 is submitted to addr=0x0004 by addr=0x0006, addr=0x0004 adds a new child node addr=0x0006 under its own node;
⑩ The path information 0x0004 x0006 is submitted to addr=0x0001 by addr=0x0004, addr=0x0001 adds a new child node addr=0x0006 at the node of addr=0x0004;
11. The path information 0x0001 0x0004 0x0006 is submitted to addr=0x0000 by addr=0x0000, where addr=0x0000 adds a new child node addr=0x0006 at the node addr=0x0004;
the steps are the process that the route information is submitted step by step and the route table is gradually perfected.
Specifically, as in fig. 7, initiating route discovery for addr=0x0008 with path 0x0002 0x0005 0x0007 already committed, a path 0x000B 0x0005 0x0008 is formed, possibly due to the link cost of path 0x00020x0005 suddenly rising due to environmental changes;
for the above case, it is necessary to perform route discovery for addr=0x0005 multiple times, select the route with the largest occurrence, and update the route information of addr=0x0007 and addr=0x0008.
4. Regarding the generation of the non-recursive preorder traversal algorithm and the device ID, the following is described with specific examples, see fig. 8:
adding an index for recording a child node currently searched by a current node and a parent node pointer into a conventional B tree node structure body so as to realize backtracking of a search path, wherein the search path of a recursive operation can be realized without a recursive operation;
① The function loop body enters a father node (equipment ID=0), searching is always started from the child node (equipment ID=1) with the minimum Index value, the Index value (index=0) of the child node currently searched is stored in the node structure body in real time, and the equipment ID value (ID=1) of the node is increased along with the searching path;
② If the current child node (equipment id=2) does not have a child node of the current child node, assigning a value (id=2) to the equipment ID of the current child node, and then tracing back to the parent node (equipment id=1) of the current child node by using a parent node pointer in the node structure;
③ The function loop body enters a father node (equipment ID=1), and adds 1 (index=1) to an Index value (index=0) of a child node in the node structure body to search for the next child node (equipment ID=3);
④ When the Index value (index=2) of the child node in the parent node (device id=1) structure reaches the child node number value (count=2), borrowing the parent node pointer in the node structure to trace back to the parent node of the node (device id=0);
⑤ The function loop body enters a father node (equipment id=0), and adds 1 (index=1) to the Index value (index=0) of the child node in the node structure body to search for the next child node (equipment id=7);
Assigning a device ID to each node in the traversal order of the algorithm establishes a unique time slot within the beacon period for the beacons delivered by the system-wide routers.
5. Regarding the generation and delivery of beacons, the following is described in specific examples, see fig. 8:
① The Zibee gateway traverses the B tree linked list to generate the equipment ID of each subtree node;
② The Zibee gateway transmits an initial beacon in the [0, 0] time slot, the beacon identification is agreed to be [0, 0], [0, 0] represents the 0 th time slot in the 0 th communication cycle. Obviously, in one embodiment of the present invention, only the 0 th slot and the 1 st slot are used for the transmission of the beacon in each communication cycle;
③ The beacon load of [0, 0] contains the equipment information of the own node and 3 sub-node routers thereof, wherein the 3 sub-node routers are ID=1, ID=7 and ID=14 as shown in figure 8, and the 3 sub-nodes can simultaneously receive the beacon of [0, 0] because of being in the radio frequency signal coverage range of the Zibee gateway;
④ After receiving the [0, 0] beacon, the router with ID=1 synchronizes the self time stamp to 0x0000, traverses the B tree linked list taking the self node as the root node, generates the device ID of each sub tree node router, and generates a new beacon [0, 1];
⑤ The router with id=1 transmits a new beacon [0, 1], [0, 1] beacon with a timestamp of 0x0001 in the [0, 1] slot, which can be received simultaneously by the 2 child node routers below it, as in fig. 8 with id=2 and id=3, respectively;
⑥ After receiving the [0, 1] beacon, the router with id=2 synchronizes the self time stamp to 0x0001, and transmits a new beacon [1, 0] in the [1, 0] time slot, and the time stamp 0x0100 of the [1, 0] beacon, wherein the MAC layer data frame of the [1, 0] beacon is possibly received by the router nodes nearby because of no child node of the self node, but is not processed because the load does not contain child node information;
⑦ The router with id=3 transmits a new beacon [1, 1] in the [1, 1] slot, and the timestamp of the [1, 1] beacon is 0x0101;
⑧ The router with ID=7 transmits a new beacon [3, 1] in the [3, 1] time slot, wherein the timestamp of the [3, 1] beacon is 0x0301;
And so on until the beacon transmission is finished, entering the next beacon period, and sending a [0, 0] beacon by the Zigbee gateway, wherein the timestamp of the [0, 0] beacon is 0x2000.
The specific structure of the invention needs to be described, the connection relation between the component modules adopted by the invention is definite and realizable, the specific connection relation can bring corresponding technical effects except the specific description in the embodiment, the types and connection modes of the components, the modules and the specific components in the invention belong to the prior art such as the published patent, the published journal paper or the common sense which can be obtained by the person skilled in the art before the application date, and the technical scheme provided by the scheme is clear, complete and realizable, and the corresponding entity products can be reproduced or obtained according to the technical means.
It should be noted that the above embodiments are merely for illustrating the technical solution of the present invention and not for limiting the same, and although the present invention has been described in detail with reference to the above embodiments, it should be understood by those skilled in the art that the technical solution described in the above embodiments may be modified or some or all of the technical features may be equivalently replaced, and these modifications or substitutions do not make the essence of the corresponding technical solution deviate from the scope of the technical solution of the embodiments of the present invention.