Skip to content

Instantly share code, notes, and snippets.

@nishanc
Last active May 15, 2021 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishanc/e80b9416abe80ec326304f5db14390b7 to your computer and use it in GitHub Desktop.
Save nishanc/e80b9416abe80ec326304f5db14390b7 to your computer and use it in GitHub Desktop.
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