Skip to content

Commit

Permalink
bugfix clock draw
Browse files Browse the repository at this point in the history
fixes the display error of the clock when the ntp server is not reached.
  • Loading branch information
o0shojo0o committed Sep 14, 2021
1 parent 6f7c0e3 commit 1c09194
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ At the moment there is also a Node-Red Node ([node-red-contrib-pixelit](https://
### **WORK IN PROGRESS**
-->

### 0.3.10 (2021-09-14)

- (o0shojo0o) bugfix clock draw

### 0.3.9 (2021-09-02)

- (o0shojo0o) bugfix auto brightness, to high values
Expand Down
31 changes: 20 additions & 11 deletions src/PixelIt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const int MQTT_RECONNECT_INTERVAL = 5000;
#define NUMMATRIX (32 * 8)
CRGB leds[NUMMATRIX];

#define VERSION "0.3.9"
#define VERSION "0.3.10"

#if defined(ESP32)
TwoWire twowire(BME280_ADDRESS_ALTERNATE);
Expand Down Expand Up @@ -154,8 +154,10 @@ uint16_t bmpArray[64];

// Timerserver Vars
String ntpServer = "de.pool.ntp.org";
int ntpRetryCounter = 0;
uint ntpRetryCounter = 0;
uint ntpTimeOut = 0;
#define NTP_MAX_RETRYS 3
#define NTP_TIMEOUT_SEC 60

// Clock Vars
bool clockBlink = false;
Expand Down Expand Up @@ -2120,18 +2122,24 @@ void loop()
clockAktiv = true;
}

if (clockAktiv && now() != clockLastUpdate && ntpRetryCounter < NTP_MAX_RETRYS)
if (clockAktiv && now() != clockLastUpdate)
{
if (timeStatus() != timeNotSet)
if (timeStatus() == timeNotSet && ntpTimeOut <= millis())
{
clockLastUpdate = now();
DrawClock(false);
}
else
{
Log(F("Sync TimeServer"), ntpServer + " waiting for sync");
setSyncProvider(getNtpTime);
if (ntpRetryCounter >= NTP_MAX_RETRYS)
{
ntpTimeOut = (millis() + (NTP_TIMEOUT_SEC * 1000));
ntpRetryCounter = 0;
Log(F("Sync TimeServer"), "sync timeout for " + String(NTP_TIMEOUT_SEC) + " seconds!");
}
else
{
Log(F("Sync TimeServer"), ntpServer + " waiting for sync");
setSyncProvider(getNtpTime);
}
}
clockLastUpdate = now();
DrawClock(false);
}

if (millis() - sendLuxPrevMillis >= 1000)
Expand Down Expand Up @@ -2334,6 +2342,7 @@ time_t getNtpTime()
time_t secsSince1970 = secsSince1900 - 2208988800UL;
float totalOffset = (clockTimeZone + DSToffset(secsSince1970, clockTimeZone));
return secsSince1970 + (time_t)(totalOffset * SECS_PER_HOUR);
ntpRetryCounter = 0;
}
yield();
}
Expand Down

0 comments on commit 1c09194

Please sign in to comment.