Time synchronization method, device and system of master device and slave device, computer device and storage medium

By generating and broadcasting a world time reference by the master device and combining it with the local time of the slave device to calculate the system time, the problem of insufficient time synchronization accuracy in short-range wireless communication networks is solved, and high-precision clock synchronization is achieved.

CN121397706APending Publication Date: 2026-01-23VERISILICON MICROELECTRONICS (SHANGHAI) CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511618362.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-06
Publication Date
2026-01-23

AI Technical Summary

Technical Problem

In short-range wireless communication networks, insufficient time synchronization accuracy between devices leads to millisecond-level errors in clock synchronization. These errors gradually increase over time, affecting the efficient operation of the system.

Method used

The master device generates a first reference time based on world time and transmits it to the slave device via broadcast packets. The system time is then calculated by combining the slave device's local time to achieve time synchronization.

Benefits of technology

Taking broadcast delay into account, the system time of the slave device is accurately calculated, which improves the clock synchronization accuracy, reduces the time difference between devices, and is suitable for multi-device synchronization scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121397706A_ABST
    Figure CN121397706A_ABST
Patent Text Reader

Abstract

The invention provides a time synchronization method, device and system of a master device and a slave device, computer equipment and a storage medium, and relates to the technical field of wireless transmission, the master device sends a first broadcast packet to the slave device, the first broadcast packet is sent only once, and therefore it is ensured that when the time difference between the master device and the slave device is calculated, the time difference between the master device and the slave device is calculated. The time difference is corresponding to receiving and transmitting of the same broadcast packet, and when the propagation time of electromagnetic waves between two devices is ignored, the time related to the time difference corresponds to the same world time, so that the system time of the slave device can be accurately calculated; the clock synchronization updating between the master device and the slave device can be completed under the condition of considering broadcast delay.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of wireless transmission, and in particular to a master-slave device time synchronization method, device, system, computer device and storage medium. BACKGROUND

[0002] In a short-range wireless communication network, data exchange and cooperative work between various nodes of the system usually need to be carried out through wireless signals. In order to ensure efficient operation of the system, especially in application scenarios such as industrial Internet, collaborative robots, wireless sensing control, and positioning and synchronization, the nodes must share a unified time reference. This time reference is the key to realizing precise time-slotted communication, cooperative sampling and control loop.

[0003] Traditional networking solutions often rely on broadcast messages and relay nodes to forward messages to cover slave devices in a multi-hop topology. However, the above networking solutions introduce various uncontrollable delays when transmitting the synchronization reference, resulting in millisecond-level errors in clock synchronization between devices. As time increases, the error gradually increases, resulting in insufficient synchronization accuracy. SUMMARY

[0004] The purpose of the present application is to provide a master-slave device time synchronization method, device, system, computer device and storage medium to overcome the lack of time synchronization accuracy between devices in a short-range wireless network.

[0005] In a first aspect, the present application provides a master-slave device time synchronization method, the method comprising: scanning a first broadcast packet sent by a master device in a short-range wireless communication network, and parsing the first broadcast packet to obtain a first reference time; wherein the first reference time is generated based on world time; scanning a second broadcast packet sent by the master device, and parsing the second broadcast packet to obtain a second reference time associated with the first reference time; obtaining a third reference time of itself; and calculating a system time of itself based on the first reference time, the second reference time and the third reference time to synchronize with the time of the master device.

[0006] In one embodiment, when the short-range wireless communication network is a Bluetooth Low Energy mesh network, the first broadcast packet is scanned based on a Bluetooth extended broadcast mode.

[0007] In one embodiment, the method further comprises: when the first broadcast packet is scanned, recording the local time of the device at this time as a first time; and when the second broadcast packet is parsed to obtain the second reference time, recording the local time of the device at this time as a second time; and the first time and the second time constitute the third reference time of the device. In one of the embodiments, the first reference time comprises a world time and a local time of the master device; the second reference time comprises a sending time of the master device sending the first broadcast packet; and the calculation of the system time of the slave device according to the first reference time, the second reference time and the third reference time comprises: calculating a first difference between the sending time of the first broadcast packet and the local time of the master device; calculating a second difference between the second time and the first time; and summing the world time, the first difference and the second difference to obtain the system time of the slave device.

[0008] In a second aspect, the application provides a time synchronization device of master-slave devices, which comprises: a scanning module, configured to scan a first broadcast packet sent by a master device in a short-distance wireless communication network; and an analyzing module, configured to analyze the first broadcast packet to obtain a first reference time; wherein the first reference time is generated based on a world time; the scanning module is further configured to scan a second broadcast packet sent by the master device; the analyzing module is further configured to analyze the second broadcast packet to obtain a second reference time associated with the first reference time; and obtain a third reference time of the slave device; and the analyzing module is further configured to calculate a system time of the slave device according to the first reference time, the second reference time and the third reference time, so as to synchronize the time with the master device.

[0009] In a third aspect, the application further provides a time synchronization method of master-slave devices, which comprises: generating a first reference time based on a world time, and packaging the first reference time into a first broadcast packet to publish in a short-distance wireless communication network; packaging a second reference time associated with the first reference time into a second broadcast packet to publish, so as to enable a slave device in the short-distance wireless communication network to calculate a system time of the slave device according to the first reference time, the second reference time and a third reference time of the slave device, and complete time synchronization.

[0010] In a fourth aspect, the application further provides a time synchronization device of master-slave devices, which comprises: a processing module, configured to generate a first reference time based on a world time and package the first reference time into a first broadcast packet; and a transmission module, configured to publish the first broadcast packet in a short-distance wireless communication network; the processing module is further configured to obtain a second reference time associated with the first reference time and package the second reference time into a second broadcast packet; and the transmission module is further configured to publish the second reference time in the short-distance wireless communication network, so as to enable a slave device in the short-distance wireless communication network to calculate a system time of the slave device according to the first reference time, the second reference time and a third reference time of the slave device, and complete time synchronization.

