wifi获取互联网时间
支持芯片: ESP32-S3系列
void wifi_sntp(str host,"CST-8");
//host: sntp服务器地址
//"CST-8"表示时区8,也就是北京时间
本函数是一个异步调用函数,wifi_sntp()被调用后,会立即向后执行,在获取信息后,会调用void app.onWIFI32(int m);判断m==5后就表示已经同步了网络时间
常用sntp服务器地址(参考,以提供服务的官网为准):
服务器地址 | 说明 |
---|---|
cn.pool.ntp.org | NTP中国开发联盟 |
ntp.sjtu.edu.cn | 教育网 |
ntp.njupt.edu.cn | 教育网 |
ntp.neu.edu.cn | 教育网 |
ntp.aliyun.com | 阿里云服务器(推荐) |
有关的wifi_getinfo参数
编号 | 内容 | 描述 | |
---|---|---|---|
0 | wifi_m | WIFI事件编号,此时==5 | |
1 | buf | str | 字符串信息交换,SNTP完成时的字符串提示信息 |
10 | ps1 | sntp服务器地址,传入字符串 | |
11 | ps2 | 时区,传入字符串 |
示例
class s3=loadcom(skinbutton);
void app.onWIFI32(int m){
if (m==5){
//wifi_sntp 完成
}
}
void s3.onclick()
{
wifi_sntp("ntp.aliyun.com","CST-8");
}
start();