Time synchronization method and device of Internet of Things terminal, and storage medium
By determining the difference between data acquisition and writing time in the Internet of Things terminal and comparing it with the time error threshold, obtaining the latest time information and synchronizing it, the problem of low time synchronization efficiency of IoT terminals is solved, and fast and accurate time synchronization is achieved.
Patent Information
- Application Number
- CN202411819550.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-11
- Publication Date
- 2025-03-18
AI Technical Summary
When the terminal types and number of existing IoT terminals are large, the management and maintenance workload is large and easy to be misconfigured, resulting in low time synchronization efficiency.
By determining the time difference between the data acquisition time and the data writing time, comparing it with the time error threshold, obtaining the latest time information of the time synchronization server, and sending it to the Internet of Things terminal to synchronize the clock time.
It realizes rapid and accurate time synchronization in complex scenarios, improves time synchronization efficiency, and avoids economic losses caused by time offset.
Smart Images

Figure CN119652460A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of time synchronization, and in particular to a time synchronization method, device and storage medium for an Internet of Things terminal. Background Art
[0002] Different devices in the Internet of Things have different performance and working modes, resulting in differences in their time information. Ensuring the synchronization of time information is a prerequisite for the collaborative work of the Internet of Things, and is also an important means to ensure the time consistency of each device in the Internet of Things system. Therefore, the normal operation of the Internet of Things platform must match the corresponding time synchronization mechanism, by synchronizing the time information in different devices to a standard time base to ensure the time consistency between devices. This mechanism plays a vital role in the normal operation of the Internet of Things system, data consistency and accuracy, and collaborative work.
[0003] The existing time synchronization method for IoT terminals is usually to synchronize time information from multiple slave devices (IoT terminals) by a time server (usually a high-precision time source, such as GPS / BD or network time server). In this way, the time server serves as the time reference, and sends time information from the server to the terminal regularly or as needed. The terminal receives and adjusts its own time to keep synchronization. However, when there are many types and numbers of IoT terminals, the workload of management and maintenance is very large, and it is easy to input configuration information incorrectly, resulting in time synchronization failure, resulting in low efficiency of time synchronization. Summary of the invention
[0004] The present invention provides a time synchronization method, device and storage medium for an Internet of Things terminal, so as to solve the technical problems that when the types and number of Internet of Things terminals are large, the workload of management and maintenance is very large, and it is easy to input configuration information incorrectly, resulting in time synchronization failure, resulting in low time synchronization efficiency.
[0005] The present invention provides a time synchronization method for an Internet of Things terminal, comprising:
[0006] Determine the time difference between the data collection time and the data writing time;
[0007] Compare the time difference with the time error threshold, and when the time difference is greater than or equal to the time error threshold, obtain the latest time information of the time synchronization server;
[0008] The latest time information is sent to the Internet of Things terminal, so that when the Internet of Things terminal receives the time update command, the clock time is synchronized based on the latest time information.
[0009] Furthermore, before determining the time difference between the data collection time and the data writing time, the method further includes:
[0010] Parse the collected data uploaded by the IoT terminal to obtain the data collection time;
[0011] When the collected data is written into the database, the data writing time of the collected data is obtained.
[0012] Furthermore, the determination of the time error threshold value includes:
[0013] Get the time data set of the preset time period;
[0014] The difference between two adjacent data collection times in the time data set is used as the collection frequency;
[0015] A time error threshold is determined according to the acquisition frequency.
[0016] Further, determining the time error threshold value according to the acquisition frequency includes:
[0017] When the preset ratio value of the acquisition frequency is less than or equal to the preset time value, the preset ratio value of the acquisition frequency is used as the time error threshold value.
[0018] Furthermore, after sending the latest time information to the IoT terminal, the method further includes:
[0019] According to the time error threshold, the current data collection time is revised to a reasonable time, wherein the time difference between the reasonable time and the data writing time is less than the time error threshold.
[0020] The present invention also provides a time synchronization device for an Internet of Things terminal, comprising:
[0021] A time difference determination module, used to determine the time difference between the data collection time and the data writing time;
[0022] The latest time information acquisition module is used to compare the time difference with the time error threshold, and when the time difference is greater than or equal to the time error threshold, acquire the latest time information of the time synchronization server;
[0023] The time synchronization module is used to send the latest time information to the Internet of Things terminal, so that the Internet of Things terminal synchronizes the clock time based on the latest time information when receiving the time update command.
[0024] Furthermore, the time synchronization device of the Internet of Things terminal also includes a data time acquisition module, which is used to:
[0025] Parse the collected data uploaded by the IoT terminal to obtain the data collection time;
[0026] When the collected data is written into the database, the data writing time of the collected data is obtained.
[0027] Furthermore, the latest time information acquisition module is also used to:
[0028] Get the time data set of the preset time period;
[0029] The difference between two adjacent data collection times in the time data set is used as the collection frequency;
[0030] A time error threshold is determined according to the acquisition frequency.
[0031] The present invention also provides a terminal device, comprising: a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, and when the processor executes the computer program, the time synchronization method of the Internet of Things terminal as described above is implemented.
[0032] The present invention also provides a computer-readable storage medium, which includes a stored computer program; wherein, when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the time synchronization method for the Internet of Things terminal as described above.
[0033] The embodiment of the present invention compares the time difference between the data collection time and the data writing time with the time error threshold value to obtain the latest time information when the conditions are met, so that the Internet of Things terminal synchronizes the clock time based on the latest time information when receiving the time update command, and realizes time synchronization by actively monitoring the timestamp of the data reported by the Internet of Things terminal. It does not rely on the NTP protocol, and does not need to send time information from the server to the terminal regularly or as needed to realize time synchronization. Even when the types or quantities of Internet of Things terminals are large, time synchronization can be realized quickly and accurately, thereby effectively improving the time synchronization efficiency, and is suitable for time synchronization of Internet of Things terminals in complex scenarios.
[0034] Furthermore, according to the time error threshold, the current data collection time is revised to a reasonable time, which can ensure that the data corresponding to the current data collection time will not be discarded, thereby ensuring the data value and data continuity, and avoiding economic losses to the enterprise due to time offset of data. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 It is a schematic diagram of a flow chart of a time synchronization method for an Internet of Things terminal provided by an embodiment of the present invention;
[0036] Figure 2is a schematic diagram of a flow chart for determining a time error threshold value provided by an embodiment of the present invention;
[0037] Figure 3 is another flow chart of the time synchronization method for an Internet of Things terminal provided by an embodiment of the present invention;
[0038] Figure 4 It is a schematic diagram of the structure of a time synchronization device for an Internet of Things terminal provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0039] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0040] In the description of this application, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the feature. In the description of this application, unless otherwise specified, "plurality" means two or more.
[0041] In the description of this application, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to specific circumstances.
[0042] See also Figure 1 The present invention provides a time synchronization method for an Internet of Things terminal, comprising:
[0043] S1, determining the time difference between data collection time and data writing time;
[0044] The execution subject of the time synchronization method for an Internet of Things terminal according to an embodiment of the present invention may be a server.
[0045] In the embodiment of the present invention, the server can determine the time difference between the data collection time and the data writing time by acquiring the data uploaded by the IoT terminal, for example:
[0046] The IoT terminal collects data and records the timestamp of the collected data, which is the data collection time. The IoT terminal sends the collected data and the corresponding timestamp to the server of the IoT platform through the wireless communication module or gateway. The server parses the data sent by the IoT terminal to obtain the data collection time.
[0047] On the other hand, when the IoT platform writes the collected data into the time series database, the server system write time is obtained, and the write time is the data write time.
[0048] S2. Compare the time difference with the time error threshold, and when the time difference is greater than or equal to the time error threshold, obtain the latest time information of the time synchronization server;
[0049] In the embodiment of the present invention, the time error threshold is the maximum allowable value of the time difference between the two clocks, that is, the maximum absolute time error. When the time difference is less than the time error threshold, it is determined that time synchronization is not required at the current time, and the time synchronization process ends.
[0050] In the embodiment of the present invention, the time error threshold can be determined and adjusted according to actual needs. When the time difference is greater than or equal to the time error threshold, the time synchronization server calls the NTP time synchronization server, and the NTP time server collects the latest time information according to the internal working mechanism and feeds the latest time information back to the server.
[0051] S3. Send the latest time information to the IoT terminal, so that the IoT terminal synchronizes the clock time based on the latest time information when receiving the time update command.
[0052] In the embodiment of the present invention, the time update command can be set as an automatic command, that is, when the IoT terminal receives the latest time information, the time update command is automatically generated, so that the IoT terminal can synchronize the clock time based on the latest time information at the first time. The time update command can also be generated according to the confirmation information input by the user, for example, when the IoT terminal receives the latest time information, the command confirmation information is generated, and when the user inputs the confirmation time update, the time update command is generated, so that the IoT terminal can synchronize the clock time based on the latest time information.
[0053] In the embodiment of the present invention, all times exceeding the time error threshold can be uniformly recorded to improve the time data management efficiency, and time synchronization can be achieved in a timely manner during the entire execution process. In view of the differences in technical capabilities of IoT terminals, such as the terminal not supporting reverse control time configuration, the administrator can also obtain relevant information in a timely manner through alarms and take additional measures to remedy the situation.
[0054] The embodiment of the present invention compares the time difference between the data collection time and the data writing time with the time error threshold value to obtain the latest time information when the conditions are met, so that the Internet of Things terminal synchronizes the clock time based on the latest time information when receiving the time update command, and realizes time synchronization by actively monitoring the timestamp of the data reported by the Internet of Things terminal. It does not rely on the NTP protocol, and does not need to send time information from the server to the terminal regularly or as needed to realize time synchronization. Even when the types or quantities of Internet of Things terminals are large, time synchronization can be realized quickly and accurately, thereby effectively improving the time synchronization efficiency, and is suitable for time synchronization of Internet of Things terminals in complex scenarios.
[0055] In one embodiment, before determining the time difference between the data collection time and the data writing time, the method further includes:
[0056] Parse the collected data uploaded by the IoT terminal to obtain the data collection time;
[0057] When writing the collected data into the database, the data writing time of the collected data is obtained.
[0058] The embodiments of the present invention monitor the uploaded data and written data of the Internet of Things terminal, and can obtain the data collection time and the data writing time in an active and imperceptible manner, thereby reducing the network and terminal load without adding additional Internet of Things platform resource overhead, thereby effectively improving the efficiency of time data acquisition and time synchronization.
[0059] In one embodiment, determining the time error threshold value includes:
[0060] Get the time data set of the preset time period;
[0061] See also Figure 2 In an embodiment of the present invention, a time data set within the last X hours may be obtained and the time data set may be sorted.
[0062] The difference between the collection times of two adjacent data in the time data set is used as the collection frequency;
[0063] In the embodiment of the present invention, the difference between the data collection times of the two most recent records may be selected as the collection frequency.
[0064] It is understandable that the time data set includes multiple data collection times, that is, multiple collection frequencies can be determined. In the embodiment of the present invention, the minimum collection frequency is used as the current collection frequency.
[0065] The time error threshold is determined according to the acquisition frequency.
[0066] The embodiments of the present invention can adjust the data collection range of the time error threshold value according to the configuration of the server hardware, network, etc., to ensure the balance between system overhead and error control, and can further adjust the time error threshold value according to actual needs after considering the network structure, security settings and delay conditions, so as to further improve the rationality of the time error threshold.
[0067] In one embodiment, determining the time error threshold value according to the acquisition frequency includes:
[0068] When the preset ratio value of the acquisition frequency is less than or equal to the preset time value, the preset ratio value of the acquisition frequency is used as the time error threshold value.
[0069] Please continue reading Figure 2 In the embodiment of the present invention, the preset ratio value and the preset time value can be determined according to actual needs. For example, the preset ratio value can be set to 1 / 3 and the preset time value can be set to 3s.
[0070] In one embodiment, after sending the latest time information to the IoT terminal, the method further includes:
[0071] According to the time error threshold, the current data collection time is revised to a reasonable time, wherein the time difference between the reasonable time and the data writing time is less than the time error threshold.
[0072] In the embodiment of the present invention, in the Internet of Things system, data collection and processing are usually very critical, and the current data collection time may include important information, such as environmental monitoring, industrial control information, etc., which are important for subsequent analysis and decision-making. The embodiment of the present invention amends the current data collection time to a reasonable time based on the time error threshold value, thereby ensuring that the data corresponding to the current data collection time will not be discarded, thereby ensuring the data value and data continuity, and avoiding economic losses to enterprises due to time offset of data.
[0073] See also Figure 3 , is another flow chart of a time synchronization method for an Internet of Things terminal provided by an embodiment of the present invention.
[0074] The implementation of the embodiments of the present invention has the following beneficial effects:
[0075] The embodiment of the present invention compares the time difference between the data collection time and the data writing time with the time error threshold value to obtain the latest time information when the conditions are met, so that the Internet of Things terminal synchronizes the clock time based on the latest time information when receiving the time update command, and realizes time synchronization by actively monitoring the timestamp of the data reported by the Internet of Things terminal. It does not rely on the NTP protocol, and does not need to send time information from the server to the terminal regularly or as needed to realize time synchronization. Even when the types or quantities of Internet of Things terminals are large, time synchronization can be realized quickly and accurately, thereby effectively improving the time synchronization efficiency, and is suitable for time synchronization of Internet of Things terminals in complex scenarios.
[0076] Furthermore, according to the time error threshold, the current data collection time is revised to a reasonable time, which can ensure that the data corresponding to the current data collection time will not be discarded, thereby ensuring the data value and data continuity, and avoiding economic losses to the enterprise due to time offset of data.
[0077] See also Figure 4 Based on the same inventive concept as the above embodiment, the present invention also provides a time synchronization device for an Internet of Things terminal, comprising:
[0078] A time difference determination module 10, used to determine the time difference between the data collection time and the data writing time;
[0079] The latest time information acquisition module 20 is used to compare the time difference with the time error threshold value, and when the time difference is greater than or equal to the time error threshold value, obtain the latest time information of the time synchronization server;
[0080] The time synchronization module 30 is used to send the latest time information to the IoT terminal, so that the IoT terminal synchronizes the clock time based on the latest time information when receiving the time update command.
[0081] In one embodiment, the time synchronization device of the Internet of Things terminal further includes a data time acquisition module, which is used to:
[0082] Parse the collected data uploaded by the IoT terminal to obtain the data collection time;
[0083] When writing the collected data into the database, the data writing time of the collected data is obtained.
[0084] In one embodiment, the latest time information acquisition module is further used to:
[0085] Get the time data set of the preset time period;
[0086] The difference between the collection times of two adjacent data in the time data set is used as the collection frequency;
[0087] The time error threshold is determined according to the acquisition frequency.
[0088] In one embodiment, determining the time error threshold value according to the acquisition frequency includes:
[0089] When the preset ratio value of the acquisition frequency is less than or equal to the preset time value, the preset ratio value of the acquisition frequency is used as the time error threshold value.
[0090] In one embodiment, the time synchronization module 30 is further used to:
[0091] According to the time error threshold, the current data collection time is revised to a reasonable time, wherein the time difference between the reasonable time and the data writing time is less than the time error threshold.
[0092] Accordingly, an embodiment of the present invention further provides a terminal device, comprising: a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, the time synchronization method for an Internet of Things terminal of any one of the above embodiments is implemented.
[0093] The terminal device of this embodiment includes: a processor, a memory, and a computer program and computer instructions stored in the memory and executable on the processor. When the processor executes the computer program, each step in the above embodiment 1 is implemented, for example Figure 1 Alternatively, when the processor executes the computer program, the functions of each module / unit in the above device embodiment, such as the latest time information acquisition module 20, are implemented.
[0094] Exemplarily, the computer program may be divided into one or more modules / units, one or more modules / units are stored in a memory and executed by a processor to complete the present invention. One or more modules / units may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program in a terminal device. For example, the latest time information acquisition module 20 is used to compare the time difference with the time error threshold value, and when the time difference is greater than or equal to the time error threshold value, the latest time information of the time synchronization server is obtained.
[0095] The terminal device may be a computing device such as a desktop computer, a notebook, a PDA, and a cloud server. The terminal device may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that the schematic diagram is merely an example of a terminal device and does not constitute a limitation on the terminal device. The terminal device may include more or fewer components than shown in the diagram, or may combine certain components, or different components. For example, the terminal device may also include an input / output device, a network access device, a bus, etc.
[0096] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the terminal device, and uses various interfaces and lines to connect various parts of the entire terminal device.
[0097] The memory can be used to store computer programs and / or modules. The processor realizes various functions of the terminal device by running or executing the computer programs and / or modules stored in the memory and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application required for a function, etc.; the data storage area can store data created according to the use of the mobile terminal, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0098] Among them, if the module / unit integrated in the terminal device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electric carrier signals and telecommunication signals.
[0099] Accordingly, an embodiment of the present invention further provides a computer-readable storage medium, the computer-readable storage medium including a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the time synchronization method of the Internet of Things terminal of any one of the above embodiments.
[0100] The above specific embodiments further illustrate the purpose, technical solutions and beneficial effects of the present invention. It should be understood that the above are only specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of protection of the present invention.
Claims
1. A time synchronization method for an Internet of Things terminal, characterized in that: include: Determine the time difference between the data collection time and the data writing time; Compare the time difference with the time error threshold, and when the time difference is greater than or equal to the time error threshold, obtain the latest time information of the time synchronization server; The latest time information is sent to the Internet of Things terminal, so that when the Internet of Things terminal receives the time update command, the clock time is synchronized based on the latest time information.
2. The time synchronization method of the Internet of Things terminal according to claim 1, characterized in that: Before determining the time difference between the data acquisition time and the data writing time, the method further includes: Parse the collected data uploaded by the IoT terminal to obtain the data collection time; When the collected data is written into the database, the data writing time of the collected data is obtained.
3. The time synchronization method of the Internet of Things terminal according to claim 1, characterized in that: The determination of the time error threshold value includes: Get the time data set of the preset time period; The difference between two adjacent data collection times in the time data set is used as the collection frequency; A time error threshold is determined according to the acquisition frequency.
4. The time synchronization method of the Internet of Things terminal as claimed in claim 3, characterized in that: The determining of the time error threshold value according to the acquisition frequency includes: When the preset ratio value of the acquisition frequency is less than or equal to the preset time value, the preset ratio value of the acquisition frequency is used as the time error threshold value.
5. The time synchronization method of the Internet of Things terminal according to claim 1, characterized in that: After sending the latest time information to the IoT terminal, the method further includes: According to the time error threshold, the current data collection time is revised to a reasonable time, wherein the time difference between the reasonable time and the data writing time is less than the time error threshold.
6. A time synchronization device for an Internet of Things terminal, characterized in that: include: A time difference determination module, used to determine the time difference between the data collection time and the data writing time; The latest time information acquisition module is used to compare the time difference with the time error threshold, and when the time difference is greater than or equal to the time error threshold, acquire the latest time information of the time synchronization server; The time synchronization module is used to send the latest time information to the Internet of Things terminal, so that the Internet of Things terminal synchronizes the clock time based on the latest time information when receiving the time update command.
7. The time synchronization device for an Internet of Things terminal as claimed in claim 6, characterized in that: It also includes a data time acquisition module for: Parse the collected data uploaded by the IoT terminal to obtain the data collection time; When the collected data is written into the database, the data writing time of the collected data is obtained.
8. The time synchronization device for an Internet of Things terminal as claimed in claim 6, characterized in that: The latest time information acquisition module is also used for: Get the time data set of the preset time period; The difference between two adjacent data collection times in the time data set is used as the collection frequency; A time error threshold is determined according to the acquisition frequency.
9. A terminal device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, the time synchronization method for an Internet of Things terminal as described in any one of claims 1 to 5 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program; wherein, when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the time synchronization method for an Internet of Things terminal according to any one of claims 1 to 5.