[0011] In a fifth aspect, the application further provides a time synchronization method of master-slave devices, which comprises: a master device generating a first reference time based on a world time, packing the first reference time into a first broadcast packet, and publishing the first broadcast packet in a short-range wireless communication network; a slave device scanning and analyzing the first broadcast packet to obtain the first reference time; the master device obtaining a second reference time associated with the first reference time, packing the second reference time into a second broadcast packet, and publishing the second broadcast packet in the short-range wireless communication network; the slave device scanning and analyzing the second broadcast packet to obtain the second reference time; and the slave device obtaining a third reference time of itself, and calculating a system time of itself according to the first reference time, the second reference time and the third reference time, so as to synchronize the time with the master device.

[0012] In one of the embodiments, the method further comprises: the master device periodically generating the first broadcast packet and the second broadcast packet based on the world time, and publishing the first broadcast packet and the second broadcast packet in the short-range wireless communication network, so that the slave device periodically synchronizes the time with the master device according to the first broadcast packet and the second broadcast packet.

[0013] In a sixth aspect, the application further provides a time synchronization system of devices in a network, which comprises: a master device configured to generate a first reference time based on a world time, pack the first reference time into a first broadcast packet, and publish the first broadcast packet in a short-range wireless communication network; at least one slave device configured to scan and analyze the first broadcast packet to obtain the first reference time; the master device is further configured to obtain a second reference time associated with the first reference time, pack the second reference time into a second broadcast packet, and publish the second broadcast packet in the short-range wireless communication network; each of the slave devices is further configured to scan and analyze the second broadcast packet to obtain the second reference time, obtain a third reference time of itself, and calculate a system time of itself according to the first reference time, the second reference time and the third reference time, so as to synchronize the time with the master device.

[0014] In a seventh aspect, the application further provides a computer device. The computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the method steps in the first aspect, or the third aspect or the fifth aspect when executing the computer program.

[0015] In an eighth aspect, the application further provides a computer readable storage medium. The computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method steps in the first aspect, or the third aspect or the fifth aspect.

[0016] The above-mentioned time synchronization method, device, system, computer device and storage medium of master-slave devices have at least the following advantages: The master device of the application sends a first broadcast packet to the slave device, and the first broadcast packet is sent only once, so as to ensure that the transmission and reception of the same broadcast packet are corresponding when calculating the time difference between the master device and the slave device, and the time involved in the above-mentioned time difference corresponds to the same world time when the propagation time of electromagnetic waves between the two devices is negligible, so that the system time of the slave device can be accurately calculated, and the clock synchronization update between the master device and the slave device can be completed under the condition of considering the broadcast delay. BRIEF DESCRIPTION OF DRAWINGS

[0017] Figure 1 A flowchart of a time synchronization method of a master device and a slave device in an embodiment; Figure 2 A block diagram of a time synchronization device of a master device and a slave device in an embodiment; Figure 3 A flowchart of a time synchronization method of a master device and a slave device in another embodiment; Figure 4 A block diagram of a time synchronization device of a master device and a slave device in another embodiment; Figure 5 A flowchart of a time synchronization method of a master device and a slave device in another embodiment; Figure 6 An internal structure diagram of a computer device in an embodiment. DETAILED DESCRIPTION

[0018] The embodiments of the present application will be described in detail with specific reference to the drawings. The skilled in the art can easily understand other advantages and effects of the present application from the content disclosed in the specification. The present application can also be implemented or applied in other different specific embodiments, and the details in the specification can be modified or changed based on different views and applications without departing from the spirit of the present application. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.

[0019] Some exemplary embodiments of the present application are described for illustrative purposes, and it should be understood that the present application can be implemented in other ways not specifically shown in the drawings.

[0020] Please refer to Figure 1 The embodiment of the application provides a time synchronization method of a master device and a slave device, which is suitable for a slave device in a short-distance wireless communication network, and comprises the following steps: In step 102, a first broadcast packet sent by a master device in a short-distance wireless communication network is scanned, and a first reference time is obtained by analyzing the first broadcast packet. The first reference time is generated based on world time.

[0021] Specifically, the short-range wireless communication network refers to a distributed network system based on wireless transmission technology, with a coverage range usually within hundreds of meters. Such a network has characteristics such as dense node deployment and low-power operation, and is widely used in industrial automation, smart home, and other fields.

[0022] Optionally, the short-range wireless communication network includes a Bluetooth Low Energy Mesh (BLE Mesh), a ZigBee network, and a WIFI network, etc.

[0023] Specifically, the BLE Mesh network is a wireless communication protocol based on Bluetooth Low Energy (BLE) technology, designed for large-scale device networking and many-to-many communication scenarios. It realizes interconnection and intercommunication between devices through mesh topology, solving the problems of limited coverage and low device capacity of traditional BLE point-to-point or star network. ZigBee network is a low-power, low-rate, short-range wireless communication technology based on IEEE 802.15.4 standard, suitable for scenarios that require long-time operation, low power consumption, and data exchange within a limited range. WiFi (Wireless Fidelity) usually refers to the wireless local area network (WLAN) technology based on IEEE 802.11 standard, designed for short-range, high-speed wireless data transmission.

[0024] The devices in the short-range wireless communication network are called nodes, and the nodes can use broadcast mode to transmit data. Among them, the master device refers to the source node responsible for publishing control information and service data on a designated broadcast channel, the slave device refers to the ordinary node in a passive receiving state, continuously scanning a specific channel, and the slave device with forwarding capability can be used as a relay node. The master device periodically or on demand publishes data to the short-range wireless communication network on a specific channel. Each slave device continuously scans and, after capturing the broadcast packet in the specific channel, parses and processes the data carried by the broadcast packet. If it needs to be executed locally, it is directly processed; if it needs to be replied, it replies to the master device; if it needs to be forwarded, it is diffused to a farther range through a relay node, thereby realizing the full-network coverage of messages in a connectionless state.

