zl程序教程

您现在的位置是:首页 >  其他

当前栏目

SimonLiu的ESP8266与AliOS Things 学习教程系列之二十:获取时间戳

教程学习 获取 系列 时间 二十 Esp8266 Things
2023-09-11 14:21:24 时间

欢迎加入交流群: ESP8266 AliOS Things 群 号: 107723112
系列文章目录:
SimonLiu的ESP8266与AliOS Things 学习教程系列目录

AliOS Things获取时间戳有两种方式:

1. 使用MCU底层SDK的sntp协议。

具体实现方法取决于MCU的底层SDK。不再赘述。

2. 使用AliOS Things IOT_Linkkit_Query

实际上在linkkit_example_solo.c已经注册了一个回调:

IOT_RegisterCallback(ITE_TIMESTAMP_REPLY, user_timestamp_reply_event_handler);
static int user_timestamp_reply_event_handler(const char *timestamp)
{
    EXAMPLE_TRACE("Current Timestamp: %s", timestamp);

    return 0;
}

我们只需要发一个Query就可以获取到timestamp字符串了:

IOT_Linkkit_Query(user_example_ctx->master_devid, ITM_MSG_QUERY_TIMESTAMP,NULL, 0);