Internet of Things time calibration method and system based on MQTT protocol

Through the time calibration method based on the MQTT protocol, the terminal device actively requests time calibration, combined with the server-side time deviation detection and dynamic triggering mechanism, the time synchronization problem of IoT devices in a weak network environment is solved, and the time synchronization effect with high accuracy and low overhead is achieved.

CN120357988APending Publication Date: 2025-07-22SHANDONG ARTAPLAY INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510362006.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-26
Publication Date
2025-07-22

AI Technical Summary

Technical Problem

Existing IoT devices have low time synchronization efficiency, high resource consumption and strong passivity in weak network environments, and lack optimization solutions for time calibration.

Method used

The time calibration method based on the MQTT protocol is adopted to realize active time calibration through the collaborative work of the time server, MQTT proxy server and IoT terminal equipment, including the terminal equipment's active request time, server-side time deviation detection and active trigger calibration, combining historical network delay estimation and correction mechanisms.

Benefits of technology

It realizes high-precision and low-overhead time synchronization, and is especially suitable for devices with weak chip processing capabilities, no Linux system, and poor network conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120357988A_ABST
    Figure CN120357988A_ABST
Patent Text Reader

Abstract

The invention discloses an Internet of Things time calibration method and system based on an MQTT protocol, and belongs to the technical field of broadcast link information transmission, the system comprises a time server, an MQTT proxy server and Internet of Things terminal equipment, the time server is used for providing a high-precision time source, an integrated MQTT client, an integrated time monitoring engine and a dynamic trigger strategy; the MQTT proxy server is responsible for message routing and supports theme subscription and publishing; the Internet of Things terminal equipment is internally provided with an MQTT client and supports active triggering of a calibration request; the method is implemented by the following steps: the Internet of Things terminal equipment is started to actively request time; performing server-side time deviation detection; and the server actively triggers calibration. According to the invention, high-precision and low-overhead time synchronization can be realized. Especially for equipment with weak chip processing capability, no linux system and poor network condition, the method has a good time synchronization effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of broadcast link information transmission, and specifically to an Internet of Things time calibration method and system based on the MQTT protocol. Background Art

[0002] Internet of Things devices (such as sensors, smart terminals, etc.) usually require precise time synchronization to support collaborative work, data recording, or event triggering. Traditional time synchronization methods (such as the NTP protocol) have the following problems:

[0003] Strong network dependence: The synchronization efficiency is low in a weak network environment (such as high latency, low bandwidth).

[0004] High resource consumption: The computing power of Internet of Things devices is limited, and traditional protocols may occupy too many resources.

[0005] Passivity: Devices need to poll the time server regularly and cannot adapt to a dynamically changing network environment.

[0006] In the prior art, Internet of Things systems based on MQTT (Message Queuing Telemetry Transport) are mostly used for data transmission, but lack an optimized solution for time calibration. Therefore, there is an urgent need for a lightweight, proactive, and low-latency time calibration method. Summary of the Invention

[0007] The technical task of the present invention is to address the above deficiencies and provide an Internet of Things time calibration method and system based on the MQTT protocol, which can achieve high-precision and low-overhead time synchronization. It has a good time synchronization effect especially for devices with weak chip processing capabilities, no Linux system, and poor network conditions.

[0008] The technical solution adopted by the present invention to solve its technical problems is:

[0009] An Internet of Things time calibration method based on the MQTT protocol, including a time server, an MQTT broker server, and Internet of Things terminal devices,

[0010] The time server is used to provide a high-precision time source, integrate an MQTT client, integrate a time monitoring engine, and a dynamic trigger strategy;

[0011] The MQTT broker server (Broker): is responsible for message routing and supports topic subscription and publication;

[0012] The Internet of Things terminal devices: are built-in with an MQTT client and support proactive triggering of calibration requests;

[0013] The implementation of this method includes the following steps:

[0014] 1) The time when the Internet of Things terminal device actively requests at startup;

[0015] 2) Server-side time deviation detection;

[0016] 3) Server actively triggers calibration.

[0017] This method realizes high-precision and low-overhead time synchronization by the server's real-time analysis of timestamps in the data reported by the Internet of Things terminal device, dynamically triggering calibration instructions, and combining the historical network delay estimation and correction mechanism.

[0018] Furthermore, the time monitoring engine: analyzes the timestamps in the device-reported data in real time and calculates the device time deviation;