[0025] World Time (TAI), also known as International Atomic Time, is a time standard based on atomic clocks, mainly used for scientific research, technical applications, and high-precision timing. The first reference time is generated by the master device based on TAI time, which is used to represent the current system time of the master device. This system time will be used as a reference to synchronize the time of the slave device.

[0026] In the embodiment, the short-range wireless communication network is provided with one master device and at least one slave device. At a certain moment, the master device generates a first reference time based on the current TAI time, packs the first reference time into a first broadcast packet, and publishes the first broadcast packet on the short-range wireless communication network through a specific channel for scanning by the slave device. If a slave device A scans the first broadcast packet, the first reference time is obtained by analyzing the first broadcast packet. Further, the slave device can be any one or more of the short-range wireless communication network, i.e., the master device can synchronize the time with one slave device or simultaneously synchronize the time with multiple slave devices. In addition, the slave device can also be all devices in a device group, so that the master device can simultaneously synchronize the time with all devices in the device group.

[0027] At step 104, the second broadcast packet sent by the master device is scanned, and the second reference time associated with the first reference time is obtained by analyzing the second broadcast packet.

[0028] Specifically, the second reference time refers to the sending time of the first broadcast packet, which is used to calculate the time difference between the generation of the first broadcast packet by the master device based on the first reference time and the sending. The master device packs the time difference and publishes it on the short-range wireless communication network through a specific channel for scanning by the slave device. After scanning the first broadcast packet, the slave device A continues to scan the specific channel, and if the second broadcast packet is scanned, the second reference time is obtained by analyzing the second broadcast packet.

[0029] Further, the master device is used to publish the first broadcast packet and the second broadcast packet on the specific channel of the short-range wireless communication network, and the slave device is used to scan the first broadcast packet and the second broadcast packet on the specific channel. In the present application, the master device and the slave device do not need to transmit messages in both directions, and the time synchronization can be completed. When the number of devices to be synchronized in the network is large, this will greatly improve the speed of clock synchronization.

[0030] At step 106, the third reference time of the slave device is obtained.

[0031] Specifically, the third reference time is the system time of the slave device. It should be understood that each slave device has a local clock, and the difference between the first reference time and the second reference time received by the slave device can be determined by the system time of the slave device.

[0032] At step 108, the system time of the slave device is calculated based on the first reference time, the second reference time, and the third reference time, so as to synchronize the time with the master device.

[0033] Specifically, the slave device calculates a new time based on the reference time provided by the master device and the time difference between the data interaction of the master device and the slave device, and takes the new time as the system time of the slave device at this time, so as to realize synchronization with the master device.

[0034] The time synchronization method of the master-slave device, the master device sends a first broadcast packet to the slave device, the first broadcast packet is sent only once, so as to ensure that the transmission and reception correspond to the same broadcast packet when calculating the time difference between the master device and the slave device, in the application scenario of the short-distance wireless communication network, the propagation time of electromagnetic waves between the two devices can be ignored, the time involved in the above-mentioned time difference corresponds to the same world time, the system time of the slave device can be accurately calculated, and the clock synchronization update between the master device and the slave device can be completed under the condition of considering the broadcast delay; further, the time synchronization can be completed without bidirectional message transmission between the master device and the slave device, when the number of devices to be synchronized in the network is large, this will greatly improve the speed of clock synchronization.

[0035] Optionally, the third reference time of the slave device is obtained, including: When the first broadcast packet is scanned, the local time of the slave device at this time is recorded as the first time; the second reference time is obtained by analyzing the second broadcast packet, and the local time of the slave device at this time is recorded as the second time; and the first time and the second time constitute the third reference time of the slave device.

[0036] Specifically, the first time corresponds to the first broadcast packet, that is, the first time is the time when the slave device scans the first broadcast packet; and the second time corresponds to the second broadcast packet, that is, the time when the slave device analyzes the second broadcast packet to obtain the second reference time.

[0037] Optionally, the first reference time includes a world time and a local time of the master device; and the second reference time represents the sending time of the master device sending the first broadcast packet. The system time of the slave device is calculated according to the first reference time, the second reference time and the third reference time, including: A first difference value between the sending time of the first broadcast packet and the local time of the master device is calculated.

[0038] A second difference value between the second time and the first time is calculated.

[0039] The sum of the world time, the first difference value and the second difference value is the system time of the slave device.

[0040] Specifically, the world time W1 is a TAI time obtained by the master device, which will serve as the clock synchronization reference of the short-distance wireless communication network. The master device retrieves the baseband reference clock t1 at this moment, and the baseband reference clock is the local time of the master device; the master device encapsulates W1 and t1 into a data packet and converts the data packet into the first broadcast packet, and publishes the first broadcast packet to the short-distance wireless communication network, and records the sending time t2 of the first broadcast packet as the second reference time.

[0041] The slave device scans the first broadcast packet, analyzes the first broadcast packet to obtain W1 and t1, and reads the baseband reference clock r1 of the slave device at this moment as the first time.

[0042] The second broadcast packet is scanned from the slave device, t2 is obtained by analyzing the second broadcast packet, r2 is read as the second time from the baseband reference clock of the slave device at this moment, and the current time w2 corresponding to the slave device can be calculated as w1 + t2 - t1 + r2 - r1. Wherein, t2 - t1 represents the time interval from the generation of the first broadcast packet by the master device to the actual sending of the first broadcast packet; r2 - r1 represents the world time elapsed from the time when the slave device scans the first broadcast packet sent by the master device to the time when the slave device calculates w2.

[0043] The time synchronization method of the master-slave device, the master device and the slave device in the short-range wireless communication network communicate based on the broadcast mode. Using this transmission mode, the time difference between the master device and the slave device corresponds to the reception and transmission of the first broadcast packet. In the case where the propagation time of electromagnetic waves between the two devices is negligible, the time involved in the above-mentioned time difference corresponds to the same world time. The slave device can accurately calculate its own system time according to the above formula, and complete clock synchronization update under the condition of considering the broadcast delay, thereby realizing the time synchronization between the master device and the slave device in the short-range wireless communication network.

