Hello, I am able to read the day, time, from a NTP server. My question is what is the right way to act on the data from the NTP server? I want it to execute a code everytime the information gotten from the NTP is for example equal to (monday, 09:00).
Here is some of my code that uses the time of day to change display brightness:
time_t tnow = time(nullptr);
gmtime_r(&tnow, &timeinfo );
localtime_r(&tnow, &localtimeinfo );
if (TimeZone == UTC) {
sec = timeinfo.tm_sec;
hr = timeinfo.tm_hour;
mn = timeinfo.tm_min;
mon = timeinfo.tm_mon + 1;
da = timeinfo.tm_mday;
}
else if (TimeZone == LOCAL) {
sec = localtimeinfo.tm_sec;
hr = localtimeinfo.tm_hour;
mn = localtimeinfo.tm_min;
mon = localtimeinfo.tm_mon + 1;
da = localtimeinfo.tm_mday;
}
deciSeconds++;
if (deciSeconds > 19) {
deciSeconds = 0;
}
attributeInterval++;
if (attributeInterval > 99) {
attributeInterval = 0;
if (hr >= 7 and hr <= 22) {
module.setBrightness(displayBright);
}
else {
module.setBrightness(displayDim);
}
}
Maybe it will give you some ideas.
You didn't say what processor you're using, so I'll do the same.
You should really, really read this!
I moved your topic out of the "installation and troubleshooting" forum section. It was not appropriate to post it there, do not post there again. There are warnings in that section about inappropriate posting, which you must have seen.
use the Time library to run clock locally and only sync with NTP once an hour or even once in a day.
Sure, I believe when you run configTime() on the ESP32 at least, The NTP update interval is set to a reasonable value by default. I can't recall the exact number but it's something like 20 minutes.
I don't have a board at hand right now. But you can find out from sntp_get_sync_interval(). The signature is in esp_sntp.h:
uint32_t sntp_get_sync_interval(void);
depending on the controller you are using you can define a callback which gets executed each time the clock is getting synced with NTP.
Which Controller are you using?
If it is not an ESP32 or ESP8266 - which code are you using?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.