单片机学习小组
直播中

陈超

7年用户 910经验值
私信 关注

请问STM32+ESP8266如何获取网络时间?

请问STM32+ESP8266如何获取网络时间?

回帖(1)

陈妙宙

2022-1-19 09:41:46

方法
不使用ntp服务器,直接GET某个网站;


这里使用GET B站的服务器进行测试;


连接上B站后执行下述程序:


        /* 先定义两个变量 */
    char *http = "GETn";
        char *ipd = NULL;

        /* 发送GET请求 */
        ESP8266_SendData(http,4);
        /* 获取服务器返回的信息 */
        ipd = ESP8266_GetIPD(100);

    printf("rn%srn",ipd);
这个ipd就指向获取到的数据;


获得的内容如下:


HTTP/1.1 400 Bad Request
Server: Tengine
Date: Mon, 21 Dec 2020 08:39:15 GMT
Content-Type: text/html
Content-Length: 568
Connection: close



400 Bad Request


400 Bad Request


Sorry for the inconvenience.

Please report this message and include the following information to us.

Thank you very much!















URL: http://default.bilibili.com
Server: ks-gz-webcdn-02
Date: 2020/12/21 16:39:15


Powered by Tengine
tengine



CLOSED
可以看到倒数第7行就是当前的北京时间;
举报

更多回帖

发帖
×
20
完善资料,
赚取积分