[0044] Optionally, the short-range wireless communication network includes any one of a BLE Mesh network, a WIFI network, and a Zigbee network.

[0045] In the case where the short-range wireless communication network is a BLE Mesh network, the first broadcast packet is scanned based on the Bluetooth extended broadcast mode.

[0046] Specifically, Bluetooth extended broadcast is a new function introduced by Bluetooth 5.0. The length of traditional BLE broadcast data is limited and cannot meet the demand of large-capacity data transmission for some applications. The extended broadcast extends the broadcast channel to all physical channels, providing larger data capacity and higher transmission efficiency, and can configure more complex scenarios.

[0047] Optionally, the first broadcast packet is scanned based on the Bluetooth extended broadcast mode, including: The master broadcast packet sent by the master device on the first broadcast channel is scanned, and the index carried in the master broadcast packet is analyzed. According to the index, the first broadcast packet sent by the master device is scanned on the second broadcast channel.

[0048] Specifically, the extended broadcast channel comprises a first broadcast channel and a second broadcast channel, and the first broadcast channel is a main broadcast channel. The master device first publishes a short main broadcast packet on the main broadcast channel, and the main broadcast packet carries an index of the second broadcast channel. Then the master device sends the first broadcast packet on the second broadcast channel. After the slave device scans the main broadcast packet on the first broadcast channel, the index is parsed to know the arrival of the extended broadcast data, and the second broadcast channel is listened to to scan the first broadcast packet.

[0049] Further, the master device continues to send a second broadcast packet for the slave device to scan after sending the first broadcast packet. It should be noted that the data length of the second broadcast packet is limited, and the transmission mode can be a traditional Bluetooth broadcast mode or the Bluetooth extended broadcast mode.

[0050] Specifically, in the embodiment, the master device first calls the baseband reference clock t1 at the moment, then encapsulates W1 and t1 into a data packet and converts the data packet into a first broadcast packet, and then publishes a short main broadcast packet on the first broadcast channel, and the main broadcast packet carries an index of the second broadcast channel. Finally, the master device publishes the first broadcast packet on the second broadcast channel, and records the sending time t2 of the first broadcast packet as a second reference time.

[0051] The slave device scans the main broadcast packet, and scans the first broadcast packet on the second broadcast channel according to the index, and parses W1 and t1 to read the baseband reference clock r1 of the slave device at the moment as a first time.

[0052] The slave device continues to scan to obtain the second broadcast packet, parses t2 to read the baseband reference clock r2 of the slave device at the moment as a second time, and thus the current time w2 of the slave device can be calculated as w2 = w1 + t2 – t1 + r2 – r1. Wherein, t2 – t1 represents the delay time from the master device preparing to send the Bluetooth extended broadcast to actually sending the first broadcast packet; and r2 – r1 represents the world time elapsed from the slave device scanning the first broadcast packet sent by the master device to the slave device calculating w2.

[0053] Optionally, in the case that the short-range wireless communication network is a WIFI network, the time synchronization method of the master-slave device can be implemented through WIFI. Taking a local area network as an example, a device supporting an access point (AP) mode is taken as a master node, and the rest of the devices are taken as slave nodes. The slave device communicates with the master device through a channel designated by the master device, and when the slave device does not complete time synchronization or the time synchronization state expires, the slave device will listen to the channel. The master device publishes a broadcast packet on the channel, such as by setting a custom Beacon frame and adding custom content in the vendor-defined field, accompanied by a corresponding reference time; wherein the broadcast packet includes a first broadcast packet and a second broadcast packet, and the reference time includes a first reference time and a second reference time. The slave device scans the first broadcast packet and reads the baseband reference clock r1 of the slave device at this time as the first time; scans and parses the second broadcast packet, and reads the baseband reference clock r2 of the slave device at this time as the second time; and finally calculates the time w2 according to the formula w2 = w1 + t2 - t1 + r2 - r1.

[0054] Optionally, in the case that the short-range wireless communication network is a Zigbee network, the time synchronization method of the master-slave device can be implemented through Zigbee. The coordinator in the Zigbee network will select a fixed channel when initializing, and the slave device will use the channel to communicate when joining the network. When the slave device does not complete time synchronization or the time synchronization state has expired, the slave device will initiate passive scanning on the fixed channel at initialization. If the slave device scans the first broadcast packet, reads the baseband reference clock r1 of the slave device at this time as the first time; if the second broadcast packet is scanned and parsed, the baseband reference clock r2 of the slave device at this time is read as the second time; and finally, the time W2 is calculated according to the formula w2 = w1 + t2 - t1 + r2 - r1. It should be understood that although each step in the flowchart involved in each of the above-described embodiments is displayed in sequence according to the direction of the arrow, these steps are not necessarily executed in the order indicated by the arrow. Unless otherwise specified herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other orders. Moreover, at least part of the steps in the flowchart involved in each of the above-described embodiments can include multiple steps or stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily sequential, but can be executed in rotation or alternation with at least part of other steps or steps or stages in other steps.

[0055] Based on the same inventive concept, the embodiment of the present application further provides a master-slave device time synchronization device, which is suitable for the master-slave device time synchronization method of the slave device. The solution provided by the device is similar to the solution described in the method, and therefore the specific limitations in one or more device embodiments provided below can refer to the limitations of the method described above, and will not be repeated here.

[0056] Please refer to Figure 2 In one embodiment, the master-slave device time synchronization device comprises a scanning module and an analysis module.

[0057] The scanning module is configured to scan a first broadcast packet sent by a master device in a short-distance wireless communication network.

[0058] The analysis module is configured to parse the first broadcast packet to obtain a first reference time, wherein the first reference time is generated based on a world time.

[0059] The scanning module is further configured to scan a second broadcast packet sent by the master device.

[0060] The analysis module is further configured to parse the second broadcast packet to obtain a second reference time associated with the first reference time, and obtain a third reference time of the slave device, and calculate a system time of the slave device based on the first reference time, the second reference time and the third reference time, so as to synchronize the time of the slave device with the time of the master device.

