@@ -58,9 +58,9 @@ void RuntimeClass::loop(void)
5858
5959/*
6060 * Writes the runtime data to LittleFS file
61- * freezeTime : Minimum necessary time [minutes] between now and last write operation
61+ * freezeMinutes : Minimum necessary time [minutes] between now and last write operation
6262 */
63- bool RuntimeClass::write (uint16_t const freezeTime )
63+ bool RuntimeClass::write (uint16_t const freezeMinutes )
6464{
6565 auto cleanExit = [this ](const bool writeOk, const char * text) -> bool {
6666 if (writeOk) {
@@ -81,7 +81,7 @@ bool RuntimeClass::write(uint16_t const freezeTime)
8181 std::lock_guard<std::mutex> lock (_mutex);
8282
8383 // we do not write more than once in a hour
84- if ((_writeEpoch != 0 ) && (difftime (nextEpoch, _writeEpoch) < 60 * freezeTime )) {
84+ if ((_writeEpoch != 0 ) && (difftime (nextEpoch, _writeEpoch) < 60 * freezeMinutes )) {
8585 return cleanExit (false , " Time interval between 2 write operations too short, skipping write" );
8686 }
8787 nextCount = _writeCount + 1 ;
@@ -193,7 +193,8 @@ String RuntimeClass::getWriteCountAndTimeString(void) const
193193 char buf[32 ] = " " ;
194194 struct tm time;
195195
196- // Check if time service is available before converting epoch to local time
196+ // Before we can convert the epoch to local time, we need to ensure we've received the correct time
197+ // from the time server. This may take some time after the system boots.
197198 if ((_writeEpoch != 0 ) && (getLocalTime (&time, 5 ))) {
198199 localtime_r (&_writeEpoch, &time);
199200 strftime (buf, sizeof (buf), " / %d-%h %R" , &time);
@@ -207,9 +208,9 @@ String RuntimeClass::getWriteCountAndTimeString(void) const
207208
208209/*
209210 * Returns true at the daily trigger time at 00:05
210- * Note: This function is not protected by a mutex, but if it is only called by loop() and loop() is only executed on a single thread, we are safe
211211 */
212212bool RuntimeClass::getWriteTrigger (void ) {
213+ std::lock_guard<std::mutex> lock (_mutex);
213214 struct tm actTime;
214215 if (getLocalTime (&actTime, 5 )) {
215216 if ((actTime.tm_hour == 0 ) && (actTime.tm_min >= 5 ) && (actTime.tm_min <= 10 )) {
0 commit comments