NTPClientPlus rework, minor improvements.

This commit is contained in:
2023-09-03 14:54:14 +02:00
parent 8598e019d4
commit f402d31be5
3 changed files with 247 additions and 287 deletions

View File

@@ -221,14 +221,14 @@ void setup()
}
// setup NTP
ntp_client.setupNTPClient();
ntp_client.setup_ntp_client();
logger.log_string("NTP running");
logger.log_string("Time: " + ntp_client.getFormattedTime());
logger.log_string("TimeOffset (seconds): " + String(ntp_client.getTimeOffset()));
logger.log_string("Time: " + ntp_client.get_formatted_time());
logger.log_string("TimeOffset (seconds): " + String(ntp_client.get_time_offset()));
// show the current time for short time in words
int hours = ntp_client.getHours24();
int minutes = ntp_client.getMinutes();
int hours = ntp_client.get_hours_24();
int minutes = ntp_client.get_minutes();
String timeMessage = time_to_string(hours, minutes);
show_string_on_clock(timeMessage, main_color_clock);
draw_minute_indicator(minutes, main_color_clock);
@@ -358,8 +358,8 @@ void handle_current_state()
{
case ST_CLOCK: // state clock
{
int hours = ntp_client.getHours24();
int minutes = ntp_client.getMinutes();
int hours = ntp_client.get_hours_24();
int minutes = ntp_client.get_minutes();
(void)show_string_on_clock(time_to_string((uint8_t)hours, (uint8_t)minutes), main_color_clock);
draw_minute_indicator((uint8_t)minutes, main_color_clock);
@@ -367,8 +367,8 @@ void handle_current_state()
}
case ST_DICLOCK: // state diclock
{
int hours = ntp_client.getHours24();
int minutes = ntp_client.getMinutes();
int hours = ntp_client.get_hours_24();
int minutes = ntp_client.get_minutes();
show_digital_clock((uint8_t)hours, (uint8_t)minutes, main_color_clock);
break;
}
@@ -455,9 +455,8 @@ void update_matrix()
*/
void send_heartbeat()
{
logger.log_string("Heartbeat, state: " + state_names[current_state] + ", FreeHeap: " + ESP.getFreeHeap() +
", HeapFrag: " + ESP.getHeapFragmentation() + ", MaxFreeBlock: " + ESP.getMaxFreeBlockSize() +
"\nCounter: " + heartbeat_counter + ", Hours: " + (float)(heartbeat_counter) / 3600.0 + "\n");
logger.log_string("Heartbeat, current state: " + state_names[current_state] + ", counter: " +
heartbeat_counter + ", on-time: " + (float)(heartbeat_counter) / 3600.0 + "h\n");
heartbeat_counter++;
}
@@ -483,8 +482,8 @@ void check_wifi_status()
void check_night_mode()
{
// check if nightmode need to be activated
int hours = ntp_client.getHours24();
int minutes = ntp_client.getMinutes();
int hours = ntp_client.get_hours_24();
int minutes = ntp_client.get_minutes();
if (hours == night_mode_times.start_hour && minutes == night_mode_times.start_min)
{
@@ -504,18 +503,14 @@ void check_night_mode()
void ntp_time_update(uint32 *last_ntp_update_us)
{
// NTP time update
int ntp_retval = ntp_client.updateNTP();
int ntp_retval = ntp_client.update_ntp();
switch (ntp_retval)
{
case NTP_UPDATE_SUCCESS:
{
ntp_client.calcDate();
logger.log_string("NTP-Update successful");
logger.log_string("Time: " + ntp_client.getFormattedTime());
logger.log_string("Date: " + ntp_client.getFormattedDate());
logger.log_string("TimeOffset (seconds): " + String(ntp_client.getTimeOffset()));
logger.log_string("Summertime: " + String(ntp_client.updateSWChange()));
ntp_client.calc_date();
logger.log_string("NTP-Update successful, Time: " + ntp_client.get_formatted_time());
*last_ntp_update_us = system_get_time();
watchdog_counter = 30;
break;
@@ -530,10 +525,10 @@ void ntp_time_update(uint32 *last_ntp_update_us)
case NTP_UPDATE_DIFFTOOHIGH:
{
logger.log_string("NTP-Update not successful. Reason: Too large time difference");
logger.log_string("Time: " + ntp_client.getFormattedTime());
logger.log_string("Date: " + ntp_client.getFormattedDate());
logger.log_string("TimeOffset (seconds): " + String(ntp_client.getTimeOffset()));
logger.log_string("Summertime: " + String(ntp_client.updateSWChange()));
logger.log_string("Time: " + ntp_client.get_formatted_time());
logger.log_string("Date: " + ntp_client.get_formatted_date());
logger.log_string("TimeOffset (seconds): " + String(ntp_client.get_time_offset()));
logger.log_string("Summertime: " + String(ntp_client.update_sw_change()));
*last_ntp_update_us += 10000000;
watchdog_counter--;
break;
@@ -548,7 +543,7 @@ void ntp_time_update(uint32 *last_ntp_update_us)
}
}
logger.log_string("Watchdog Counter: " + String(watchdog_counter));
logger.log_string("Watchdog counter: " + String(watchdog_counter));
if (watchdog_counter <= 0)
{
logger.log_string("Trigger restart due to watchdog...");