[0061] Optionally, the analysis module obtains the third reference time of the slave device, including: when the first broadcast packet is scanned, recording the local time of the slave device at this time as a first time; when the second broadcast packet is parsed to obtain the second reference time, recording the local time of the slave device at this time as a second time; and the first time and the second time constitute the third reference time of the slave device.

[0062] Optionally, the first reference time comprises a world time and a local time of the master device, and the second reference time comprises a sending time of the first broadcast packet sent by the master device. The analysis module calculates the system time of the slave device based on the first reference time, the second reference time and the third reference time, including: calculating a first difference value between the sending time of the first broadcast packet and the local time of the master device; calculating a second difference value between the second time and the first time; and the sum of the world time, the first difference value and the second difference value is the system time of the slave device.

[0063] Optionally, the short-range wireless communication network comprises any one of a BLE Mesh network, a WIFI network, and a Zigbee network, in a case where the short-range wireless communication network is a BLE Mesh network, the scanning module scans to obtain the first broadcast packet based on a Bluetooth extended broadcast manner, comprising: scanning to obtain a master broadcast packet sent by a master device on a first broadcast channel, and parsing to obtain an index carried in the master broadcast packet; and according to the index, scanning to obtain the first broadcast packet sent by the master device on a second broadcast channel.

[0064] The time synchronization device of the master-slave device, the master device and the slave device in the short-range wireless communication network communicate based on a broadcast manner, in this transmission manner, the time difference between the master device and the slave device is the transmission and reception of a same broadcast packet, in a case where the propagation time of an electromagnetic wave between the two devices is negligible, the time involved in the time difference corresponds to the same world time, the slave device can accurately calculate its own system time, and can complete clock synchronization update under the condition of considering broadcast delay, thereby realizing time synchronization between the master device and the slave device in the short-range wireless communication network. Further, the time synchronization between the master device and the slave device can be completed without bidirectional message transmission, and when the number of devices to be synchronized in the network is large, this can greatly improve the speed of clock synchronization.

[0065] Please refer to Figure 3 Based on the same inventive concept, the embodiments of the present application also provide a time synchronization method of a master-slave device, suitable for a master device in a short-range wireless communication network, comprising: Step 302: generating a first reference time based on a world time, and publishing the first reference time in the short-range wireless communication network after being packaged into a first broadcast packet.

[0066] Step 304: packaging a second reference time associated with the first reference time into a second broadcast packet, and publishing the second reference time, so that a slave device in the short-range wireless communication network calculates its own system time according to the first reference time, the second reference time, and its own third reference time, and completes time synchronization.

[0067] Optionally, the first reference time comprises a world time and a local time of the master device, and the second reference time comprises a sending time of the master device sending the first broadcast packet. In the time synchronization method of the master and the slave, the master and the slave in the short-range wireless communication network communicate based on a broadcast mode. In this transmission mode, the time difference between the master and the slave corresponds to the sending and receiving of a same broadcast packet, and in the case that the propagation time of electromagnetic waves between the two devices is negligible, the time involved in the time difference corresponds to the same world time. The slave can accurately calculate its own system time and complete clock synchronization update under the condition of considering the broadcast delay, thereby realizing the time synchronization between the master and the slave in the short-range wireless communication network. Further, the time synchronization between the master and the slave can be completed without bidirectional message transmission, which greatly improves the speed of clock synchronization when the number of devices to be synchronized in the network is large.

[0068] Based on the same inventive concept, the embodiment of the present application further provides a time synchronization device of a master and a slave, which is suitable for the time synchronization method of the master and the slave of the master device.

[0069] Please refer to Figure 4 In one embodiment, the time synchronization device of the master and the slave comprises a processing module and a transmission module.

[0070] The processing module is configured to generate a first reference time based on a world time and pack the first reference time into a first broadcast packet.

[0071] The transmission module is configured to publish the first broadcast packet in a short-range wireless communication network. The processing module is further configured to obtain a second reference time associated with the first reference time and pack the second reference time into a second broadcast packet.

[0072] The transmission module is further configured to publish the second reference time in the short-range wireless communication network, so that a slave in the short-range wireless communication network calculates its own system time according to the first reference time, the second reference time and its own third reference time, and completes time synchronization.

[0073] The time synchronization device of the master-slave device, the master device and the slave device in the short-range wireless communication network communicate based on a broadcast mode. In this transmission mode, the time difference between the master device and the slave device is the transmission and reception of a same broadcast packet. In the case that the propagation time of electromagnetic waves between the two devices is negligible, the time involved in the time difference corresponds to the same world time. The slave device can accurately calculate its own system time and complete clock synchronization update under the condition of considering the broadcast delay, thereby realizing the time synchronization between the master device and the slave device in the short-range wireless communication network. Further, the time synchronization between the master device and the slave device can be completed without bidirectional message transmission. When the number of devices to be synchronized in the network is large, the speed of clock synchronization is greatly improved.

[0074] Please refer to Figure 5 Based on the same inventive concept, the embodiment of the present application further provides a time synchronization method of a master-slave device, which is suitable for a master device and a slave device in a short-range wireless communication network, and includes the following steps: In step 502, the master device generates a first reference time based on the world time, packs the first reference time into a first broadcast packet, and publishes the first broadcast packet in the short-range wireless communication network.

[0075] In step 504, the slave device scans the first broadcast packet and analyzes the first broadcast packet to obtain the first reference time.

[0076] In step 506, the master device obtains a second reference time associated with the first reference time, packs the second reference time into a second broadcast packet, and publishes the second broadcast packet in the short-range wireless communication network.

[0077] In step 508, the slave device scans the second broadcast packet and analyzes the second broadcast packet to obtain the second reference time.

[0078] In step 510, the slave device obtains a third reference time of itself, and calculates a system time of itself according to the first reference time, the second reference time and the third reference time, so as to synchronize the time with the master device.

