Skip to content

Commit 9039839

Browse files
committed
Added controlLights to the main loop
1 parent 7949232 commit 9039839

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/main/main.ino

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,13 @@ void handleHumidity(float humidity, float desiredHumidity, const char* mode) {
285285
}
286286
}
287287

288-
// Function to set light state
289-
void controlLights(int hour, int minute) {
288+
// Function to control the lights based on the RTC time and flower state
289+
void controlLights() {
290+
DateTime now = getCurrentTime();
291+
int hour = now.hour();
292+
290293
bool lightsOn = false;
294+
291295
if (FLOWER) {
292296
// Flower mode
293297
lightsOn = (hour >= LIGHTS_ON_HOUR_FLOWER_ON || hour < LIGHTS_OFF_HOUR_FLOWER_ON);
@@ -539,6 +543,7 @@ void loop() {
539543
static unsigned long lastWiFiCheck = 0;
540544
static unsigned long lastBitmapCheck = 0;
541545
static unsigned long lastPlugCheck = 0;
546+
unsigned long lastNTPUpdate = 0;
542547
unsigned long currentTime = millis();
543548

544549
// Check position of flower switch
@@ -602,6 +607,14 @@ void loop() {
602607
handleHumidity(humidity, desiredHumidity, mode);
603608
}
604609

610+
// Periodically sync with NTP
611+
if (WiFi.status() == WL_CONNECTED && millis() - lastNTPUpdate > (NTP_UPDATE_INTERVAL * 1000)) {
612+
syncRTCWithNTP();
613+
}
614+
615+
DateTime now = getCurrentTime();
616+
controlLights();
617+
605618
// Periodically show bitmap
606619
if (INTERRUPT_WITH_BITMAP) {
607620
if (currentTime - lastBitmapCheck >= INTERRUPT_BITMAP_TIME) {

0 commit comments

Comments
 (0)