[0019] The dynamic policy module: actively initiates calibration instructions according to preset rules (such as the maximum allowable deviation, device priority).

[0020] Furthermore, for the step 1), the specific process is as follows:

[0021] When the device starts up, it actively requests time calibration through MQTT;

[0022] After receiving the request, the time server replies with the current time and records the current sending time A;

[0023] After receiving the reply, the device updates the local time and replies with a confirmation message;

[0024] The server receives the reply message and records the received message time B; calculates the round-trip time RTT (Round-Trip Time) through the difference between time B and time A; the average value of multiple historical RTT times can be used for subsequent transmission delay calculation.

[0025] Furthermore, for the step 2), the specific process is as follows:

[0026] When the device reports normal service data, it implicitly carries the local timestamp (for example, embedded in the metadata of the MQTT message);

[0027] The time server passively receives the timestamp by subscribing to the device service topic (such as device / DEV001 / data) and calculates the deviation from the server time:

[0028] Time deviation = server time - device-reported time - one-way transmission delay.

[0029] Furthermore, the one-way transmission delay can be estimated through the average value of multiple historical RTT times.

[0030] Furthermore, for the step 3), the specific process is as follows:

[0031] If the time deviation exceeds the threshold (such as ±10 s), the time server immediately publishes a calibration instruction to the target device via MQTT and records the current transmission time A;

[0032] After receiving the calibration instruction, the device immediately calculates the correction value and updates the local time or records the deviation, and then replies a confirmation message to the server;

[0033] The server receives the reply message and records the message reception time B; calculates the round-trip time RTT through the difference between time B and time A; the average value of multiple historical RTT times can be used for subsequent transmission delay calculation.

[0034] Furthermore, the process for the terminal device to achieve time calibration is as follows:

[0035] S1. When the device is powered on, it sends an mqtt request to update the time. After receiving the request, the time server of the device management platform issues the time and calculates the RTT round-trip time according to the reply;

[0036] S2. When the user uses the device, the device publishes a device activation event, including the local timestamp T1;

[0037] S3. When the server detects that the deviation between T1 and the server time exceeds the threshold, it immediately issues a calibration instruction;

[0038] S4. The device completes time correction before activation and replies with confirmation;

[0039] S5. The corrected time can be used for subsequent timing / billing.

[0040] The present invention also claims to protect an Internet of Things time calibration system based on the MQTT protocol, including

[0041] A time server, used to provide a high-precision time source, integrated with an MQTT client, integrated with a time monitoring engine and a dynamic trigger strategy;

[0042] An MQTT broker server (Broker): responsible for message routing, supporting topic subscription and publication;

[0043] An Internet of Things terminal device: built-in with an MQTT client, supporting active trigger of calibration requests;

[0044] This system realizes time calibration based on the above method, including:

[0045] 1) The Internet of Things terminal device actively requests time when powered on;

[0046] 2) Server-side time deviation detection;

[0047] 3) Server actively triggers calibration.

[0048] The present invention also claims to protect an implementation device for Internet of Things time calibration based on the MQTT protocol, comprising: at least one memory and at least one processor;

[0049] The at least one memory is used for storing machine-readable programs;

[0050] The at least one processor is used for calling the machine-readable programs to implement the above-mentioned method.

[0051] The present invention also claims to protect a computer-readable medium, on which computer instructions are stored, and when the computer instructions are executed by a processor, the above-mentioned method can be implemented.

[0052] Compared with the prior art, the Internet of Things time calibration method and system based on the MQTT protocol of the present invention have the following beneficial effects:

[0053] The present invention analyzes the timestamps in the data reported by Internet of Things terminal devices in real time through a server, dynamically triggers calibration instructions, and combines the historical network delay estimation and correction mechanism to achieve high-precision and low-overhead time synchronization. In particular, it has a good time synchronization effect for devices with weak chip processing capabilities, no Linux system, and poor network conditions. Description of the Drawings

[0054] Figure 1 is a system architecture diagram of the Internet of Things time calibration method based on the MQTT protocol provided by an embodiment of the present invention;

[0055] Figure 2 is a working process diagram of the time server provided by an embodiment of the present invention. Detailed Embodiments

[0056] The present invention will be further described below in conjunction with specific embodiments.

