Last active
December 30, 2018 14:30
-
-
Save copercini/25265bdde2db4fd111db48fba8d96b44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <WiFi.h> | |
#include "time.h" | |
const char* ssid = "ssid"; | |
const char* password = "pass"; | |
const char* ntpServer = "pool.ntp.org"; | |
const long gmtOffset_sec = 3600; | |
const int daylightOffset_sec = 3600; | |
int i = 0; | |
void printLocalTime() | |
{ | |
struct tm timeinfo; | |
if (!getLocalTime(&timeinfo)) { | |
Serial.println("Failed to obtain time"); | |
return; | |
} | |
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); | |
} | |
void setup() | |
{ | |
Serial.begin(115200); | |
//connect to WiFi | |
Serial.printf("Connecting to %s ", ssid); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(" CONNECTED"); | |
//init and get the time | |
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); | |
printLocalTime(); | |
//disconnect WiFi as it's no longer needed | |
WiFi.disconnect(true); | |
WiFi.mode(WIFI_OFF); | |
} | |
void loop() | |
{ | |
delay(1000); | |
printLocalTime(); | |
i++; | |
if (i == 20) { | |
Serial.println("Setting CPU clock to 80Mhz"); | |
setCpuFrequency(80); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment