Skip to content

Commit

Permalink
Merge pull request #8 from ConnerWill/rocker-switch-flower
Browse files Browse the repository at this point in the history
Rocker switch flower
  • Loading branch information
ConnerWill authored Jan 29, 2025
2 parents bbd6413 + 323f431 commit 86916e8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v5.1.1
v5.2.1
18 changes: 8 additions & 10 deletions src/main/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = 19; // GPIO pin for flower rocker switch

// SCREEN CONFIGURATION
constexpr int SCREEN_WIDTH = 128; // OLED display width, in pixels
Expand All @@ -31,22 +32,19 @@ 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)

// SMART PLUG CONFIGURATION
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
constexpr float DESIRED_TEMP_VEG = 75.0; // Desired temperature in F (veg)
constexpr float DESIRED_HUMIDITY_VEG = 60.0; // Desired humidity in percentage (veg)
bool FLOWER = false; // Flower default value (this changes based on rocker switch)
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)
Expand All @@ -58,4 +56,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
//vim: filetype=arduino:shiftwidth=2:softtabstop=2:expandtab:nowrap:cursorline:cursorcolumn:number:relativenumber
46 changes: 25 additions & 21 deletions src/main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
// -------------------------------------
Expand Down Expand Up @@ -354,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();
}
}
Expand All @@ -377,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
Expand All @@ -418,6 +418,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
Expand Down Expand Up @@ -465,6 +466,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;
Expand Down Expand Up @@ -532,4 +536,4 @@ void loop() {
}
}
// ============================================================================
//vim: filetype=arduino:shiftwidth=2:softtabstop=2:expandtab:nowrap:cursorline:cursorcolumn:number:relativenumber
//vim: filetype=arduino:shiftwidth=2:softtabstop=2:expandtab:nowrap:cursorline:cursorcolumn:number:relativenumber

0 comments on commit 86916e8

Please sign in to comment.