[0057] An embodiment of the present invention provides an Internet of Things time calibration method based on the MQTT protocol. This method listens to the service data reported by Internet of Things terminal devices and extracts the embedded local timestamps; combines the historical RTT to estimate the one-way delay and calculates the device time deviation; if the deviation exceeds the dynamic threshold, a calibration instruction is sent through the device-specific MQTT topic; Internet of Things terminal devices such as charging piles calculate and correct the time according to the instruction during use, and feedback the calibration result to achieve a good time synchronization effect.

[0058] As Figure 1 shown, the system architecture for implementing this method includes a time server, an MQTT broker server, and Internet of Things terminal devices.

[0059] 1. A time server, which is used to provide a high-precision time source, integrates an MQTT client, a time monitoring engine, and a dynamic trigger policy.

[0060] The time monitoring engine: Analyzes the timestamps in the device-reported data in real time and calculates the device time deviation.

[0061] The dynamic policy module: Initiates a calibration instruction actively according to preset rules (such as the maximum allowable deviation, device priority).

[0062] 2. An MQTT broker server: Responsible for message routing, supporting topic subscription and publication;

[0063] 3. An Internet of Things terminal device: Built-in with an MQTT client, supporting active triggering of calibration requests;

[0064] Combined with Figure 2 As shown, the implementation of this method specifically includes the following steps:

[0065] 1. The Internet of Things terminal device requests time actively when powered on:

[0066] 1.1. When the device is powered on, it actively requests time calibration through MQTT;

[0067] 1.2. After receiving the request, the time server replies with the current time and records the current sending time A;

[0068] 1.3. After receiving the reply, the device updates the local time and replies with a confirmation message;

[0069] 1.4. The server receives the reply message and records the received message time B; calculates the round-trip time RTT through the difference between time B and time A; the average value of multiple historical RTT times can be used for subsequent transmission delay calculation.

[0070] 2. Server-side time deviation detection:

[0071] 2.1. When the device reports normal service data, it implicitly carries the local timestamp (for example, embedded in the metadata of the MQTT message);

[0072] 2.2. The time server subscribes to the device service topic (such as device / DEV001 / data) and passively receives the timestamp, and calculates the deviation from the server time:

[0073] Time deviation = server time - device-reported time - one-way transmission delay.

[0074] Among them, the one-way transmission delay can be estimated through multiple historical RTT data.

[0075] 3. Server actively triggers calibration:

[0076] 3.1. If the time deviation exceeds the threshold (e.g., ±10 s), the time server immediately sends a calibration instruction to the target device via MQTT and records the current sending time A.

[0077] 3.2. After receiving the calibration instruction, the device immediately calculates the correction value and updates the local time or records the deviation, and then sends a confirmation message to the server.

[0078] 3.3. The server receives the reply message and records the received message time B; calculates the round-trip time RTT through the difference between time B and time A; the average value of multiple historical RTT times can be used for subsequent transmission delay calculation.

[0079] The process for the terminal device to achieve time calibration is as follows:

[0080] S1. When the device is powered on, it sends an mqtt request to update the time. After receiving the request, the time server of the device management platform sends the time and calculates the RTT round-trip time based on the reply.

[0081] S2. When the user uses the device, the device publishes a device activation event, including the local timestamp T1.

[0082] S3. When the server detects that the deviation between T1 and the server time exceeds the threshold, it immediately sends a calibration instruction.

[0083] S4. The device completes time correction before activation and replies with confirmation.

[0084] S5. The corrected time can be used for subsequent timing / billing.

[0085] This method can be applied to various mqtt devices such as charging piles, battery detection devices, energy storage devices, etc.

[0086] Taking the charging pile device as an example:

[0087] S1. When the charging pile device is powered on, it sends an mqtt request to update the time. After receiving the request, the time server of the charging pile management platform sends the time and calculates the RTT round-trip time as 1 s based on the reply.

[0088] S2. When the user inserts the charging gun, the charging pile publishes a charging start event (including the local timestamp T1 = 1740000000.000).

[0089] S3. When the server detects that the deviation between T1 and the server time (1740000002.000) is +1.5 s (exceeding the ±1 s threshold), it immediately sends a calibration instruction.

[0090] S4. The charging pile completes time correction before charging starts (before starting to charge) and replies with confirmation.

[0091] S5. The corrected time is used for subsequent billing timing, and the error is controlled within ±1 s.

