Last active
May 15, 2021 18:16
-
-
Save nishanc/e80b9416abe80ec326304f5db14390b7 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
void setup() { | |
// Everything else | |
startCameraServer(); | |
Serial.print("Camera Ready! Use 'http://"); | |
Serial.print(WiFi.localIP()); | |
Serial.println("' to connect"); | |
// Set system time | |
if (WiFi.status() == WL_CONNECTED) { // Connected to WiFi | |
internet_connected = true; | |
Serial.println("Internet connected"); | |
init_time(); | |
time(&now); | |
// Set timezone to Indian Standard Time | |
setenv("TZ", "UTC-05:30", 1); | |
tzset(); | |
} | |
} | |
void init_time() | |
{ | |
sntp_setoperatingmode(SNTP_OPMODE_POLL); | |
sntp_setservername(0, "pool.ntp.org"); | |
sntp_init(); | |
// wait for time to be set | |
time_t now = 0; | |
timeinfo = { 0 }; | |
int retry = 0; | |
const int retry_count = 10; | |
while (timeinfo.tm_year < (2016 - 1900) && ++retry < retry_count) { | |
Serial.printf("Waiting for system time to be set... (%d/%d)\n", retry, retry_count); | |
delay(2000); | |
time(&now); | |
localtime_r(&now, &timeinfo); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment