Connect to Alibaba Cloud to obtain network time based on STM32+MQTT
Note: This time obtaining the network time from Alibaba Cloud is based on the previous chapter (connecting to Alibaba Cloud based on STM32+FreeRtos+DHT12+ESP8266+MQTT (link: link .) ) .
1. Process description
2. Process analysis
2.1. Connect to the router
First connect to the router (wifi), and after getting the network status, connect to the server.
2.2.Connect to the server
After the network connection is successful, connect to the Alibaba Cloud platform server and get the connection receipt.
2.3. Subscribe to NTP clock synchronization response
After connecting to the server, we start subscribing to the NTP clock synchronization response for later issuing NTP clock synchronization requests and obtaining timestamps.
2.4. Publish NTP clock synchronization request
After subscribing to the NTP clock synchronization response, we start to publish the NTP clock synchronization request and wait for the server to return a timestamp.
2.5. Server returns data
Receive data returned by the server:
{
"deviceSendTime":"1592361428000","serverSendTime":"1645599995121","serverRecvTime":"1645599995121"}
Then parse the data and get the timestamp returned by the service.
2.6. Convert network timestamp to Beijing time (note time zone: 8)
3. The actual picture is as follows