The NTP feature is mainly used to solve the problem with resource-constrained devices where they don't have the NTP service and thus have no accurate timestamps. The following two topics are required for this feature:
$sys/operation/${ProductId}/${DeviceName}
.$sys/operation/result/${ProductId}/${DeviceName}
.The IoT Hub platform draws on the principles of the NTP protocol and uses the platform itself as an NTP server. After a device requests the platform, the platform will return the NTP time. After the device receives the response, it will calculate the current accurate time based on the request time and receipt time.
The device sends a message in JSON format with the following content to $sys/operation/${ProductId}/${DeviceName}
to request the platform for the NTP time and records the request time deviceSendtime
:
{
"type": "get",
"resource": [
"time"
]
}
The platform returns the NTP time through $sys/operation/result/${ProductId}/${DeviceName}
with a message in JSON format with the following content, and the device records the receipt time deviceRecvtime
:
{
"type": "get",
"time": 1621562342,
"ntptime1": 1621562342773,
"ntptime2": 1621562342773
}
The accurate time is calculated through the NTP time (${ntptime1} + ${ntptime2}) received by the device, receipt time (${deviceRecvtime}), and request time (${deviceSendtime}) as follows:
Accurate time =(${ntptime1} + ${ntptime2} + ${deviceRecvtime} - ${deviceSendtime}) / 2
Was this page helpful?