Skip to content

Commit 1ca5238

Browse files
committed
added check times
1 parent 0dc26d3 commit 1ca5238

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/main/config.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ constexpr float HUMIDITY_HYSTERESIS = 5.0; // Humidity hyster
5555
constexpr float CO2_HYSTERESIS = 100.0; // CO2 hysteresis to prevent rapid switching
5656

5757
// TIME / LIGHT CONFIGURATION
58+
bool ENABLE_NTP_SYNC = true; // Enable or disable NTP synchronization
59+
bool ENABLE_RTC = true; // Enable RTC synchronization
5860
constexpr int TIMEZONE_OFFSET = -6 * 3600; // Adjust for your timezone (CST example)
59-
constexpr int NTP_UPDATE_INTERVAL = 86400; // Sync every 24 hours (seconds)
61+
constexpr int NTP_UPDATE_INTERVAL = 86400000; // Sync every 24 hours (ms)
6062
constexpr int RTC_CHECK_INTERVAL = 60000; // Check RTC time (ms)
63+
constexpr int UPDATE_LIGHTS_TIME = 5000; // Update lights time (ms)
6164
constexpr char NTP_SERVER[] = "pool.ntp.org"; // NTP server address
62-
bool ENABLE_NTP_SYNC = true; // Enable or disable NTP synchronization
63-
bool ENABLE_RTC = true; // Enable RTC synchronization
6465
constexpr int RTC_I2C_ADDRESS = 0x68; // RTC module I2C address (DS3231 default)
6566
constexpr int LIGHTS_ON_HOUR_FLOWER_ON = 18; // Lights on hour when flower mode is active (6:00 PM)
6667
constexpr int LIGHTS_OFF_HOUR_FLOWER_ON = 6; // Lights off hour when flower mode is active (6:00 AM)

src/main/main.ino

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,11 @@ void handleHumidity(float humidity, float desiredHumidity, const char* mode) {
289289
void 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

Comments
 (0)