added comments for ntpManager
This commit is contained in:
parent
93561d4273
commit
80b6e5269f
@ -1,14 +1,19 @@
|
|||||||
#include <header.h>
|
#include <header.h>
|
||||||
|
|
||||||
|
// Url to ntp server
|
||||||
const char* ntpServer = "pool.ntp.org";
|
const char* ntpServer = "pool.ntp.org";
|
||||||
|
// Time offset based on gmt in seconds
|
||||||
const long gmtOffset_sec = 3600;
|
const long gmtOffset_sec = 3600;
|
||||||
|
// Offset in seconds for daylight saving time
|
||||||
const int daylightOffset_sec = 3600;
|
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 dayStart = 8;
|
||||||
const int dayEnd = 20;
|
const int dayEnd = 20;
|
||||||
|
// Time info structure comes from time.h
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
|
|
||||||
|
// If wifi is connected configure time of esp32
|
||||||
void setupNTP() {
|
void setupNTP() {
|
||||||
if (WiFi.isConnected()) {
|
if (WiFi.isConnected()) {
|
||||||
Serial.println("WiFi OK. Getting Timestamp");
|
Serial.println("WiFi OK. Getting Timestamp");
|
||||||
@ -17,6 +22,7 @@ void setupNTP() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Method to check if it is currently day or night
|
||||||
bool checkForDay() {
|
bool checkForDay() {
|
||||||
printTimestamp();
|
printTimestamp();
|
||||||
if((getCurrentHour() > dayStart) && (getCurrentHour() < dayEnd)) {
|
if((getCurrentHour() > dayStart) && (getCurrentHour() < dayEnd)) {
|
||||||
@ -27,11 +33,13 @@ bool checkForDay() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Method to get current hour in 24 hour format
|
||||||
int getCurrentHour() {
|
int getCurrentHour() {
|
||||||
int currentHour = timeinfo.tm_hour;
|
int currentHour = timeinfo.tm_hour;
|
||||||
return currentHour;
|
return currentHour;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Method to print a timestamp
|
||||||
void printTimestamp() {
|
void printTimestamp() {
|
||||||
if(!getLocalTime(&timeinfo)){
|
if(!getLocalTime(&timeinfo)){
|
||||||
Serial.println("Failed to obtain time");
|
Serial.println("Failed to obtain time");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user