获取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);



  
}
上一篇:Ansible部署LAMP官方案例


下一篇:ubuntu作为NTP客户端与windows 2008NTP 服务器同步时间