Skip to content

Commit

Permalink
Only update to the EVSE time if later than the ESP32 time.
Browse files Browse the repository at this point in the history
On making a connection to the EVSE we read the time as the EVSE module may have a battery backed RTC or even just it has remained on during reboot.

However it also may not have a useful time set, eg when recovering from a power cut and no battery backed RTC. In ths case there is a race condition between getting the time from NTP and the time from the EVSE. So now we only set to the EVSE time if it is later than the local ESP time.

This fixes NTP not automatically working  #194.
  • Loading branch information
jeremypoulter committed Jul 24, 2021
1 parent dbe4215 commit e59151e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ handleRapiRead()
{
if(RAPI_RESPONSE_OK == ret)
{
struct timeval set_time = { evse_time, 0 };
settimeofday(&set_time, NULL);
time_t local_time = time(NULL);
if(evse_time > local_time) {
struct timeval set_time = { evse_time, 0 };
settimeofday(&set_time, NULL);
}
}
});

Expand Down

0 comments on commit e59151e

Please sign in to comment.