/* https://garretlab.web.fc2.com/arduino/lab/ntp/ https://www.ei.tohoku.ac.jp/xkozima/lab/espTutorial0wifi.html */ #include const char *ssid = "your-ssid"; const char *password = "your-password"; IPAddress ip; void setup() { /* wifi --dhcp client --connect */ Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(); // Serial.println("IP address:"); // Serial.println(WiFi.localIP()); /* ntpサーバのIPアドレス,FQDNを記述 複数台記述可能 "192.168.xx.xx", "ntp.aaa.com", ... */ configTime(9 * 3600L, 0, "192.168.xx.xx"); } void loop() { struct tm timeInfo; char s[32]; getLocalTime(&timeInfo); sprintf(s, " %04d/%02d/%02d %02d:%02d:%02d", timeInfo.tm_year + 1900, timeInfo.tm_mon + 1, timeInfo.tm_mday, timeInfo.tm_hour, timeInfo.tm_min, timeInfo.tm_sec); /* 現在の時刻をシリアルモニタに表示 */ Serial.println(s); delay(1000); }