[0079] Optionally, in the case of the short-range wireless communication network being a BLE Mesh network, the master device and the slave device each include a Host and a Controller. The Host is a software protocol stack running on an application processor, responsible for high-layer protocol management and business logic, including modules such as Generic Access Profile (GAP), Generic Attribute Profile (GATT), and Security Management Protocol (SMP); the Controller is a hardware module responsible for processing the underlying radio frequency communication, including the physical layer (PHY), the link layer (LL), and the Host Controller Interface (HCI). When the Host of a node needs to send data, the encapsulated data packet is sent to the Controller of the node through the HCI, and the Controller converts the data packet into a radio frequency signal and broadcasts it to the BLE Mesh network; when the Controller receives radio frequency data sent by other nodes, it uploads the data to the Host through the HCI, which parses and triggers the application layer callback.

[0080] Optionally, the master device and the slave device communicate based on a Bluetooth extended broadcast mode.

[0081] The Host of the master device sets the Bluetooth extended broadcast parameters to be sent, and configures a specific first identification bit in the broadcast event attribute. The Host of the master device also sets the data content of the master broadcast packet and the extended broadcast packet. The data content of the master broadcast packet includes a second broadcast channel index, and the data content of the extended broadcast packet includes a first reference time. Specifically, the Host of the master device obtains a TAI time W1 as a clock synchronization reference of the BLE Mesh network, and reads a baseband reference clock t1 in the Controller of the master device. W1 and t1 are combined as the first reference time. The Host of the master device sends the Bluetooth broadcast parameters and the broadcast packet content to the Controller of the master device through an HCI command.

[0082] The Controller of the master device receives the Bluetooth extended broadcast parameters issued by the Host of the master device, detects the first identification bit in the broadcast event attribute, generates a first broadcast packet according to the first reference time, and sets a specific second identification bit in the first broadcast packet. At the same time, the Controller of the master device reads the baseband reference clock t2 when preparing to send the first broadcast packet in the physical layer, and reports the sending time t2 to the Host of the master device through an HCI event after the broadcast packet is sent. Since the time when the Controller of the master device sends the broadcast packet is affected by the length of the broadcast packet, the time reported by the master device and the slave device should be the start or end time of the broadcast packet transmission.

[0083] The Controller of the slave device is always in a scanning state, listening to messages in the broadcast channel. If a main broadcast packet is scanned, the corresponding second broadcast channel is scanned according to the index to obtain the first broadcast packet. The Controller of the slave device reads the baseband reference clock r1 when the physical layer starts scanning the first broadcast packet.

[0084] After the Controller of the slave device scans the first broadcast packet, if the second identification bit is detected, the first broadcast packet and the baseband reference clock r1 scanned to obtain the first broadcast packet are reported to the Host of the slave device through an HCI event.

[0085] Further, the Host of the master device receives the second reference time t2 reported by the Controller of the master device, packs the second reference time t2 into a second broadcast packet, and then controls the Controller of the master device to send the second broadcast packet to the slave device through an HCI command.

[0086] The Host of the slave device receives the second reference time t2, reads the current baseband reference clock r2 of the slave device, and then calculates the system time of the slave device according to the formula w2 = w1 + t2 - t1 + r2 - r1, and takes the system time as the local time of the slave device at this time, so as to realize synchronization with the master device.

[0087] Exemplarily, in the case that the short-range wireless communication network is a WIFI network, the master device and the slave device each include an application layer, a MAC layer and a physical layer. The application layer of the master device obtains the world time W1 through Ethernet and the like, and reads the baseband reference clock t1. The application layer of the master device transmits information to the MAC layer, and the MAC layer adds the information to the Beacon field, such as adding w1 and t1 as broadcast data in the vendor-defined field. At the same time, the application layer of the master device sets a first identification bit in the broadcast packet, such as setting a private frame subtype in the frame control field, or other positions that can be recognized by the MAC layer. When the MAC layer of the master device detects the identification bit, the second identification bit is set in the broadcast packet, and the baseband reference clock is read to obtain the sending time t2 when the physical layer prepares to send the first broadcast packet, and is reported to the application layer. The slave device is in a scanning state, and listens to messages in a preset broadcast channel. The slave device reads the baseband reference clock r1 when the physical layer starts scanning the first broadcast packet. If the MAC layer of the slave device detects the second identification bit, the first broadcast packet and r1 are reported to the application layer of the slave device.

[0088] Further, the master device application layer acquires the sending time t2, which is packaged into a second broadcast packet in the same way and sent on the specific channel. The slave device receives the second reference time t2, reads the slave device's current baseband reference clock r2, and calculates the slave device's system time according to the formula w2 = w1 + t2 - t1 + r2 - r1, taking the system time as the slave device's local time at this time, thereby achieving synchronization with the master device.

[0089] Exemplarily, in the case of a Zigbee network as the short-range wireless communication network, the master device and the slave device each include an application layer, a network layer, a MAC layer, and a physical layer. The master device sets the destination address to the broadcast address and the broadcast radius field to 1 at the network layer, thereby ensuring that the message can be received by the slave devices within the communication range of the master device and not forwarded by the slave devices. The network layer of the master device sets a first identification bit in the broadcast, such as the reserved bit of the frame control field, thereby causing the MAC layer to read the baseband reference clock t2 when preparing to send the first broadcast packet when the MAC layer recognizes the identification bit. Meanwhile, the MAC layer sets a second identification bit in the broadcast packet and controls the physical layer to send the first broadcast packet on a fixed channel.

[0090] The slave device reads the baseband reference clock r1 when the physical layer starts scanning for the first broadcast packet. When the slave device scans the first broadcast packet, the MAC layer detects the second identification bit, and the first broadcast packet and the baseband reference clock r1 at which the first broadcast packet is scanned are reported to the application layer of the slave device.

[0091] Further, the MAC layer of the master device reports the sending time t2 to the application layer of the master device after sending the first broadcast packet. The master device application layer packages it into a second broadcast packet and sets the destination address to the broadcast address and the broadcast radius field to 1 at the network layer. The master device sends the second broadcast packet to the Zigbee network, and the physical layer of the slave device reports the second broadcast packet to the application layer after scanning the second broadcast packet. The slave device application layer reads the baseband reference clock r2 after parsing the second broadcast packet, and the slave device obtains the slave device's system time w2 according to the formula.

