其他分享
首页 > 其他分享> > 获取NTP时间

获取NTP时间

作者:互联网

无线配网 + 获取网络时间

在这里插入图片描述

#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino

//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <CustomWiFiManager.h>         //https://github.com/tzapu/WiFiManager
#include <NTPClient.h>
// change next line to use with another board/shield
#include <ESP8266WiFi.h>
//#include <WiFi.h> // for WiFi shield
//#include <WiFi101.h> // for WiFi 101 shield or MKR1000
#include <WiFiUdp.h>

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "ntp1.aliyun.com",60*60*8, 30*60*1000);
void setup() {
    
    Serial.begin(115200);

    //WiFiManager
    //Local intialization. Once its business is done, there is no need to keep it around
    WiFiManager wifiManager;
    
 wifiManager.autoConnect("密码8个8", "88888888");

    
    //if you get here you have connected to the WiFi
    Serial.println("已经脸连上无线网啦!!");
    
    timeClient.begin();
}

void loop() {
    
    timeClient.update();

  Serial.println(timeClient.getFormattedTime());

  delay(1000);



  
}

标签:shield,NTP,WiFi,60,获取,时间,WiFiManager,include,timeClient
来源: https://blog.csdn.net/weixin_51397215/article/details/117293408