From f0007b6eb68c4e70d4be0ab693fa9d0ad65d68ed Mon Sep 17 00:00:00 2001 From: ConnerWill Date: Mon, 27 Jan 2025 11:48:47 -0600 Subject: [PATCH 1/4] Added rocker switch to set flower state --- src/main/config.h | 10 +++++----- src/main/main.ino | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/config.h b/src/main/config.h index de7091b..5b9a2fe 100644 --- a/src/main/config.h +++ b/src/main/config.h @@ -20,8 +20,9 @@ constexpr uint16_t SERVER_PORT = 80; // Port for the web ser constexpr char SERVER_PATH[] = "/"; // Path for serving the data // PINS CONFIGURATION -constexpr uint8_t CO2_PIN = 35; // Analog pin for CO2 sensor -constexpr uint8_t DHT_PIN = 27; // GPIO pin for DHT sensor +constexpr uint8_t CO2_PIN = 35; // Analog pin for CO2 sensor +constexpr uint8_t DHT_PIN = 27; // GPIO pin for DHT sensor +constexpr uint8_t ROCKER_SWITCH_PIN = 25; // GPIO pin for flower rocker switch // SCREEN CONFIGURATION constexpr int SCREEN_WIDTH = 128; // OLED display width, in pixels @@ -42,9 +43,8 @@ constexpr int INTERRUPT_BITMAP_TIME = 300000; // Check WiFi time (ms) const char *intakePlugAlias = "tent1_intake"; // Kasa plug alias (Intake) const char *exhaustPlugAlias = "tent1_exhaust"; // Kasa plug aliases (Exhaust) const char *humidifierPlugAlias = "tent1_humidifier"; // Kasa plug aliases (Humidifier) -//const char *lightPlugAlias = "tent1_light"; // Kasa plug aliases (Lights) constexpr int SMARTPLUG_UPDATE_TIME = 30000; // Update smart plugs time (ms) -bool FLOWER = false; // Set to true to set flower mode //TODO: Link this to a physical switch +bool FLOWER = false; // Flower default value (this changes based on rocker switch) constexpr float DESIRED_TEMP_VEG = 75.0; // Desired temperature in F (veg) constexpr float DESIRED_HUMIDITY_VEG = 60.0; // Desired humidity in percentage (veg) constexpr float DESIRED_CO2_VEG = 800.0; // Desired CO2 level (ppm) (veg) @@ -58,4 +58,4 @@ constexpr float CO2_HYSTERESIS = 100.0; // CO2 hysteresis // SERIAL CONFIGURATION constexpr int BAUD_RATE = 115200; // Baud rate // ============================================================================ -//vim: filetype=arduino:shiftwidth=2:softtabstop=2:expandtab:nowrap:cursorline:cursorcolumn:number:relativenumber \ No newline at end of file +//vim: filetype=arduino:shiftwidth=2:softtabstop=2:expandtab:nowrap:cursorline:cursorcolumn:number:relativenumber diff --git a/src/main/main.ino b/src/main/main.ino index 5dbe956..b7475ac 100644 --- a/src/main/main.ino +++ b/src/main/main.ino @@ -82,6 +82,17 @@ float celsiusToFahrenheit(float celsius) { return fahrenheit; } + +// ------------------------------------- +// Switch Functions +// ------------------------------------- +// Function to read and update the state of the FLOWER variable based on the rocker switch +void updateFlowerState() { + int rockerState = digitalRead(ROCKER_SWITCH_PIN); + FLOWER = (rockerState == LOW); // Assuming LOW means ON +} + + // ------------------------------------- // KASA TP-Link Smart Plug Functions // ------------------------------------- @@ -418,6 +429,7 @@ void updateOLED(float co2, float temperature, float temperatureF, float humidity // ============================================================================ void setup() { pinMode(CO2_PIN, INPUT); // Set co2 pin mode + pinMode(ROCKER_SWITCH_PIN, INPUT_PULLUP); // Initialize digital input for the rocker switch dht.setup(DHT_PIN, DHTesp::DHT_MODEL_t::DHT22); // Initialize DHT sensor Serial.begin(BAUD_RATE); // Initialize Serial for debugging initOLED(); // Initialize OLED @@ -465,6 +477,9 @@ void loop() { static unsigned long lastPlugCheck = 0; unsigned long currentTime = millis(); + // Check position of flower switch + updateFlowerState(); + // Update OLED display if (currentTime - lastUpdateTime >= SCREEN_UPDATE_TIME) { lastUpdateTime = currentTime; @@ -532,4 +547,4 @@ void loop() { } } // ============================================================================ -//vim: filetype=arduino:shiftwidth=2:softtabstop=2:expandtab:nowrap:cursorline:cursorcolumn:number:relativenumber \ No newline at end of file +//vim: filetype=arduino:shiftwidth=2:softtabstop=2:expandtab:nowrap:cursorline:cursorcolumn:number:relativenumber From 1f274385d3608e86048673f655d2e9b3b624c7ad Mon Sep 17 00:00:00 2001 From: ConnerWill Date: Mon, 27 Jan 2025 12:04:43 -0600 Subject: [PATCH 2/4] Made oled display the current flower mode --- src/main/config.h | 2 -- src/main/main.ino | 29 +++++++++-------------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/main/config.h b/src/main/config.h index 5b9a2fe..d63dd2b 100644 --- a/src/main/config.h +++ b/src/main/config.h @@ -32,10 +32,8 @@ constexpr int SCREEN_UPDATE_TIME = 1000; // Time to wait before constexpr int SCREEN_STARTUP_DISPLAY_TIME = 3000; // Startup screen delay time (ms) bool SHOW_STARTUP = true; // Set to true to show the startup sequence bool SHOW_BITMAP = true; // Set to true to show the bitmap -bool SHOW_CUSTOM_TEXT = true; // Set to true to show custom text bool SHOW_IP_INFO = true; // Set to true to show IP information constexpr char STARTUP_TEXT[] = ":)"; // Startup custom text -constexpr char CUSTOM_TEXT[] = ""; // OLED custom text "_____________________" bool INTERRUPT_WITH_BITMAP = true; // Periodically show bitmap constexpr int INTERRUPT_BITMAP_TIME = 300000; // Check WiFi time (ms) diff --git a/src/main/main.ino b/src/main/main.ino index b7475ac..064071c 100644 --- a/src/main/main.ino +++ b/src/main/main.ino @@ -365,12 +365,6 @@ void showIPInfo() { display.setCursor(0, 36); display.print("IP: "); display.println(WiFi.localIP().toString().c_str()); - - // Custom Text - if (SHOW_CUSTOM_TEXT || strlen(CUSTOM_TEXT) == 0) { - display.setCursor(0, 56); - display.print(CUSTOM_TEXT); - } display.display(); } } @@ -388,35 +382,30 @@ void updateOLED(float co2, float temperature, float temperatureF, float humidity // Temperature display.setCursor(0, 16); display.print("Temp: "); - display.print(temperature); - display.print(" "); // print space - display.write(0xF8); // Print the degrees symbol - display.println("C"); - - // Temperature - display.setCursor(0, 26); - display.print("Temp: "); display.print(temperatureF); display.print(" "); // print space display.write(0xF8); // Print the degrees symbol display.println("F"); // Humidity - display.setCursor(0, 36); + display.setCursor(0, 26); display.print("RH: "); display.print(humidity); display.println(" %"); // CO2 - display.setCursor(0, 46); + display.setCursor(0, 36); display.print("CO2: "); display.print(co2); display.println(" ppm"); - // Custom Text - if (SHOW_CUSTOM_TEXT || strlen(CUSTOM_TEXT) == 0) { - display.setCursor(0, 56); - display.print(CUSTOM_TEXT); + // Flower Mode + display.setCursor(0, 56); + display.print("Flower: "); + if (FLOWER) { + display.println("ON"); + } else { + display.println("OFF"); } // Update Display From e7895886fd2b6fa7975c4669e66da851a118f9b1 Mon Sep 17 00:00:00 2001 From: ConnerWill Date: Mon, 27 Jan 2025 12:07:21 -0600 Subject: [PATCH 3/4] Increased version --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index f8cef92..98f6742 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v5.1.1 \ No newline at end of file +v5.2.1 From 323f431c705b5044daba8ccf15a8e04025b3d063 Mon Sep 17 00:00:00 2001 From: ConnerWill Date: Tue, 28 Jan 2025 22:46:38 -0600 Subject: [PATCH 4/4] Changed temp and switch pin --- src/main/config.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/config.h b/src/main/config.h index d63dd2b..b84d11e 100644 --- a/src/main/config.h +++ b/src/main/config.h @@ -10,7 +10,7 @@ // ============================================================================ // WIFI CONFIGURATION constexpr char WIFI_SSID[] = ""; // Wi-Fi SSID -constexpr char WIFI_PASSWORD[] = "!"; // Wi-Fi password +constexpr char WIFI_PASSWORD[] = ""; // Wi-Fi password constexpr char WIFI_HOSTNAME[] = "esp32-plant"; // Hostname constexpr int WIFI_TIMEOUT_TIME = 30000; // Timeout if unable to connect to WiFi (ms) constexpr int WIFI_CHECK_INTERVAL = 5000; // Check WiFi time (ms) @@ -22,7 +22,7 @@ constexpr char SERVER_PATH[] = "/"; // Path for serving the // PINS CONFIGURATION constexpr uint8_t CO2_PIN = 35; // Analog pin for CO2 sensor constexpr uint8_t DHT_PIN = 27; // GPIO pin for DHT sensor -constexpr uint8_t ROCKER_SWITCH_PIN = 25; // GPIO pin for flower rocker switch +constexpr uint8_t ROCKER_SWITCH_PIN = 19; // GPIO pin for flower rocker switch // SCREEN CONFIGURATION constexpr int SCREEN_WIDTH = 128; // OLED display width, in pixels @@ -43,8 +43,8 @@ const char *exhaustPlugAlias = "tent1_exhaust"; // Kasa plug alias const char *humidifierPlugAlias = "tent1_humidifier"; // Kasa plug aliases (Humidifier) constexpr int SMARTPLUG_UPDATE_TIME = 30000; // Update smart plugs time (ms) bool FLOWER = false; // Flower default value (this changes based on rocker switch) -constexpr float DESIRED_TEMP_VEG = 75.0; // Desired temperature in F (veg) -constexpr float DESIRED_HUMIDITY_VEG = 60.0; // Desired humidity in percentage (veg) +constexpr float DESIRED_TEMP_VEG = 80.0; // Desired temperature in F (veg) +constexpr float DESIRED_HUMIDITY_VEG = 50.0; // Desired humidity in percentage (veg) constexpr float DESIRED_CO2_VEG = 800.0; // Desired CO2 level (ppm) (veg) constexpr float DESIRED_TEMP_FLOWER = 70.0; // Desired temperature in F (flower) constexpr float DESIRED_HUMIDITY_FLOWER = 45.0; // Desired humidity in percentage (flower)