[0092] Exemplarily, the following is described by taking a BLE Mesh network composed of one master device and two slave devices and clock synchronization. Each device maintains an independently running 1000HZ timer and an 8-bit count bit. The timer adds 1 to the count bit each time it counts, and the count bit overflows every 256ms. Each time the time synchronization is established, the slave device adds the clock deviation to the count bit, so that the timer is synchronized with the master device. When the counter overflows, the master device and the two slave devices record the local time at this time. In the embodiment of the application, the target clock synchronization accuracy is set to 1000us, the maximum clock drift of the device is 100us per second on average, and the clock synchronization period T is 5s. According to statistics, the local time output after the time synchronization of the above three devices using the master-slave device time synchronization method of the application is shown in Table 1. As can be seen from Table 1, the time synchronization error of the three devices is 300us-400us, which meets the target clock synchronization accuracy requirement.

[0093] Table 1 Local time output after synchronization of master-slave devices

[0094] Optionally, the master-slave device time synchronization method further comprises: The master device periodically generates and publishes first broadcast packets and second broadcast packets in the short-range wireless communication network based on the world time, so that the slave device performs periodic time synchronization with the master device according to the first broadcast packets and the second broadcast packets.

[0095] Specifically, the master device generates a first reference time based on the current world time according to a preset time interval, and obtains a second reference time associated with the first reference time, and packs them into first broadcast packets and second broadcast packets respectively, and periodically publishes them in the short-range wireless communication network.

[0096] The slave device continuously scans the short-range wireless communication network, and after obtaining the first broadcast packet and the second broadcast packet each time, it analyzes them, and calculates its system time according to the first reference time, the second reference time obtained by analysis, and its own third reference time, to synchronize with the time of the master device.

[0097] By using the above scheme, the master device and each slave device periodically perform clock synchronization, which can correct the clock drift generated in the last period in time, so that the relative error between the master device and the slave device does not accumulate with time, and is stably converged within the preset threshold, thereby maintaining the time consistency of the master device and the slave device.

[0098] The time synchronization method of the master-slave device, the master device and the slave device in the short-range wireless communication network communicate based on a broadcast mode. In this transmission mode, the time difference between the master device and the slave device is the transmission and reception of a same broadcast packet. In the case that the propagation time of electromagnetic waves between the two devices is negligible, the time involved in the above time difference corresponds to the same world time. The slave device can accurately calculate its own system time, complete clock synchronization update under the condition of considering the broadcast delay, periodically synchronize the clock, and make the master-slave device not affected by clock drift, thereby realizing the time synchronization between the master device and the slave device in the short-range wireless communication network. Further, the time synchronization between the master device and the slave device can be completed without bidirectional message transmission. When the number of devices to be synchronized in the network is large, this can greatly improve the speed of clock synchronization.

[0099] Based on the same inventive concept, the embodiments of the present application also provide a time synchronization system of devices in a network, comprising a master device and at least one slave device. The master device and the slave device are located in a short-range wireless communication network, and the master device and the slave device communicate based on a broadcast mode to realize the time synchronization between the master device and the slave device. Further, the time synchronization method of the master-slave device between the master device and the slave device is the same as the time synchronization method of the master-slave device disclosed in the above embodiments. For brevity, details are not repeated here.

[0100] It should be noted that the master device can be any authorized node in the short-range wireless communication network that meets the constraint condition. Specifically, in the case that the short-range wireless communication network includes a Bluetooth low energy mesh network, a node supporting broadcast is selected as the master device; in the case that the short-range wireless communication network includes a WIFI network, a node supporting an access point (AP) mode is selected as the master device; and in the case that the short-range wireless communication network includes a Zigbee network, a coordinator is selected as the master device.

[0101] The time synchronization system of devices in the network, the master device and the slave device in the short-range wireless communication network communicate based on a broadcast mode. In this transmission mode, the time difference between the master device and the slave device is the transmission and reception of a same broadcast packet. In the case that the propagation time of electromagnetic waves between the two devices is negligible, the time involved in the above time difference corresponds to the same world time. The slave device can accurately calculate its own system time, complete clock synchronization update under the condition of considering the broadcast delay, periodically synchronize the clock, and make the master-slave device not affected by clock drift, thereby realizing the time synchronization between the master device and the slave device in the short-range wireless communication network. Further, the time synchronization between the master device and the slave device can be completed without bidirectional message transmission. When the number of devices to be synchronized in the network is large, this can greatly improve the speed of clock synchronization.

[0102] The modules in the time synchronization system of the devices in the network can be implemented by software, hardware, or a combination thereof. The modules can be embedded in or independent of a processor in a computer device in hardware form, or stored in a memory in a computer device in software form, so that the processor can call and execute the operations corresponding to the modules.

[0103] In an embodiment, a computer device, which can be a terminal, has an internal structure as shown in Figure 6 The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, the memory, and the input / output interface are connected through a system bus, and the communication interface, the display unit, and the input device are connected to the system bus through the input / output interface. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for running the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is configured to exchange information between the processor and external devices. The communication interface of the computer device is configured to perform wired or wireless communication with external terminals. The wireless communication can be achieved through WIFI, mobile cellular network, NFC (Near Field Communication), or other technologies. The computer program is executed by the processor to implement the time synchronization method of the master and slave devices. The display unit of the computer device is configured to form a visually visible picture, which can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer overlaid on the display screen, or a key, a trackball, or a touchpad arranged on the housing of the computer device, or an external keyboard, a touchpad, a mouse, or the like.

[0104] Those skilled in the art can understand that Figure 6 The structure shown in the above embodiment is only a block diagram of part of the structure related to the scheme of the present application, and does not limit the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0105] In an embodiment, a computer device includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the method steps in the time synchronization method of the master and slave devices.

