Disclosure of Invention
In view of this, the present invention discloses a time synchronization method and apparatus for a wireless sensor network, so as to implement time synchronization of the wireless sensor network without increasing additional communication overhead.
A time synchronization method of a wireless sensor network is applied to a node to be accessed into the wireless sensor network, and comprises the following steps:
acquiring a broadcast DIO message in the wireless sensor network;
determining a target network node which sends the broadcast DIO message as an alternative father node, and sending a unicast DIO detection message to the alternative father node;
judging whether an ACK frame fed back by the alternative father node is received in a preset time period;
if the ACK frame is received, analyzing the ACK frame to obtain an ACK frame sequence number and a standard time stamp;
judging whether the ACK frame is an ACK feedback frame according to the ACK frame serial number, wherein the ACK feedback frame is an ACK frame of an MAC layer of the unicast DIO detection message;
and if the ACK frame is the ACK feedback frame, performing time synchronization according to the standard time stamp.
Optionally, the determining, as the alternative parent node, the network node that sends the broadcast DIO packet, and sending the unicast DIO probe packet to the alternative parent node specifically includes:
analyzing the broadcast DIO message to obtain an address field for sending the broadcast DIO message;
determining a target network node for sending the broadcast DIO message based on the address field, and determining the target network node as an alternative father node;
and sending a unicast DIO detection message to the alternative father node.
Optionally, the performing time synchronization according to the standard timestamp specifically includes:
adding the standard time stamp to a standard time stamp queue;
judging whether the alternative father node is the father node of the node to be accessed to the network or not according to a preset father node judgment standard;
when the alternative father node is the father node of the node to be networked, a linear regression algorithm is adopted for the standard timestamp queue to obtain a time synchronization offset;
correcting the standard timestamp by using the time synchronization offset to obtain network standard time;
and carrying out time synchronization according to the network standard time.
Alternatively, the time synchronization offset skew is calculated according to the following formula,
wherein N is the number of standard timestamps in the standard timestamp queue, i is the ith standard timestamp in the standard timestamp queue, and T is the number of standard timestamps in the standard timestamp queue
offset=T
send–T
arrive,T
sendFor ACK frame transmission time, T
arriveIn order for the ACK frame to be received time,
is T
offsetThe average value of (a) of (b),
is T
arriveIs measured.
Optionally, the network standard timestamp T is calculated according to the following formulaglobal,
In the formula, TlocalAnd the local time is the local time of the node to be networked.
A time synchronizer of a wireless sensor network is applied to a node to be accessed into the wireless sensor network, and comprises:
the message acquisition unit is used for acquiring a broadcast DIO message in the wireless sensor network;
a father node determining unit, configured to determine a target network node that sends the broadcast DIO packet as an alternative father node, and send a unicast DIO probe packet to the alternative father node;
the first judging unit is used for judging whether an ACK frame fed back by the alternative father node is received in a preset time period;
the analysis unit is used for analyzing the ACK frame to obtain an ACK frame serial number and a standard timestamp under the condition that the first judgment unit judges that the ACK frame is positive;
a second judging unit, configured to judge whether the ACK frame is an ACK feedback frame of an MAC layer of the unicast DIO detection packet according to the ACK frame sequence number;
and a time synchronization unit configured to perform time synchronization according to the standard timestamp if the second determination unit determines that the time stamp is included in the standard timestamp.
Optionally, the parent node determining unit is specifically configured to:
analyzing the broadcast DIO message to obtain an address field for sending the broadcast DIO message;
determining a target network node for sending the broadcast DIO message based on the address field, and determining the target network node as an alternative father node;
and sending a unicast DIO detection message to the alternative father node.
Optionally, the time synchronization unit is specifically configured to:
adding the standard time stamp to a standard time stamp queue;
judging whether the alternative father node is the father node of the node to be accessed to the network or not according to a preset father node judgment standard;
when the alternative father node is the father node of the node to be networked, a linear regression algorithm is adopted for the standard timestamp queue to obtain a time synchronization offset;
correcting the standard timestamp by using the time synchronization offset to obtain network standard time;
and carrying out time synchronization according to the network standard time.
Alternatively, the time synchronization offset skew is calculated according to the following formula,
wherein N is the number of standard timestamps in the standard timestamp queue, i is the ith standard timestamp in the standard timestamp queue, and T is the number of standard timestamps in the standard timestamp queue
offset=T
send–T
arrive,T
sendFor ACK frame transmission time, T
arriveIn order for the ACK frame to be received time,
is T
offsetThe average value of (a) of (b),
is T
arriveIs measured.
Optionally, the network standard timestamp T is calculated according to the following formulaglobal,
In the formula, TlocalAnd the local time is the local time of the node to be networked.
According to the technical scheme, the node to be networked acquires a broadcast DIO message in the wireless sensor network, a target network node which sends the broadcast DIO message is determined as an alternative father node, a unicast DIO detection message is sent to the alternative father node, when an ACK frame fed back by the alternative father node is received in a preset time period, the ACK frame is analyzed to obtain an ACK frame serial number and a standard timestamp, when the ACK frame is determined to be an ACK feedback frame according to the ACK frame serial number, the ACK feedback frame is an ACK frame of an MAC layer of the unicast DIO detection message, and time synchronization is carried out according to the standard timestamp. The invention embeds the one-way time synchronization method into the MAC layer confirmation mechanism of the wireless sensor network, encapsulates the standard time stamp into the ACK frame, realizes the transmission of the standard time stamp by utilizing the ACK confirmation mechanism of the MAC layer, has timeliness and does not relate to the processing delay of the upper layer of a network protocol stack, and sends the unicast DIO detection message to the alternative father node through the node to be accessed to trigger the time synchronization process, so that the whole time synchronization process does not generate extra communication overhead, can solve the problem of network congestion caused by extra communication, and is beneficial to the deployment of the high-density wireless sensor network.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The embodiment of the invention discloses a time synchronization method and a time synchronization device of a wireless sensor network.A node to be networked acquires a broadcast DIO message in the wireless sensor network, determines a target network node which sends the broadcast DIO message as an alternative father node, sends a unicast DIO detection message to the alternative father node, analyzes an ACK frame to obtain an ACK frame serial number and a standard timestamp when receiving an ACK frame fed back by the alternative father node in a preset time period, and performs time synchronization according to the standard timestamp when determining that the ACK frame is the ACK feedback frame according to the ACK frame serial number, wherein the ACK feedback frame is the ACK frame of an MAC layer of the unicast DIO detection message. The invention embeds the one-way time synchronization method into the MAC layer confirmation mechanism of the wireless sensor network, encapsulates the standard time stamp into the ACK frame, realizes the transmission of the standard time stamp by utilizing the ACK confirmation mechanism of the MAC layer, has timeliness and does not relate to the processing delay of the upper layer of a network protocol stack, and sends the unicast DIO detection message to the alternative father node through the node to be accessed to trigger the time synchronization process, so that the whole time synchronization process does not generate extra communication overhead, can solve the problem of network congestion caused by extra communication, and is beneficial to the deployment of the high-density wireless sensor network.
In order to understand the time synchronization process of the wireless sensor network, the invention first introduces a time synchronization application scenario of the wireless sensor network. Referring to fig. 1, a topology structure diagram of a wireless sensor network disclosed in the embodiment of the present invention is shown, where a node 1 is a CCO (Central Coordinator), and also indicates a root node in an RPL Protocol, and the RPL is an IPv6 Routing Protocol for Low-Power and Low network for short. The nodes 2 to 4 shown in fig. 1 are ordinary nodes that have joined the wireless sensor network, and the node 5 represents a node to be networked. The node 1 is connected with a plurality of common nodes through wireless channels, and in addition, all the nodes are mainly Single-Chip microcomputers (Single-Chip microcomputers) matched with a wireless sensor network, such as the CC13XX series developed by Texas instruments and Inc. in America.
Referring to fig. 2, a flowchart of a time synchronization method for a wireless sensor network disclosed in an embodiment of the present invention is applied to a node to be networked, such as the node 5 in fig. 1, which is to join the wireless sensor network, and the time synchronization method includes:
step S101, obtaining a broadcast DIO message in a wireless sensor network;
DIO (DODAG Information Object, DODAG representing a network fabric network Information Object).
For convenience of description, the present embodiment defines a network node to be joined to the wireless sensor network as a "node to be joined to the network".
In this embodiment, a node to be networked seeks to join a wireless sensor network, where the wireless sensor network is based on a network layer RPL protocol, and the node to be networked detects whether a broadcast DIO packet is sent out in the wireless sensor network on its own channel, and acquires the broadcast DIO packet when detecting the broadcast DIO packet. The broadcast DIO packet is a control packet for discovering a new node and maintaining a route.
For example, the node 5 to be networked in fig. 1 needs to join the wireless sensor network to obtain the broadcast DIO packet sent by the network node 4, and the node 5 to be networked and the network node 4 perform time synchronization interaction based on the broadcast DIO packet.
Step S102, determining a target network node which sends the broadcast DIO message as an alternative father node, and sending a unicast DIO detection message to the alternative father node;
in this embodiment, after receiving a broadcast DIO packet, a node to be networked parses the broadcast DIO packet to obtain an address field for sending the broadcast DIO packet, determines a target network node for sending the broadcast DIO packet based on the address field, and determines the target network node as an alternative parent node.
And the node to be accessed to the network sends a unicast DIO detection message to the alternative father node, wherein the unicast DIO detection message is a detection message selected by the RPL protocol father node based on the communication quality between the nodes. After the node to be networked sends the unicast DIO detection message in the network layer, based on the principle of the computer network protocol stack, the unicast DIO detection message will be transmitted in the form of a data frame in the MAC (Media Access Control) layer, and due to the acknowledgement mechanism of the MAC layer, the destination node needs to return an ACK (acknowledgement character) frame representing acknowledgement after receiving the data frame, so that after the node to be networked sends the unicast DIO detection message to the candidate parent node, it will wait for the candidate parent node to feed back an ACK frame.
Step S103, judging whether an ACK frame fed back by the alternative father node is received in a preset time period, if so, executing step S104;
and when the ACK frame fed back by the alternative father node is not received in the preset time period, returning to the step S102, and sending the unicast DIO detection message to the alternative father node again.
Step S104, analyzing the ACK frame to obtain an ACK frame sequence number and a standard time stamp;
the ACK frame sequence number is used to determine a data frame corresponding to the ACK frame, that is, to determine a unicast DIO probe packet corresponding to the ACK frame.
Step S105, judging whether the ACK frame is an ACK feedback frame according to the ACK frame sequence number, if so, executing step S106;
wherein, the ACK feedback frame is an ACK frame of the MAC layer of the unicast DIO detection packet, and when it is determined that the ACK frame is not an ACK feedback frame according to the ACK frame sequence number, the step S102 is returned to.
And step S106, carrying out time synchronization according to the standard time stamp.
In this embodiment, the node to be networked adjusts its own time according to the standard timestamp, thereby achieving time synchronization.
In summary, the invention discloses a time synchronization method of a wireless sensor network, a node to be accessed to the network acquires a broadcast DIO message in the wireless sensor network, determines a target network node sending the broadcast DIO message as an alternative father node, sends a unicast DIO detection message to the alternative father node, analyzes an ACK frame to obtain an ACK frame serial number and a standard timestamp when receiving an ACK frame fed back by the alternative father node in a preset time period, and performs time synchronization according to the standard timestamp when determining that the ACK frame is the ACK feedback frame, wherein the ACK feedback frame is the ACK frame of an MAC layer of the unicast DIO detection message. The invention embeds the one-way time synchronization method into the MAC layer confirmation mechanism of the wireless sensor network, encapsulates the standard time stamp into the ACK frame, realizes the transmission of the standard time stamp by utilizing the ACK confirmation mechanism of the MAC layer, has timeliness and does not relate to the processing delay of the upper layer of a network protocol stack, and sends the unicast DIO detection message to the alternative father node through the node to be accessed to trigger the time synchronization process, so that the whole time synchronization process does not generate extra communication overhead, can solve the problem of network congestion caused by extra communication, and is beneficial to the deployment of the high-density wireless sensor network.
In order to further improve the time synchronization precision of the wireless sensor network, the invention further calculates the time synchronization offset of the standard timestamp fed back by the alternative negative node.
Referring to fig. 3, a flowchart of a method for performing time synchronization according to a standard timestamp is disclosed in an embodiment of the present invention, where the method includes:
step S201, adding a standard timestamp into a standard timestamp queue;
step S202, judging whether the alternative father node is the father node of the node to be accessed to the network according to a preset father node judgment standard, and if so, executing step S108;
and when the alternative parent node is not the parent node of the node to be networked, returning to the step S101.
In practical application, the node to be networked calculates a routing metric value, such as hop count and expected transmission times, according to a preset objective function, and selects the node with the largest or smallest routing metric value as a parent node.
Step S203, obtaining time synchronization offset by adopting a linear regression algorithm to the standard timestamp queue;
when the number of the standard timestamps in the standard timestamp queue reaches a preset number N, for example, N is 8, a linear regression algorithm is used for the standard timestamp queue to obtain the time synchronization offset.
Of course, when the number of the standard timestamps in the standard timestamp queue does not reach the preset number, the time synchronization offset can also be obtained by adopting a linear regression algorithm for the standard timestamp queue.
The standard timestamp queue is a first-in-first-out queue.
Specifically, in practical application, all the standard timestamps in the standard timestamp queue are subjected to straight line fitting to obtain the straight line slope of a fitted straight line, and the time trend can be estimated through a predicted linear function based on the straight line slope so as to realize direct compensation of the standard timestamps.
It should be particularly noted that the time synchronization offset in this embodiment is a time synchronization offset between a node to be networked as a child node and a corresponding parent node.
Calculating the time synchronization offset skew according to the formula (1) and the formula (2), wherein the formula (1) and the formula (2) are as follows:
wherein N is the number of standard timestamps in the standard timestamp queue, i is the ith standard timestamp in the standard timestamp queue, and T
offset=T
send–T
arrive,T
sendFor ACK frame transmission time, T
arriveIn order for the ACK frame to be received time,
is T
offsetThe average value of (a) of (b),
is T
arriveMean value of (1), T
localIs the local time of the node to be networked, T
globalIs the network standard time.
Step S204, correcting the standard timestamp by using the time synchronization offset to obtain network standard time;
and step S205, performing time synchronization according to the network standard time.
In summary, the invention uses a first-in first-out timestamp queue to store the standard timestamps, obtains the time synchronization offset by adopting a linear regression algorithm to the standard timestamp queue, and obtains the network standard time by correcting the standard timestamps by using the time synchronization offset. The linear regression algorithm adopted by the invention has the advantage of high time synchronization precision, and the computational power of the network nodes can be borne.
Based on the above discussion, the time synchronization method of the wireless sensor disclosed in the present invention can be roughly divided into three stages, which are: a synchronization phase, a time synchronization interaction phase and a time synchronization offset calculation phase are started.
In the synchronization starting stage, if a node to be networked wants to access a wireless sensor network, negotiation needs to be performed through a network layer RPL protocol, once the node to be networked receives a broadcast DIO message of a certain network node in the wireless sensor network, the node to be networked starts to judge whether the network node sending the broadcast DIO message in the wireless sensor network is suitable for being used as a father node of the node, the network node sending the broadcast DIO message is determined to be an alternative father node, a unicast DIO detection message is sent to the alternative father node, the unicast DIO detection message can be used as trigger of time synchronization, and the time synchronization interaction stage is started at this moment.
In the time synchronization interaction stage, according to the principle of a computer network protocol stack, unicast DIO message transmission of a network layer is represented as data frame transmission at an MAC layer, according to an ACK (acknowledgement) mechanism of the MAC layer, if a node to be networked sends a data frame to an alternative father node, the node to be networked waits for the alternative father node to return an ACK frame acknowledgement to the alternative father node, and the ACK frame represents the successful transmission of the corresponding data frame.
In the time synchronization offset calculation stage, the node to be networked stores the standard time stamp received in the ACK frame for the last 8 times by maintaining a standard time stamp queue, for example, a standard time stamp queue with a length of 8, and performs a queuing operation when receiving a new time stamp. And finally, calculating the time synchronization offset of the time by adopting a linear regression algorithm for the standard timestamp queue, correcting the standard timestamp by utilizing the time synchronization offset to obtain network standard time, and carrying out time synchronization on the nodes to be accessed to the network according to the network standard time.
According to the invention, time synchronization is decoupled into three stages, so that the overall time synchronization precision is higher, the CPU calculation power of the sensor node is more suitable, and no additional communication cost is required.
Corresponding to the embodiment of the method, the invention also discloses a time synchronization device of the wireless sensor network.
Referring to fig. 4, a schematic structural diagram of a time synchronization apparatus for a wireless sensor network disclosed in an embodiment of the present invention is applied to a node to be accessed to a wireless sensor network, where the node to be accessed to the wireless sensor network is to be added to the time synchronization apparatus, and the time synchronization apparatus includes:
a message acquiring unit 301, configured to acquire a broadcast DIO message in the wireless sensor network;
for convenience of description, the present embodiment defines a network node to be joined to the wireless sensor network as a "node to be joined to the network".
In this embodiment, a node to be networked seeks to join a wireless sensor network, where the wireless sensor network is based on a network layer RPL protocol, and the node to be networked detects whether a broadcast DIO packet is sent out in the wireless sensor network on its own channel, and acquires the broadcast DIO packet when detecting the broadcast DIO packet. The broadcast DIO packet is a control packet for discovering a new node and maintaining a route.
For example, the node 5 to be networked in fig. 1 needs to join the wireless sensor network to obtain the broadcast DIO packet sent by the network node 4, and the node 5 to be networked and the network node 4 perform time synchronization interaction based on the broadcast DIO packet.
A parent node determining unit 302, configured to determine a target network node that sends the broadcast DIO packet as an alternative parent node, and send a unicast DIO probe packet to the alternative parent node;
in this embodiment, after receiving a broadcast DIO packet, a node to be networked parses the broadcast DIO packet to obtain an address field for sending the broadcast DIO packet, determines a target network node for sending the broadcast DIO packet based on the address field, and determines the target network node as an alternative parent node.
And the node to be accessed to the network sends a unicast DIO detection message to the alternative father node, wherein the unicast DIO detection message is a detection message selected by the RPL protocol father node based on the communication quality between the nodes. After the node to be networked sends the unicast DIO detection message in the network layer, based on the principle of the computer network protocol stack, the unicast DIO detection message will be transmitted in the form of a data frame in the MAC (Media Access Control) layer, and due to the acknowledgement mechanism of the MAC layer, the destination node needs to return an ACK (acknowledgement character) frame representing acknowledgement after receiving the data frame, so that after the node to be networked sends the unicast DIO detection message to the candidate parent node, it will wait for the candidate parent node to feed back an ACK frame.
A first judging unit 303, configured to judge whether an ACK frame fed back by the candidate parent node is received within a preset time period;
when the ACK frame fed back by the candidate parent node is not received within the preset time period, the node returns to the parent node determining unit 302, and sends the unicast DIO detection packet to the candidate parent node again.
An analyzing unit 304, configured to, if the first determining unit 303 determines that the ACK frame is received, analyze the ACK frame to obtain an ACK frame sequence number and a standard timestamp;
the ACK frame sequence number is used to determine a data frame corresponding to the ACK frame, that is, to determine a unicast DIO probe packet corresponding to the ACK frame.
A second determining unit 305, configured to determine whether the ACK frame is an ACK feedback frame according to the ACK frame sequence number, where the ACK feedback frame is an ACK frame of a MAC layer of the unicast DIO detection packet;
when the ACK frame is judged not to be the ACK feedback frame according to the ACK frame sequence number, the parent node determination unit 302 is returned.
A time synchronization unit 306, configured to perform time synchronization according to the standard timestamp if the second determination unit 305 determines that the time stamp is positive.
In this embodiment, the node to be networked adjusts its own time according to the standard timestamp, thereby achieving time synchronization.
In summary, the invention discloses a time synchronization device of a wireless sensor network, a node to be networked acquires a broadcast DIO message in the wireless sensor network, determines a target network node sending the broadcast DIO message as an alternative father node, sends a unicast DIO detection message to the alternative father node, analyzes an ACK frame to obtain an ACK frame serial number and a standard timestamp when receiving an ACK frame fed back by the alternative father node in a preset time period, and performs time synchronization according to the standard timestamp when determining that the ACK frame is the ACK feedback frame, wherein the ACK feedback frame is the ACK frame of an MAC layer of the unicast DIO detection message. The invention embeds the one-way time synchronization method into the MAC layer confirmation mechanism of the wireless sensor network, encapsulates the standard time stamp into the ACK frame, realizes the transmission of the standard time stamp by utilizing the ACK confirmation mechanism of the MAC layer, has timeliness and does not relate to the processing delay of the upper layer of a network protocol stack, and sends the unicast DIO detection message to the alternative father node through the node to be accessed to trigger the time synchronization process, so that the whole time synchronization process does not generate extra communication overhead, can solve the problem of network congestion caused by extra communication, and is beneficial to the deployment of the high-density wireless sensor network.
In order to further improve the time synchronization precision of the wireless sensor network, the invention further calculates the time synchronization offset of the standard timestamp fed back by the alternative negative node.
The time synchronization unit 306 is specifically configured to:
adding the standard time stamp to a standard time stamp queue;
judging whether the alternative father node is the father node of the node to be accessed to the network or not according to a preset father node judgment standard;
when the alternative father node is the father node of the node to be networked, a linear regression algorithm is adopted for the standard timestamp queue to obtain a time synchronization offset;
correcting the standard timestamp by using the time synchronization offset to obtain network standard time;
and carrying out time synchronization according to the network standard time.
In practical application, all standard timestamps in the standard timestamp queue are subjected to straight line fitting to obtain the straight line slope of a fitting straight line, and the time trend can be estimated through a predicted linear function based on the straight line slope so as to realize direct compensation of the standard timestamps.
It should be particularly noted that the time synchronization offset in this embodiment is a time synchronization offset between a node to be networked as a child node and a corresponding parent node.
Calculating the time synchronization offset skew according to the formula (1) and the formula (2), wherein the formula (1) and the formula (2) are as follows:
wherein N is the number of standard timestamps in the standard timestamp queue, i is the ith standard timestamp in the standard timestamp queue, and T
offset=T
send–T
arrive,T
sendFor ACK frame transmission time, T
arriveIn order for the ACK frame to be received time,
is T
offsetThe average value of (a) of (b),
is T
arriveMean value of (1), T
localIs the local time of the node to be networked, T
globalIs the network standard time.
To further optimize the above embodiment, the parent node determining unit 302 is specifically configured to:
analyzing the broadcast DIO message to obtain an address field for sending the broadcast DIO message;
determining a target network node for sending the broadcast DIO message based on the address field, and determining the target network node as an alternative father node;
and sending a unicast DIO detection message to the alternative father node.
In summary, the invention uses a first-in first-out timestamp queue to store the standard timestamps, obtains the time synchronization offset by adopting a linear regression algorithm to the standard timestamp queue, and obtains the network standard time by correcting the standard timestamps by using the time synchronization offset. The linear regression algorithm adopted by the invention has the advantage of high time synchronization precision, and the computational power of the network nodes can be borne.
It should be noted that, for the specific working principle of each component in the device embodiment, please refer to the corresponding part of the method embodiment, which is not described herein again.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.