Time synchronization method, apparatus and system, and device and storage medium
By receiving time data packets sent by networked devices, parsing the confidence level, and updating the local time, the problem of obtaining time from non-networked devices is solved, ensuring the normal operation of the function.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- MIDEA INTELLIGENT LIGHTING & CONTROLS TECHNOLOGY CO LTD
- Filing Date
- 2025-10-30
- Publication Date
- 2026-07-02
AI Technical Summary
Electronic devices cannot obtain accurate time when they are not connected to the internet, which prevents them from performing time-dependent functions, such as rhythmic lighting.
By acquiring time data packets sent by a second device that is connected to the network, parsing and determining the confidence level, updating the local time based on the confidence level, and generating and sending time data packets to other devices.
This enables devices that are not connected to the internet to accurately obtain the time, ensuring the normal execution of functions.
Smart Images

Figure CN2025131150_02072026_PF_FP_ABST
Abstract
Description
Time synchronization methods, devices, equipment, storage media and systems
[0001] Related applications
[0002] This application claims priority to Chinese patent application No. 202411947119.X, filed on December 27, 2024, the entire contents of which are incorporated herein by reference. Technical Field
[0003] This application relates to the field of time synchronization technology, and in particular to time synchronization methods, apparatus, devices, storage media and systems. Background Technology
[0004] Currently, to enhance user experience and functionality, many electronic devices feature timed on / off, scheduling, and rhythmic lighting. The realization of these functions largely depends on the device's ability to obtain accurate time. However, some electronic devices may be offline, preventing them from acquiring time and thus hindering their ability to perform actions based on time. For example, for rhythmic lighting, the light fixture must be connected to the internet to accurately obtain time and execute the corresponding actions. Such designs fail to consider how the function works when the light fixture is offline.
[0005] Therefore, how electronic devices can obtain accurate time when they are not connected to the internet has become an urgent problem to be solved. Summary of the Invention
[0006] To address the aforementioned technical problems, this application provides a time synchronization method, apparatus, device, storage medium, and system.
[0007] In a first aspect, this application provides a time synchronization method applied to a first device, the first device being in a non-networked state, the method comprising:
[0008] Acquire a first time data packet sent by the second device. The first time data packet includes a first synchronization time and its corresponding first confidence level. The number of first time data packets acquired by the first device at the same time is n, where n is a positive integer.
[0009] Parse the first time data packet to obtain the first synchronization time and its corresponding first confidence level;
[0010] Based on n of the first confidence levels, determine the target confidence level;
[0011] Based on the target confidence level, determine whether to update the current local time of the first device;
[0012] If it is determined that the current local time of the first device needs to be updated, a second time data packet is generated based on the target confidence level and its corresponding first synchronization time, and the second time data packet is sent to other devices.
[0013] Secondly, this application also provides a time synchronization device applied to a first device, the first device being in a non-networked state, the device comprising:
[0014] The first acquisition module is used to acquire a first time data packet sent by the second device. The first time data packet includes a first synchronization time and its corresponding first confidence level. The number of first time data packets acquired by the first device at the same time is n, where n is a positive integer.
[0015] The first parsing module is used to parse the first time data packet to obtain the first synchronization time and its corresponding first confidence level.
[0016] The first determining module is used to determine the target confidence level based on n of the first confidence levels;
[0017] The second determining module is used to determine whether to update the current local time of the first device based on the target confidence level.
[0018] The first sending module is configured to, upon determining that the current local time of the first device needs to be updated, generate a second time data packet based on the target confidence level and its corresponding first synchronization time, and send the second time data packet to other devices.
[0019] Thirdly, this application also provides an electronic device, including:
[0020] processor;
[0021] Memory, used to store executable instructions;
[0022] The processor is used to read executable instructions from memory and execute the executable instructions to implement the time synchronization method of the first aspect mentioned above.
[0023] Fourthly, this application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to implement the time synchronization method described in the first aspect.
[0024] Fifthly, this application also provides a time synchronization system, including:
[0025] At least one second device, the second device being configured to process the first synchronization time and its corresponding first confidence level to obtain a first time data packet, and to send the first time data packet to the first device;
[0026] At least one first device is in a non-networked state. The first device is used to acquire the first time data packet sent by the second device. The number of first time data packets acquired by the first device at the same time is n, where n is a positive integer. The first device is also used to parse the first time data packet to obtain the first synchronization time and its corresponding first confidence level. Based on the n first confidence levels, a target confidence level is determined. Based on the target confidence level, it is determined whether to update the current local time of the first device. The first device is also used to generate a second time data packet based on the target confidence level and its corresponding first synchronization time if it is determined to update the current local time of the first device, and send the second time data packet to other devices.
[0027] The technical solution provided in this application has the following advantages compared with the prior art:
[0028] The time synchronization method, apparatus, device, storage medium, and system of this application embodiment include a first device capable of acquiring a first time data packet sent by a second device. The first time data packet includes a first synchronization time and its corresponding first confidence level. The number of first time data packets acquired simultaneously by the first device is n. The first time data packet is parsed to obtain the first synchronization time and its corresponding first confidence level. Based on the n first confidence levels, a target confidence level is determined. Based on the target confidence level, it is determined whether to update the current local time of the first device. If it is determined that the current local time of the first device should be updated, a second time data packet is generated based on the target confidence level and its corresponding first synchronization time, and the second time data packet is sent to other devices. According to the embodiments of this application, when the first device is not connected to the network, it can obtain the time by receiving the first time data packet sent by the second device. Therefore, by adopting the above technical solution, when the first device is not connected to the network, it can obtain n first synchronization times by receiving the first time data packet sent by the second device, then determine the target confidence level based on the n first confidence levels corresponding to the n first synchronization times, and then determine whether to update its own current local time based on the target confidence level, thereby obtaining an accurate time. Attached Figure Description
[0029] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0030] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0031] Figure 1 is a flowchart illustrating a time synchronization method provided in an embodiment of this application;
[0032] Figure 2 is a schematic diagram of a process for a second device to send a first time data packet according to an embodiment of this application;
[0033] Figure 3 is a flowchart illustrating a time synchronization example provided in an embodiment of this application;
[0034] Figure 4 is a schematic diagram of a time synchronization system provided in an embodiment of this application;
[0035] Figure 5 is a schematic diagram of a time synchronization device provided in an embodiment of this application;
[0036] Figure 6 is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Embodiments of the present invention
[0037] Embodiments of this application will now be described in more detail with reference to the accompanying drawings. While some embodiments of this application are shown in the drawings, it should be understood that this application can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this application. It should be understood that the drawings and embodiments of this application are for illustrative purposes only and are not intended to limit the scope of protection of this application.
[0038] It should be understood that the steps described in the method embodiments of this application may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this application is not limited in this respect.
[0039] The term "comprising" and its variations as used herein are open-ended inclusions, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the description below.
[0040] It should be noted that the concepts of "first" and "second" mentioned in this application are only used to distinguish different devices, modules or units, and are not used to limit the order of functions performed by these devices, modules or units or their interdependencies.
[0041] It should be noted that the terms "a" and "a plurality of" used in this application are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".
[0042] The names of the messages or information exchanged between multiple devices in the embodiments of this application are for illustrative purposes only and are not intended to limit the scope of these messages or information.
[0043] Figure 1 is a flowchart illustrating a time synchronization method provided in an embodiment of this application. In some embodiments of this application, the method shown in Figure 1 can be applied to a first device, which is in a non-networked state. The non-networked state can be understood, for example, as the first device lacking network connectivity, or as the first device having network connectivity but not being connected to the network. The first device can be understood, for example, a light fixture (e.g., a ceiling light), a door lock, a sensor, a remote control, etc., but is not limited to these.
[0044] As shown in Figure 1, the time synchronization method may include the following steps.
[0045] S110. Obtain a first time data packet sent by the second device. The first time data packet includes a first synchronization time and its corresponding first confidence level. The number of first time data packets obtained by the first device at the same time is n, where n is a positive integer.
[0046] Specifically, the first confidence level is used to characterize how close the corresponding first synchronization time is to the standard time provided by a standard time source (e.g., a network). The higher the first confidence level, the closer the first synchronization time is to the standard time, and the more accurate the first synchronization time. Conversely, the lower the first confidence level, the less close the first synchronization time is to the standard time, and the less accurate the first synchronization time is. The first confidence level can be exemplarily represented as a numerical value between 0 and 1, or as a percentage (e.g., 0% to 100%), but is not limited to these representations.
[0047] In some embodiments, the second device is in a networked state (i.e., the second device has network connectivity and is connected to the network), and the first synchronization time is the standard time obtained by the second device when connected to the network.
[0048] Specifically, the second device can obtain a standard time via Wi-Fi or cellular network and use the obtained standard time as the first synchronization time. In this case, the first confidence level corresponding to the first synchronization time can be set to the maximum confidence value, such as 1 or 100%.
[0049] For example, Figure 2 is a schematic diagram of a second device sending a first time data packet according to an embodiment of this application. As shown in Figure 2, when the second device is connected to the network, the second device can obtain a standard time through the network, and then set the first confidence level corresponding to the standard time as the maximum confidence level value, and then package the standard time and its corresponding first confidence level to obtain a first time data packet.
[0050] Understandably, after acquiring the standard time, the second device promptly packages and sends out the standard time and its corresponding first confidence level, demonstrating the effectiveness of the first-time data packet.
[0051] In one embodiment, after the second device obtains the standard time through the network, it can update the current local time of the second device to the standard time. Then, S01, the current local time of the second device is obtained and used as the first synchronization time.
[0052] S02. Calculate the difference between the time when the second device last updated its local time and the current local time of the second device to obtain the third difference;
[0053] S03. Determine the first confidence level corresponding to the first synchronization time based on the absolute value of the third difference, wherein the absolute value of the third difference is negatively correlated with the first confidence level;
[0054] S04. Process the first synchronization time and its corresponding first confidence level to obtain the first time data packet.
[0055] Specifically, the second device can execute S01-S04 once, or it can repeatedly execute S01-S04 until the second device obtains the standard time through the network again or the second device is powered off.
[0056] Specifically, following the principle that "the further the current local time is from the last time the local time was updated according to the standard time, the lower the corresponding first confidence level," the first confidence level corresponding to the current local time (i.e., the first synchronization time) is set. For example, the time interval between "the current local time" and "the last time the local time was updated according to the standard time" is recorded as the first time interval. The second device can determine the reduction amplitude corresponding to the absolute value of the third difference based on the pre-set first time interval and the comparison relationship between the reduction amplitude and the reduction amplitude. Then, the first confidence level corresponding to the current local time (i.e., the first synchronization time) is obtained by subtracting the reduction amplitude from the maximum confidence level, but it is not limited to this.
[0057] Understandably, after updating the current local time to the standard time, the local time of the second device will become increasingly inaccurate over time due to factors such as crystal oscillator drift. By setting the first confidence level corresponding to the current local time (i.e., the first synchronization time) of the second device to decrease over time, the first confidence level can more accurately represent the accuracy of its corresponding current local time (i.e., the first synchronization time).
[0058] In other examples, the second device is connected to the control device, which has network connectivity and is already connected to the network. After obtaining the standard time through the network, the control device can send the standard time it obtained to the second device. The second device uses the obtained standard time as the first synchronization time. In this case, considering that it takes a certain amount of time for the second device to obtain the standard time from the control device, the first confidence level corresponding to the first synchronization time can be set to be less than the maximum confidence level. The absolute value of the difference between the first confidence level corresponding to the first synchronization time and the maximum confidence level is positively correlated with the time taken for the second device to obtain the standard time from the control device.
[0059] Specifically, the second device and the control device can be connected via a wired connection or a wireless connection (such as Bluetooth), and this application does not limit this. The control device may include, but is not limited to, mobile phones, tablets, and / or wearable devices.
[0060] In some other embodiments, the second device may obtain the standard time input by the user in response to the user's time setting operation.
[0061] Specifically, the time setting operation refers to the operation of manually setting the time of the second device so that the second device can obtain the standard time. For example, the time setting operation can be the operation of inputting the standard time into the second device through a keyboard, mouse, touch, or voice, but it is not limited to these.
[0062] Specifically, there are various implementation methods for the second device to send the first time data packet to the first device, and this application does not limit this to any particular method. For example, the second device can broadcast the first time data packet via wireless communication, such as 2.4G Bluetooth communication or 433MHz communication, but is not limited to these. In this way, the first device within the receiving range of the wireless broadcast can receive the first time data packet. The receiving range refers to the maximum geographical area within which the first device can receive the first time data packet, and within this area, the first device should be able to stably receive the first time data packet. Those skilled in the art should understand that the second device can adjust the receiving range of its broadcast first time data packet by changing the transmission power or frequency, or by adjusting the received signal strength threshold for receiving the first time data packet. This allows the first time data packets to communicate within a controllable range, for example, without being affected by the signals from devices in neighboring houses.
[0063] S120. Parse the first time data packet to obtain the first synchronization time and its corresponding first confidence level.
[0064] Specifically, for each first time data packet, the first device can parse the first time data packet to obtain the first synchronization time and the corresponding first confidence level contained in the first time data packet. In this way, n first synchronization times and n corresponding first confidence levels can be obtained.
[0065] S130. Determine the target confidence level based on n first confidence levels.
[0066] In some embodiments, S130 includes: taking the maximum value among the n first confidence levels as the target confidence level.
[0067] Understandably, a higher first confidence level indicates a more accurate first synchronization time. By using the maximum value among n first confidence levels as the target confidence level, it becomes possible to determine whether to update the current local time of the first device based on the most accurate first synchronization time among the n first synchronization times. This improves the accuracy of "determining whether the current local time of the first device needs to be updated".
[0068] In other embodiments, S130 includes: randomly selecting one from n first confidence levels as the target confidence level.
[0069] S140. Based on the target confidence level, determine whether to update the current local time of the first device.
[0070] In some embodiments, S140 includes: if the target confidence level is greater than a preset threshold, then determining to update the current local time of the first device. This allows for a simple and quick determination of whether the current local time of the first device needs to be updated.
[0071] Specifically, the specific value of the preset threshold can be set by those skilled in the art according to the actual situation, and is not limited here.
[0072] In some other embodiments, S140 includes: obtaining a first reference confidence level and a reference time interval, and reducing the first reference confidence level according to the reference time interval to obtain a second reference confidence level, wherein the first reference confidence level is the first confidence level in the first time data packet used when the first device last updated the local time, and the reference time interval is the time interval from the moment when the first device last updated the local time to the current moment.
[0073] If the target confidence level is greater than the second reference confidence level, then the current local time of the first device is updated.
[0074] Specifically, the first time data packet used when the first device last updated its local time includes the first synchronization time and its corresponding first confidence level, which is the first reference confidence level.
[0075] Specifically, the first reference confidence level is reduced according to the principle that the longer the reference time interval, the greater the reduction amplitude, thereby obtaining the second reference confidence level. For example, the first device can determine the reduction amplitude corresponding to the reference time interval based on the pre-set correspondence between the reference time interval and the reduction amplitude, and then subtract the reduction amplitude from the first reference confidence level to obtain the second reference confidence level, but it is not limited to this.
[0076] Specifically, if the target confidence level is less than or equal to the second reference confidence level, the first device may not update its current local time.
[0077] It is understandable that, since the first device last updated its local time based on the first synchronization time, its local time will become increasingly inaccurate over time due to factors such as crystal oscillator drift. In this embodiment, the first reference confidence level can be reduced based on a reference time interval to obtain a second reference confidence level. The second reference confidence level more accurately represents the accuracy of the first device's current local time. The second reference confidence level is compared with a target confidence level. If the second reference confidence level is greater than the target confidence level, it indicates that the first device's current local time is more accurate than the first synchronization time corresponding to the target confidence level, and the current local time is not updated. If the second reference confidence level is less than the target confidence level, it indicates that the first synchronization time corresponding to the target confidence level is more accurate than the first device's current local time, and the current local time can be updated based on the first synchronization time corresponding to the target confidence level. In this way, the first device's local time can be kept in a relatively accurate state.
[0078] In one embodiment, determining to update the current local time of the first device if the target confidence level is greater than the second reference confidence level includes: if the target confidence level is greater than a preset threshold and greater than the second reference confidence level, then determining to update the current local time of the first device.
[0079] Specifically, if the current local time of the first device is determined to be updated, the current local time of the first device can be updated according to the first synchronization time corresponding to the target confidence level.
[0080] S150. If the current local time of the first device is determined to be updated, a second time data packet is generated based on the target confidence level and its corresponding first synchronization time, and the second time data packet is sent to other devices.
[0081] In some embodiments, generating a second time data packet based on a target confidence level and its corresponding first synchronization time includes: adjusting the target confidence level according to a preset method to obtain a second confidence level, wherein the second confidence level is less than the target confidence level;
[0082] The second confidence level and its corresponding first synchronization time are processed to obtain the second time data packet.
[0083] Specifically, considering that it takes time for the first device to obtain the first time data packet from the second device, the target confidence level can be reduced to obtain the second confidence level by setting a positive correlation between the absolute value of the difference between the second confidence level corresponding to the first synchronization time and the target confidence level and the time taken for the first device to obtain the first time data packet from the second device. In this way, the second confidence level can more accurately represent the accuracy of the first synchronization time.
[0084] In some embodiments, generating a second time data packet based on a target confidence level and its corresponding first synchronization time includes: directly processing the target confidence level and its corresponding first synchronization time to obtain the second time data packet.
[0085] Specifically, there are various implementation methods for the first device to send the second time data packet to other devices, and this application does not limit this one. For example, the first device can send the second time data packet to other devices through wired communication (such as RS-422 interface, etc.) or wireless communication (such as 2.4G Bluetooth communication, or 433MHz communication, etc.), and this application does not limit this one.
[0086] It is understandable that when the first device receives the first time data packet, it can update its current local time according to the first synchronization time corresponding to the target confidence level when the target confidence level is high, so as to keep the local time updated and more accurate. It will also generate a second time data packet and send it to other devices, thus ensuring that more devices can obtain the time.
[0087] For example, Figure 3 is a flowchart illustrating a time synchronization example provided in an embodiment of this application. As shown in Figure 3, the first device receives a first time data packet via wireless communication, and checks whether the first confidence level in the first time data packet is greater than a first threshold (i.e., a preset threshold). If not, the first time data packet is discarded and the process ends. If so, it checks whether the first confidence level (used to characterize the accuracy of receiving the first synchronization time) is greater than a second reference confidence level (capable of characterizing the accuracy of the current local time of the second device). If not, the first time data packet is discarded and the process ends. If so, it calculates the difference between the first synchronization time and the current local time of the second device. If the absolute value of the difference is greater than a preset error, the current local time of the second device is updated to the first synchronization time. If the absolute value of the difference is less than or equal to the preset error, the current local time of the second device is not updated. Then, a second time data packet is generated based on the first confidence level and the first synchronization time, and the second time data packet is sent to other devices. It should be noted that the specific value of the preset error can be set by those skilled in the art according to actual conditions, and is not limited here. For example, the preset error is 0, but it is not limited thereto.
[0088] In this embodiment of the application, when the first device is not connected to the network, it can obtain n first synchronization times by receiving the first time data packet sent by the second device, and then determine the target confidence level based on the n first confidence levels corresponding to the n first synchronization times, and then determine whether to update its own current local time based on the target confidence level, thereby obtaining an accurate time.
[0089] In another embodiment of this application, after sending the second time data packet to other devices, the method further includes:
[0090] S11. Obtain the current local time of the first device and use it as the second synchronization time;
[0091] S12. Calculate the difference between the first synchronization time in the first time data packet used when the first device last updated its local time and the current local time of the first device to obtain the first difference;
[0092] S13. Determine the third confidence level corresponding to the second synchronization time based on the absolute value of the first difference, wherein the absolute value of the first difference is negatively correlated with the third confidence level;
[0093] S14. Process the second synchronization time and its corresponding third confidence level to obtain the third time data packet;
[0094] S15. Send the third time data packet to other devices.
[0095] Specifically, the first device can execute S11-S15 once, or it can repeatedly execute S11-S15 until the first device updates its local time according to the first synchronization time corresponding to the target confidence level or the first device is powered off.
[0096] Specifically, following the principle that "the further away the current local time is from the last update of the local time based on the first synchronization time corresponding to the target confidence level, the lower the corresponding third confidence level," the third confidence level corresponding to the current local time (i.e., the second synchronization time) is set. For example, the time interval between "the current local time" and "the last update of the local time based on the first synchronization time corresponding to the target confidence level" is denoted as the second time interval. The first device can determine the reduction magnitude corresponding to the absolute value of the first difference based on the pre-set second time interval and the comparison relationship between the reduction magnitude and the reduction magnitude. Then, the third confidence level corresponding to the current local time is obtained by subtracting the reduction magnitude from "the target confidence level in the first time data packet used when the local time was last updated," but this is not limited to this method.
[0097] Understandably, after updating the current local time to the standard time, the local time of the first device will become increasingly inaccurate over time due to factors such as crystal oscillator drift. By setting the third confidence level corresponding to the current local time (i.e., the second synchronization time) of the first device to decrease over time, the third confidence level can more accurately represent the accuracy of its corresponding current local time (i.e., the second synchronization time).
[0098] In another embodiment of this application, if it is determined that the current local time of the first device should not be updated, the method further includes:
[0099] Obtain the current local time of the first device and use it as the third synchronization time;
[0100] Calculate the difference between the first synchronization time in the first time data packet used when the first device last updated its local time and the current local time of the first device to obtain the second difference;
[0101] The fourth confidence level corresponding to the third synchronization time is determined based on the absolute value of the second difference, wherein the absolute value of the second difference is negatively correlated with the fourth confidence level;
[0102] The third synchronization time and its corresponding fourth confidence level are processed to obtain the fourth time data packet;
[0103] Send the fourth time data packet to other devices.
[0104] Specifically, following the principle that "the further away the current local time is from the last update of the local time based on the first synchronization time corresponding to the target confidence level, the lower the corresponding fourth confidence level," the fourth confidence level corresponding to the current local time (i.e., the third synchronization time) is set. For example, the time interval between "the current local time" and "the last update of the local time based on the first synchronization time corresponding to the target confidence level" is denoted as the third time interval. The first device can determine the reduction magnitude corresponding to the absolute value of the second difference based on the pre-set third time interval and the comparison relationship between the reduction magnitude and the reduction magnitude. This allows the fourth confidence level corresponding to the current local time to be obtained by subtracting the reduction magnitude from "the target confidence level in the first time data packet used when the local time was last updated," but this is not limited to this method.
[0105] Understandably, after updating the current local time to the standard time, the local time of the first device will become increasingly inaccurate over time due to factors such as crystal oscillator drift. By setting the fourth confidence level corresponding to the current local time (i.e., the third synchronization time) of the first device to decrease over time, the fourth confidence level can more accurately represent the accuracy of its corresponding current local time (i.e., the third synchronization time).
[0106] This application embodiment also provides a time synchronization system, including: at least one second device, the second device being used to process a first synchronization time and its corresponding first confidence level to obtain a first time data packet, and to send the first time data packet to the first device;
[0107] At least one first device is in a non-networked state. The first device is used to acquire first time data packets sent by the second device. The number of first time data packets acquired by the first device at the same time is n, where n is a positive integer. The first device is also used to parse the first time data packets to obtain a first synchronization time and its corresponding first confidence level. Based on the n first confidence levels, a target confidence level is determined. Based on the target confidence level, it is determined whether to update the current local time of the first device. The first device is also used to generate a second time data packet based on the target confidence level and its corresponding first synchronization time if it is determined to update the current local time of the first device, and send the second time data packet to other devices.
[0108] The time synchronization method provided in this application embodiment will be described in detail below with reference to a specific time synchronization system example. Figure 4 is a schematic diagram of a time synchronization system provided in this application embodiment. As shown in Figure 4, the time synchronization system includes electronic devices in a first home and a second home, and the wireless broadcast coverage of each electronic device is circled. The second home contains a first ceiling light device A, a second ceiling light device B, and a first door lock device C. The first ceiling light device A is a Wi-Fi connected device. The first home contains a second door lock device D and a third ceiling light device E. The third ceiling light device E can connect to a mobile phone (control device). The first ceiling light device A obtains the standard time (i.e., the first synchronization time) through Wi-Fi, packages the first synchronization time and the maximum confidence value into a first time data packet, and wirelessly broadcasts the first time data packet. After obtaining the first time data packet, the second ceiling light device B updates its current local time according to the first synchronization time, reduces the maximum confidence value to obtain a second confidence value, processes the first synchronization time and the second confidence value to obtain a second time data packet, and wirelessly broadcasts the second time data packet. After receiving the second time data packet, the first door lock device C determines whether to update its current local time based on the second confidence level in the second time data packet. If it decides to update its current local time, it updates its current local time according to the first synchronization time, reduces the second confidence level to obtain a reduced second confidence level, and processes the first synchronization time and the reduced second confidence level to obtain a new second time data packet, which is then wirelessly broadcast. This process continues until the third ceiling light device E in the first household receives the second time data packet, allowing it to perform rhythmic lighting and other actions based on the first synchronization time. Suppose that the Wi-Fi network of the second household is disconnected for a period of time, and the confidence level of the first time data packet generated by it decreases every day. At this time, the third ceiling light device E in the second household is connected to the mobile phone and obtains the time sent by the mobile phone. Since the confidence level of the time sent by the mobile phone is higher than the confidence level of the first synchronization time obtained through the second door lock device D, the third ceiling light device E packages the time with higher confidence (i.e., the time sent by the mobile phone) into a first time data packet and broadcasts it via Bluetooth. Similarly, through the second door lock device D, the first door lock device C, and the second ceiling light device B, all electronic devices in the first household can receive the first time data packet generated by the third ceiling light device E. In this way, the first ceiling light device A, the second ceiling light device B, the first door lock device C, and the second door lock device D are all updated to the time broadcast by the third ceiling light device E, and continue to broadcast the time broadcast by the third ceiling light device E to keep the time up-to-date within a certain range.
[0109] Figure 5 is a schematic diagram of a time synchronization device provided in an embodiment of this application.
[0110] In some embodiments of this application, the device shown in FIG5 can be applied to a first device, which is in a non-networked state. The first device can be understood by way of example as a lamp (such as a ceiling light), a door lock, a sensor, a remote control, etc., but is not limited thereto.
[0111] As shown in Figure 5, the time synchronization device may include: a first acquisition module 510, used to acquire a first time data packet sent by a second device, wherein the first time data packet includes a first synchronization time and its corresponding first confidence level, and the number of the first time data packets acquired by the first device at the same time is n, where n is a positive integer;
[0112] The first parsing module 520 is used to parse the first time data packet to obtain the first synchronization time and its corresponding first confidence level.
[0113] The first determining module 530 is used to determine the target confidence level based on n first confidence levels;
[0114] The second determining module 540 is used to determine whether to update the current local time of the first device based on the target confidence level.
[0115] The first sending module 550 is configured to, upon determining that the current local time of the first device needs to be updated, generate a second time data packet based on the target confidence level and its corresponding first synchronization time, and send the second time data packet to other devices.
[0116] In one embodiment, the first determining module 530 is specifically used to take the maximum value among the n first confidence scores as the target confidence score.
[0117] In one embodiment, the second determining module 540 is specifically used to determine to update the current local time of the first device if the target confidence level is greater than a preset threshold.
[0118] In one embodiment, the second determining module 540 is specifically used to obtain a first reference confidence level and a reference time interval, and reduce the first reference confidence level according to the reference time interval to obtain a second reference confidence level, wherein the first reference confidence level is the first confidence level in the first time data packet used when the first device last updated its local time, and the reference time interval is the time interval between the moment when the first device last updated its local time and the current moment.
[0119] If the target confidence level is greater than the second reference confidence level, then the current local time of the first device is updated.
[0120] The first sending module 550 is specifically used to adjust the target confidence level according to a preset method to obtain a second confidence level when it is determined that the current local time of the first device needs to be updated, wherein the second confidence level is less than the target confidence level;
[0121] The second confidence level and its corresponding first synchronization time are processed to obtain the second time data packet.
[0122] In one embodiment, the device further includes: a second sending module, configured to, after sending the second time data packet to other devices, obtain the current local time of the first device and use it as the second synchronization time;
[0123] The difference between the first synchronization time in the first time data packet used when the first device last updated its local time and the current local time of the first device is calculated to obtain the first difference;
[0124] Based on the absolute value of the first difference, a third confidence level corresponding to the second synchronization time is determined, wherein the absolute value of the first difference is negatively correlated with the third confidence level;
[0125] The second synchronization time and its corresponding third confidence level are processed to obtain a third time data packet;
[0126] The third time data packet is sent to other devices.
[0127] In one embodiment, the apparatus further includes: a third sending module, configured to obtain the current local time of the first device and use it as a third synchronization time if it is determined that the current local time of the first device should not be updated;
[0128] Calculate the difference between the first synchronization time in the first time data packet used when the first device last updated its local time and the current local time of the first device to obtain the second difference;
[0129] Based on the absolute value of the second difference, a fourth confidence level corresponding to the third synchronization time is determined, wherein the absolute value of the second difference is negatively correlated with the fourth confidence level;
[0130] The third synchronization time and its corresponding fourth confidence level are processed to obtain the fourth time data packet;
[0131] The fourth time data packet is sent to other devices.
[0132] In one embodiment, the second device is connected to the network, and the first synchronization time is the standard time obtained by the second device when connected to the network.
[0133] It should be noted that the time synchronization device shown in Figure 5 can execute each step in any of the above method embodiments and achieve each process and effect in any of the above method embodiments, which will not be elaborated here.
[0134] Figure 6 is a schematic diagram of an electronic device provided in an embodiment of this application. As shown in Figure 6, the electronic device may include a processor 601 and a memory 602 storing computer program instructions.
[0135] Specifically, the processor 601 may include a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.
[0136] Memory 602 may include a large-capacity storage for information or instructions. For example, and not limitingly, memory 602 may include a hard disk drive (HDD), a floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or a Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, memory 602 may include removable or non-removable (or fixed) media. Where appropriate, memory 602 may be internal or external to the integrated gateway device. In a particular embodiment, memory 602 is a non-volatile solid-state memory. In a particular embodiment, memory 602 includes read-only memory (ROM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (Electrically Programmable ROM, EPROM), an electrically erasable programmable ROM (EEPROM), an electrically alterable ROM (EAROM), or flash memory, or a combination of two or more of these.
[0137] The processor 601 can perform the steps in any of the above method embodiments by reading and executing the computer program instructions stored in the memory 602.
[0138] In one example, the electronic device may also include a transceiver 603 and a bus 604. As shown in FIG6, the processor 601, memory 602 and transceiver 603 are connected via bus 604 and communicate with each other.
[0139] Bus 604 includes hardware, software, or both. For example, and not limitingly, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industrial Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses, or a combination of two or more of these. Where appropriate, bus 604 may include one or more buses. Although specific buses are described and illustrated in embodiments of this application, this application contemplates any suitable bus or interconnect.
[0140] This application also provides a computer-readable storage medium that can store a computer program. When the computer program is executed by a processor, the processor implements the time synchronization method provided in this application.
[0141] The aforementioned storage medium may, for example, include a memory 602 containing computer program instructions, which can be executed by a processor 601 of an electronic device to perform the time synchronization method provided in the embodiments of this application. In one embodiment, the storage medium may be a non-transitory computer-readable storage medium, such as a ROM, random access memory (RAM), compact disc ROM (CD-ROM), magnetic tape, floppy disk, and optical data storage device.
[0142] The above description is merely a specific embodiment of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A time synchronization method applied to a first device, the first device being in an unconnected state, wherein, The method includes: Acquire a first time data packet sent by the second device. The first time data packet includes a first synchronization time and its corresponding first confidence level. The number of first time data packets acquired by the first device at the same time is n, where n is a positive integer. Parse the first time data packet to obtain the first synchronization time and its corresponding first confidence level; Determine the target confidence level based on n first confidence levels; Based on the target confidence level, determine whether to update the current local time of the first device; If it is determined that the current local time of the first device needs to be updated, a second time data packet is generated based on the target confidence level and its corresponding first synchronization time, and the second time data packet is sent to other devices.
2. The method of claim 1, wherein, The step of determining the target confidence level based on n first confidence levels includes: The maximum value among the n first confidence scores is taken as the target confidence score.
3. The method of claim 1, wherein, The step of determining whether to update the current local time of the first device based on the target confidence level includes: If the target confidence level is greater than a preset threshold, then the current local time of the first device is updated.
4. The method of claim 1, wherein, The step of determining whether to update the current local time of the first device based on the target confidence level includes: A first reference confidence level and a reference time interval are obtained, and the first reference confidence level is reduced according to the reference time interval to obtain a second reference confidence level. The first reference confidence level is the first confidence level in the first time data packet used when the first device last updated its local time, and the reference time interval is the time interval between the moment when the first device last updated its local time and the current moment. If the target confidence level is greater than the second reference confidence level, then the current local time of the first device is updated.
5. The method of claim 1, wherein, The step of generating a second time data packet based on the target confidence level and its corresponding first synchronization time includes: The target confidence level is adjusted according to a preset method to obtain a second confidence level, which is less than the target confidence level. The second confidence level and its corresponding first synchronization time are processed to obtain the second time data packet.
6. The method of claim 1, wherein, After sending the second time data packet to other devices, the method further includes: Obtain the current local time of the first device and use it as the second synchronization time; The difference between the first synchronization time in the first time data packet used when the first device last updated its local time and the current local time of the first device is calculated to obtain the first difference; Based on the absolute value of the first difference, a third confidence level corresponding to the second synchronization time is determined, wherein the absolute value of the first difference is negatively correlated with the third confidence level; The second synchronization time and its corresponding third confidence level are processed to obtain a third time data packet; The third time data packet is sent to other devices.
7. The method of claim 1, wherein, If it is determined that the current local time of the first device should not be updated, the method further includes: Obtain the current local time of the first device and use it as the third synchronization time; Calculate the difference between the first synchronization time in the first time data packet used when the first device last updated its local time and the current local time of the first device to obtain the second difference; Based on the absolute value of the second difference, a fourth confidence level corresponding to the third synchronization time is determined, wherein the absolute value of the second difference is negatively correlated with the fourth confidence level; The third synchronization time and its corresponding fourth confidence level are processed to obtain the fourth time data packet; The fourth time data packet is sent to other devices.
8. The method of any one of claims 1-7, wherein, The second device is connected to the network, and the first synchronization time is the standard time obtained by the second device when connected to the network.
9. A time synchronization apparatus applied to a first device, the first device being in an unconnected state, wherein, The device includes: The first acquisition module is used to acquire a first time data packet sent by the second device. The first time data packet includes a first synchronization time and its corresponding first confidence level. The number of first time data packets acquired by the first device at the same time is n, where n is a positive integer. The first parsing module is used to parse the first time data packet to obtain the first synchronization time and its corresponding first confidence level. The first determining module is used to determine the target confidence level based on n of the first confidence levels; The second determining module is used to determine whether to update the current local time of the first device based on the target confidence level. The first sending module is configured to, upon determining that the current local time of the first device needs to be updated, generate a second time data packet based on the target confidence level and its corresponding first synchronization time, and send the second time data packet to other devices.
10. An electronic device, comprising: The electronic device includes: processor; Memory, used to store executable instructions; The processor is configured to read the executable instructions from the memory and execute the executable instructions to implement the time synchronization method according to any one of claims 1-8.
11. A computer readable storage medium, wherein, The storage medium stores a computer program that, when executed by a processor, causes the processor to implement the time synchronization method according to any one of claims 1-8.
12. A time synchronization system, wherein, The time synchronization system includes: At least one second device, the second device being configured to process the first synchronization time and its corresponding first confidence level to obtain a first time data packet, and to send the first time data packet to the first device; At least one first device is in a non-networked state. The first device is used to acquire the first time data packet sent by the second device. The number of first time data packets acquired by the first device at the same time is n, where n is a positive integer. The first device is also used to parse the first time data packet to obtain the first synchronization time and its corresponding first confidence level. Based on the n first confidence levels, a target confidence level is determined. Based on the target confidence level, it is determined whether to update the current local time of the first device. The first device is also used to generate a second time data packet based on the target confidence level and its corresponding first synchronization time if it is determined to update the current local time of the first device, and send the second time data packet to other devices.