[0092] An embodiment of the present invention further provides an Internet of Things time calibration system based on the MQTT protocol. This system realizes time calibration based on the Internet of Things time calibration method based on the MQTT protocol described in the above embodiment.

[0093] The system includes:

[0094] 1. A time server, which is used to provide a high-precision time source, integrates an MQTT client, and integrates a time monitoring engine and a dynamic trigger strategy.

[0095] The time monitoring engine: analyzes the timestamps in the device-reported data in real time and calculates the device time deviation.

[0096] The dynamic policy module: actively initiates a calibration instruction according to preset rules (such as the maximum allowable deviation, device priority).

[0097] 2. An MQTT broker server (Broker): responsible for message routing, supporting topic subscription and publication;

[0098] 3. An Internet of Things terminal device: built-in MQTT client, supporting active triggering of calibration requests;

[0099] The steps for this system to realize Internet of Things time calibration include:

[0100] 1. The Internet of Things terminal device actively requests time when it is powered on:

[0101] 1.1. When the device is powered on, it actively requests time calibration through MQTT;

[0102] 1.2. After receiving the request, the time server replies with the current time and records the current sending time A;

[0103] 1.3. After receiving the reply, the device updates its local time and replies with an acknowledgment message;

[0104] 1.4. The server receives the reply message and records the received message time B; calculates the round-trip time RTT through the difference between time B and time A; the average value of multiple historical RTT times can be used for subsequent transmission delay calculation.

[0105] 2. Server-side time deviation detection:

[0106] 2.1. When the device reports normal service data, it implicitly carries its local timestamp (for example, embedded in the metadata of the MQTT message);

[0107] 2.2. The time server passively receives timestamps by subscribing to the device service topic (such as device / DEV001 / data), and calculates the deviation from the server time:

[0108] Time deviation = server time - device reported time - one-way transmission delay.

[0109] Among them, the one-way transmission delay can be estimated through multiple historical RTT data.

[0110] 3. The server actively triggers calibration:

[0111] 3.1. If the time deviation exceeds the threshold (such as ±10s), the time server immediately publishes a calibration instruction to the target device through MQTT and records the current sending time A;

[0112] 3.2. After receiving the calibration instruction, the device immediately calculates the correction value and updates the local time or records the deviation, and then replies a confirmation message to the server;

[0113] 3.3. The server receives the reply message and records the received message time B; calculates the round-trip time RTT through the difference between time B and time A; the average value of multiple historical RTT times can be used for subsequent transmission delay calculation.

[0114] This system can be applied to charging piles, battery detection devices, energy storage devices, etc.

[0115] The embodiment of the present invention also provides an IoT time calibration implementation device based on the MQTT protocol, including: at least one memory and at least one processor;

[0116] The at least one memory is used to store machine-readable programs;

[0117] The at least one processor is used to call the machine-readable program to implement the IoT time calibration method based on the MQTT protocol described in the above embodiment.

[0118] The embodiment of the present invention also provides a computer-readable medium, on which computer instructions are stored. When the computer instructions are executed by a processor, the processor executes the IoT time calibration method based on the MQTT protocol described in the above embodiment. Specifically, a system or device equipped with a storage medium can be provided, on which software program codes for implementing the functions of any one of the above embodiments are stored, and the computer (or CPU or MPU) of the system or device reads and executes the program codes stored in the storage medium.

[0119] In this case, the program code read from the storage medium itself can implement the functions of any one of the above-described embodiments. Therefore, the program code and the storage medium storing the program code constitute a part of the present invention.

[0120] Examples of the storage medium for providing the program code include a floppy disk, a hard disk, a magneto-optical disk, an optical disk (such as a CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), a magnetic tape, a non-volatile memory card, and a ROM. Alternatively, the program code can be downloaded from a server computer via a communication network.

[0121] Furthermore, it should be clear that not only can the functions of any one of the above-described embodiments be implemented by executing the program code read by the computer, but also by causing an operating system or the like operating on the computer based on the instructions of the program code to complete part or all of the actual operations.

[0122] In addition, it can be understood that the program code read from the storage medium is written into the memory provided in an expansion board inserted into the computer or into the memory provided in an expansion unit connected to the computer, and then based on the instructions of the program code, a CPU or the like installed on the expansion board or the expansion unit is caused to execute part or all of the actual operations, thereby implementing the functions of any one of the above-described embodiments.