[0106] In an implementable embodiment, a computer readable storage medium is provided, which stores a computer program. The computer program is executed by a processor to implement the method steps of the time synchronization method of the master-slave device.

[0107] In an implementable embodiment, a computer program product is provided, which includes a computer program. The computer program is executed by a processor to implement the method steps of the time synchronization method of the master-slave device.

[0108] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer readable storage medium. When the computer program is executed, it can include the processes of the above-mentioned embodiments. Any reference to memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical storage, high-density embedded non-volatile memory, resistive memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The database involved in the embodiments provided in the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided in the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., without being limited thereto.

[0109] Any technical features in the above embodiments can be combined, and for the sake of brevity, not all possible combinations are described above, however, as long as the combinations of technical features do not have contradictions, they shall be considered within the scope of the present disclosure.

[0110] The above embodiments only express several implementation manners of the present application, and the description is relatively specific and detailed, but it shall not be understood as a limitation on the patent scope of the present application. It shall be pointed out that, for ordinary skilled persons in the art, several modifications and improvements can be made without departing from the concept of the present application, and these shall be within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the appended claims.

Claims

1. A time synchronization method of master-slave devices, characterized by, The method comprises: scanning a first broadcast packet sent by a master device in a short-range wireless communication network, and analyzing the first broadcast packet to obtain a first reference time; wherein the first reference time is generated based on a world time; scanning a second broadcast packet sent by the master device, and analyzing the second broadcast packet to obtain a second reference time associated with the first reference time; obtaining a third reference time of the slave device; calculating a system time of the slave device based on the first reference time, the second reference time and the third reference time, to synchronize the time of the slave device with the time of the master device.

2. The method of claim 1, wherein: In the case where the short-range wireless communication network is the Bluetooth low energy mesh network, the first broadcast packet is scanned based on a Bluetooth extended broadcast mode.

3. The method of claim 1, wherein, The method comprises: when the first broadcast packet is scanned, recording a local time of the slave device at this time as a first time; analyzing the second broadcast packet to obtain the second reference time, and recording a local time of the slave device at this time as a second time; the first time and the second time constitute the third reference time of the slave device.

4. The method of claim 3, wherein, The first reference time comprises a world time and a local time of the master device; The second reference time comprises a sending time of the first broadcast packet sent by the master device; The method comprises: calculating a first difference value between the sending time of the first broadcast packet and the local time of the master device; calculating a second difference value between the second time and the first time; the sum of the world time, the first difference value and the second difference value is the system time of the slave device.

5. A time synchronization apparatus of a master-slave device of a master-slave device, characterized by, The device comprises: a scanning module, configured to scan a first broadcast packet sent by a master device in a short-range wireless communication network; an analyzing module, configured to analyze the first broadcast packet to obtain a first reference time; wherein the first reference time is generated based on a world time; The scanning module is further configured to scan a second broadcast packet sent by the master device. The analyzing module is further configured to analyze the second broadcast packet to obtain a second reference time associated with the first reference time, and obtain a third reference time of the slave device, and calculate a system time of the slave device based on the first reference time, the second reference time and the third reference time, to synchronize the time of the slave device with the time of the master device.

6. A time synchronization method of master-slave devices, characterized by, The method comprises: generating a first reference time based on a world time, and packaging the first reference time into a first broadcast packet to publish in a short-range wireless communication network; packaging a second reference time associated with the first reference time into a second broadcast packet, and publishing the second broadcast packet, so that a slave device in the short-range wireless communication network calculates a system time of the slave device based on the first reference time, the second reference time and a third reference time of the slave device, to complete time synchronization.

7. A time synchronization apparatus of a master-slave device of a master-slave device, characterized by, The device comprises: a processing module, configured to generate a first reference time based on a world time, and package the first reference time into a first broadcast packet; a transmission module, configured to publish the first broadcast packet in a short-range wireless communication network; The processing module is further configured to obtain a second reference time associated with the first reference time and pack the second reference time into a second broadcast packet. The transmission module is further configured to publish the second reference time in the short-range wireless communication network, so that a slave device in the short-range wireless communication network calculates its own system time according to the first reference time, the second reference time and its own third reference time, and completes time synchronization.

8. A time synchronization method of master-slave devices, characterized by, The method comprises: The master device generates a first reference time based on a world time, packs the first reference time into a first broadcast packet and publishes the first broadcast packet in the short-range wireless communication network; The slave device parses the first broadcast packet after scanning the first broadcast packet to obtain the first reference time; The master device obtains a second reference time associated with the first reference time, packs the second reference time into a second broadcast packet and publishes the second broadcast packet in the short-range wireless communication network; The slave device parses the second broadcast packet after scanning the second broadcast packet to obtain the second reference time; The slave device obtains its own third reference time and calculates its own system time according to the first reference time, the second reference time and the third reference time, so as to synchronize the time with the master device.

9. The method of claim 8, wherein, The method further comprises: The master device periodically generates a first broadcast packet and a second broadcast packet based on a world time and publishes the first broadcast packet and the second broadcast packet in the short-range wireless communication network, so that the slave device periodically synchronizes the time with the master device according to the first broadcast packet and the second broadcast packet.

10. A time synchronization system of devices in a network, characterized by, The system comprises: The master device is configured to generate a first reference time based on a world time, pack the first reference time into a first broadcast packet and publish the first broadcast packet in the short-range wireless communication network; The slave device is configured to parse the first broadcast packet after scanning the first broadcast packet to obtain the first reference time; The master device is further configured to obtain a second reference time associated with the first reference time, pack the second reference time into a second broadcast packet and publish the second broadcast packet in the short-range wireless communication network; The slave device is further configured to parse the second broadcast packet after scanning the second broadcast packet to obtain the second reference time, obtain its own third reference time and calculate its own system time according to the first reference time, the second reference time and the third reference time, so as to synchronize the time with the master device. 11.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-10. The processor executes the computer program to implement the steps of the method of any one of claims 1-4, or 6 or 8-9.

12. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method of any one of claims 1-4, or 6 or 8-9.