added comments for ntpManager

This commit is contained in:
Sebastian 2020-07-22 16:52:15 +02:00
parent 93561d4273
commit 80b6e5269f

View File

@ -1,14 +1,19 @@
#include <header.h>
// Url to ntp server
const char* ntpServer = "pool.ntp.org";
// Time offset based on gmt in seconds
const long gmtOffset_sec = 3600;
// Offset in seconds for daylight saving time
const int daylightOffset_sec = 3600;
// start and end hour of the date
// Start and end hour of the date
const int dayStart = 8;
const int dayEnd = 20;
// Time info structure comes from time.h
struct tm timeinfo;
// If wifi is connected configure time of esp32
void setupNTP() {
if (WiFi.isConnected()) {
Serial.println("WiFi OK. Getting Timestamp");
@ -17,6 +22,7 @@ void setupNTP() {
}
}
// Method to check if it is currently day or night
bool checkForDay() {
printTimestamp();
if((getCurrentHour() > dayStart) && (getCurrentHour() < dayEnd)) {
@ -27,11 +33,13 @@ bool checkForDay() {
}
}
// Method to get current hour in 24 hour format
int getCurrentHour() {
int currentHour = timeinfo.tm_hour;
return currentHour;
}
// Method to print a timestamp
void printTimestamp() {
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");