@@ -289,11 +289,11 @@ void handleHumidity(float humidity, float desiredHumidity, const char* mode) {
289289void controlLights () {
290290 DateTime now = getCurrentTime ();
291291 int hour = now.hour ();
292-
293292 bool lightsOn = false ;
294293
295294 if (FLOWER) {
296295 // Flower mode
296+ Serial.printf (" Humidity too low in %s mode! Turning on humidifier...\n " , mode); //
297297 lightsOn = (hour >= LIGHTS_ON_HOUR_FLOWER_ON || hour < LIGHTS_OFF_HOUR_FLOWER_ON);
298298 } else {
299299 // Vegetative mode
@@ -543,6 +543,7 @@ void loop() {
543543 static unsigned long lastWiFiCheck = 0 ;
544544 static unsigned long lastBitmapCheck = 0 ;
545545 static unsigned long lastPlugCheck = 0 ;
546+ static unsigned long lastLightCheck = 0 ;
546547 unsigned long lastNTPUpdate = 0 ;
547548 unsigned long currentTime = millis ();
548549
@@ -607,13 +608,18 @@ void loop() {
607608 handleHumidity (humidity, desiredHumidity, mode);
608609 }
609610
610- // Periodically sync with NTP
611- if (WiFi.status () == WL_CONNECTED && millis () - lastNTPUpdate > ( NTP_UPDATE_INTERVAL * 1000 ) ) {
611+ // Periodically sync with NTP if connected to WiFi
612+ if (WiFi.status () == WL_CONNECTED && currentTime - lastNTPUpdate >= NTP_UPDATE_INTERVAL) {
612613 syncRTCWithNTP ();
613614 }
614615
615- DateTime now = getCurrentTime ();
616- controlLights ();
616+ // Update light smart plugs
617+ if (currentTime - lastLightCheck >= UPDATE_LIGHTS_TIME) {
618+ lastLightCheck = currentTime;
619+ // TODO: Not sure if this is needed here
620+ DateTime now = getCurrentTime ();
621+ controlLights ();
622+ }
617623
618624 // Periodically show bitmap
619625 if (INTERRUPT_WITH_BITMAP) {
0 commit comments