SDK-v1.3, 文档中代码如下,运行时串口打印提示 "please start sntp first !"
我是在station模式下,获取到ip后执行的,在 user_esp_platform_check_ip()中调用,公网是可用的。
网上看了下公开的sntp.c代码,调用sntp_init()后,代码好像时异步执行的,不知在ESP的sdk中如何处理?
请帮忙,谢谢!
void my_sntp_test2() // change sntp server, tested pass on win7
{
// 202.120.2.101 (上海交通大学网络中心NTP服务器地址)
// 3.cn.pool.ntp.org 202.112.29.82
// 3.tw.pool.ntp.org 120.119.28.1
//uint8 ip0 = {210.72.145.44};//210.72.145.44 (国家授时中心服务器IP地址)
ip_addr_t ip0, ip1, ip2;
IP4_ADDR(&ip0, 202, 120, 2, 101);
IP4_ADDR(&ip1, 202,112,29,82);
IP4_ADDR(&ip2, 120, 119, 28, 1);
sntp_setserver(0, &ip0);
sntp_setserver(1, &ip1);
sntp_setserver(2, &ip2);
sntp_init();
uint32 current_stamp;
current_stamp = sntp_get_current_timestamp();
os_printf(">>>>>>>>>1111>>>>>>sntp: %d, %s \n",current_stamp, sntp_get_real_time(current_stamp));
}
void my_sntp_test() // copy from sdk-doc
{
ip_addr_t *addr = (ip_addr_t *)os_zalloc(sizeof(ip_addr_t));
sntp_setservername(0, "us.pool.ntp.org"); // set server 0 by domain name
sntp_setservername(1, "ntp.sjtu.edu.cn"); // set server 1 by domain name
ipaddr_aton("210.72.145.44", addr);
sntp_setserver(2, addr); // set server 2 by IP address
sntp_init();
os_free(addr);
uint32 current_stamp;
current_stamp = sntp_get_current_timestamp();
os_printf(">>>>>>>>>>>>>>>>>>>>>>>sntp: %d, %s \n",current_stamp, sntp_get_real_time(current_stamp));
}
-----------------
log:
connected with my_ssid, channel 1
dhcp client start...
ip:192.168.1.106,mask:255.255.255.0,gw:192.168.1.1
please start sntp first !
>>>>>>>>>>>>>>>>>>>>>>>sntp: 0, Thu Jan 01 00:00:00 1970
拷贝运行sdk文档中的 SNTP示例代码,失败,不能获取时钟?
Who is online
Users browsing this forum: No registered users and 27 guests
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.