[0123] The present invention has been described in detail above with reference to the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above-described multiple embodiments, those skilled in the art can know that more embodiments of the present invention can be obtained by combining the code review means in the above different embodiments, and these embodiments are also within the protection scope of the present invention.

Claims

1. An Internet of Things time calibration method based on the MQTT protocol, characterized in that It includes a time server, an MQTT broker server, and Internet of Things (IoT) terminal devices. The time server is used to provide a high-precision time source, integrate an MQTT client, integrate a time monitoring engine, and a dynamic triggering policy. The MQTT broker server is responsible for message routing and supports topic subscription and publication. The IoT terminal devices have an in-built MQTT client and support actively triggering calibration requests. The implementation of this method includes the following steps: 1) When the IoT terminal device powers on, it actively requests time. 2) Server-side time deviation detection. 3) The server actively triggers calibration.

2. The Internet of Things time calibration method based on the MQTT protocol according to claim 1, wherein The time monitoring engine analyzes the timestamps in the device-reported data in real time and calculates the device time deviation. The dynamic policy module actively initiates calibration instructions according to preset rules.

3. A method for calibrating the time of the Internet of Things based on the MQTT protocol according to claim 1, characterized in that, For step 1), the specific process is as follows: When the device powers on, it actively requests time calibration through MQTT. After receiving the request, the time server replies with the current time and records the current sending time A. After receiving the reply, the device updates its local time and replies with an acknowledgement message. The server receives the reply message and records the received message time B. The round-trip time (RTT) is calculated based on the difference between time B and time A. The average value of multiple historical RTT times can be used for subsequent transmission delay calculations.

4. An Internet of Things time calibration method based on the MQTT protocol according to claim 1 or 3, characterized in that, For step 2), the specific process is as follows: When the device reports normal business data, it implicitly carries the local timestamp. The time server passively receives the timestamp by subscribing to the device's business topic and calculates the deviation from the server time: Time deviation = Server time - Device-reported time - One-way transmission delay.

5. The Internet of Things time calibration method based on the MQTT protocol according to claim 4, characterized in that, The one-way transmission delay can be estimated using the average value of multiple historical RTT times.

6. The Internet of Things time calibration method based on the MQTT protocol according to claim 4, characterized in that For step 3), the specific process is as follows: If the time deviation exceeds the threshold, the time server immediately publishes a calibration instruction to the target device through MQTT and records the current sending time A. After receiving the calibration instruction, the device immediately calculates the correction value and updates its local time or records the deviation, and then replies with an acknowledgement message to the server. The server receives the reply message and records the received message time B. The round-trip time (RTT) is calculated based on the difference between time B and time A. The average value of multiple historical RTT times can be used for subsequent transmission delay calculations.

7. A method for calibrating the time of the Internet of Things based on the MQTT protocol according to claim 4, characterized in that, The process for the terminal device to achieve time calibration is as follows: S1. When the device powers on, it sends an MQTT request to update the time. After receiving the request, the time server of the device management platform sends the time and calculates the RTT round-trip time based on the reply. S2. When the user uses the device, the device publishes a device activation event, which includes the local timestamp T1. S3. When the server detects that the deviation between T1 and the server time exceeds the threshold, it immediately sends a calibration instruction. S4. The device completes time correction before activation and replies with an acknowledgement. S5. The corrected time can be used for subsequent timing / charging.

8. An Internet of Things time calibration system based on the MQTT protocol, characterized in that, It includes A time server, which is used to provide a high-precision time source, integrate an MQTT client, integrate a time monitoring engine, and a dynamic triggering policy. An MQTT broker server: responsible for message routing and supporting topic subscription and publication. Internet of Things (IoT) terminal devices: have an in-built MQTT client and support actively triggering calibration requests. The system realizes time calibration based on the method described in claims 1-7, including: 1) The IoT terminal device actively requests time when powered on; 2) The server-side time deviation detection; 3) The server actively triggers calibration.

9. An implementation device for Internet of Things time calibration based on the MQTT protocol, characterized in that, Including: At least one memory and at least one processor; The at least one memory is used to store machine-readable programs; The at least one processor is used to call the machine-readable program to implement the method described in any one of claims 1 to 7.

10. A computer-readable medium, characterized in that, Computer instructions are stored on the computer-readable medium, and when the computer instructions are executed by the processor, the method described in any one of claims 1 to 7 can be implemented.