DISCLAIMER
Please note that all content presented on this page is provided by Tuya (HK) Limited. Alibaba Cloud makes no representations and warranties, explicit or implied, as to the authenticity or accuracy of any such content, nor makes any guarantee to the condition, quality, durability, performance, reliability, merchantability or fitness for a particular purpose, or non-infringement of any products and/or services made available by Tuya (HK) Limited.
The IoT platform provides NTP services to solve the problem that the server time cannot be obtained in real time for resource-constrained embedded devices. Principle Introduction The NTP service of IoT platform uses IoT platform as an NTP server based on the principle of NTP protocol. The high-precision time correction process is as follows: 1 The device sends messages to IoT platform through the specified Topic, which carries the sending time deviceSendTime . 2 After IoT Platform receives a device-side message, the time to receive the message is increased in the reply message. serverRecvTime and the time to reply to the message serverSendTime . 3 When the device receives a reply from the IoT platform, it will give the time to receive the reply based on the local time. deviceRecvTime . 4 According to the above four times, calculate the time difference between the device and the Internet of Things platform, and obtain the current accurate time obtained by the device and the server. Time .
Important The device can perform time calibration through the NTP service only after the device is successfully connected to IoT platform. If the embedded device is not connected to the IoT platform and cannot use the NTP service to perform time calibration after the device is powered on, the certificate time verification fails during the TSL connection process.
Communication Topic Upstream (Alink JSON). The device requests a timestamp from the cloud. Request Topic: /ext/ntp/${ProductID}/${HardwareID}/request Response Topic: /ext/ntp/${ProductID}/${HardwareID}/response Among them, ${ ProductID } and ${ HardwareID } is the ProductID and HardwareID in the device Certificate, you can ioT Platform Consoleof equipment Details page acquisition. Request data format:
{
"deviceSendTime":"1571724098000"
}Response data format:
{
"deviceSendTime":"1571724098000",
"serverRecvTime":"1571724098110",
"serverSendTime":"1571724098115"
}How to use 1 The device calculates the exact Unix time of the server. Assuming that the request-based delay is the same as the response-based delay, and the time When the device receives the server is ${deviceRecvTime}, the exact time on the device is: (${serverRecvTime}+${serverSendTime}+${deviceRecvTime}-${deviceSendTime})/2 2 If the device does not have a timestamp, you can send an empty request. Device empty object request.
{
}The platform returns a timestamp.
{
"serverRecvTime":"1571724098110",
"serverSendTime":"1571724098115"
}If the device does not require high time accuracy (allowing an error of 10ms to 30ms), you can directly use serverRecvTime or serverSendTime.