This commit is contained in:
Nicu Hodos 2020-05-12 20:29:00 +02:00
parent d2b0bc4fd6
commit 611124d166

View File

@ -16,7 +16,7 @@
#define TIME_24_HOUR
#define DISPLAY_ADDRESS 0x70
#define BRIGHTNESS 7
#define BRIGHTNESS 1
//##########################################################################
// Globals
@ -46,7 +46,6 @@ NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", tzOffset*3600);
void setup() {
Serial.begin(9600); // Start the serial console
Serial.println("Clock starting!"); // Start the clock message.
wifiMulti.addAP("vulturul", "***REMOVED***");
wifiMulti.addAP("Miracle", "***REMOVED***");
@ -69,7 +68,7 @@ void setup() {
void loop() {
ArduinoOTA.handle();
if (shouldUpdate && timeClient.forceUpdate()) {
if (shouldUpdate && WiFi.status() == WL_CONNECTED && timeClient.forceUpdate()) {
shouldUpdate = false;
hours = timeClient.getHours();
minutes = timeClient.getMinutes();
@ -83,16 +82,14 @@ void loop() {
}
void incrementTime() {
seconds++;
if (seconds == 60) {
if (++seconds == 60) {
seconds = 0;
minutes++;
if (((minutes % 5) == 0)) shouldUpdate = true;
if (minutes == 60) {
if (++minutes == 60) {
minutes = 0;
Serial.println("Minutes set to zero - should query NTP on next loop()");
hours = ++hours % 24;
if (++hours == 24) hours = 0;
}
if (((minutes % 5) == 0)) shouldUpdate = true;
}
}