bclose

Time setting

Programa para poner en hora el ESP8266 a traves de WIFI

#include <ESP8266WiFi.h>
#include <time.h>

const char* ssid = "REDLINEB";
const char* password = "contrase";

int timezone = 1;
int dst = 0;

void setup() {
 Serial.begin(115200);
 Serial.setDebugOutput(true);

WiFi.mode(WIFI_STA);
 WiFi.begin(ssid, password);
 Serial.println("\nConnecting to WiFi");
 while (WiFi.status() != WL_CONNECTED) {
 Serial.print(".");
 delay(1000);
 }

configTime( timezone * 3600, 0, "pool.ntp.org", "time.nist.gov");
 Serial.println("\nWaiting for time");
 while (!time(nullptr)) {
 Serial.print(".");
 delay(1000);
 }
 Serial.println("");
}

void loop() {
 time_t now = time(nullptr);
 Serial.println(ctime(&now));
 delay(1000);
}