From 6454a090d185e36f8bc1d7b4cfeddc619b929778 Mon Sep 17 00:00:00 2001 From: Marcus Date: Thu, 23 May 2024 02:09:19 +0200 Subject: [PATCH] firmware wip - fine tune soilmoisture values, add esp32-cam support --- Arduino/CanGrow/CanGrow.ino | 2 +- Arduino/CanGrow/CanGrow_HTML.h | 10 ++++++++-- Arduino/CanGrow/CanGrow_Init.h | 3 ++- Arduino/CanGrow/CanGrow_Sensors.h | 16 ++++++++++------ Arduino/CanGrow/CanGrow_SysFunctions.h | 9 ++++++--- Arduino/CanGrow/CanGrow_WebFunctions.h | 23 +++++++++++++++++++++-- playground/html/root/index.html | 23 ++++++++++++++++------- 7 files changed, 64 insertions(+), 22 deletions(-) diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index c4ceff4..b6eddd6 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -75,7 +75,7 @@ void setup() { digitalWrite(PinPUMP, LOW); // except PINsoilmoisture // PINsoilmoisture is always HIGH and gets LOW in moment of waterlevel measurement - digitalWrite(PINsoilmoisture, HIGH); + digitalWrite(PINsoilmoisture, LOW); // set PWM frequency lower to avoid annoying noises // in combination with 47uF at fan output, 220Hz is kinda sweetspot for a fan diff --git a/Arduino/CanGrow/CanGrow_HTML.h b/Arduino/CanGrow/CanGrow_HTML.h index 009c1e3..3cbec47 100644 --- a/Arduino/CanGrow/CanGrow_HTML.h +++ b/Arduino/CanGrow/CanGrow_HTML.h @@ -30,10 +30,16 @@ body { } .center { - width: 100%; - margin: auto; + width: 100%; + margin: auto; } +.centered { + display: block; + margin-left: auto; + margin-right: auto; +} + h1, h2, h3, h4, h5 { text-align: center; } diff --git a/Arduino/CanGrow/CanGrow_Init.h b/Arduino/CanGrow/CanGrow_Init.h index 091b7d2..9849b26 100644 --- a/Arduino/CanGrow/CanGrow_Init.h +++ b/Arduino/CanGrow/CanGrow_Init.h @@ -92,7 +92,8 @@ bool UseLEDrelais; bool UseFANrelais; // Which temperature sensor to use? byte TemperatureSensor_Type; -unsigned short MaintenanceDuration = 60; +unsigned short MaintenanceDuration = 300; +char Esp32CamIP[16]; // // Grow Stuff diff --git a/Arduino/CanGrow/CanGrow_Sensors.h b/Arduino/CanGrow/CanGrow_Sensors.h index 48be196..a65b831 100644 --- a/Arduino/CanGrow/CanGrow_Sensors.h +++ b/Arduino/CanGrow/CanGrow_Sensors.h @@ -147,14 +147,14 @@ int getSoilmoisture(byte moistureSensor, bool returnRAW = false) { // read analog value from analog moisture sensor wet = 180; // this value was measured in air, without contact to anything - // dry= 590; + //dry= 590; // was measured in dry soil, not bone dry but really dry (6 days no watering) - dry = 300; + dry = 360; - //digitalWrite(PINsoilmoisture, HIGH); + digitalWrite(PINsoilmoisture, HIGH); // wait a bit to let the circuit stabilize - //delay(50); + delay(50); // get analog input value // get values 10 times and get the middle for more precise data @@ -164,11 +164,15 @@ int getSoilmoisture(byte moistureSensor, bool returnRAW = false) { soilmoisture = soilmoisture / 10; // disable Vcc for the sensor to release analog pin - //digitalWrite(PINsoilmoisture, LOW); + digitalWrite(PINsoilmoisture, LOW); break; case 2: // read soil moisture from chrip I2C - wet = 560; + // this value was measured in water + // wet = 560; + + // measured in fresh watered soil + wet = 390; dry= 250; // get raw value from I2C chirp sensor diff --git a/Arduino/CanGrow/CanGrow_SysFunctions.h b/Arduino/CanGrow/CanGrow_SysFunctions.h index 38cfa15..c9fec14 100644 --- a/Arduino/CanGrow/CanGrow_SysFunctions.h +++ b/Arduino/CanGrow/CanGrow_SysFunctions.h @@ -101,9 +101,10 @@ bool loadEEPROM() { * 215 UseFANrelais * 216 PinFANPWM * 217 SunFade - * 218 SunFadeDuration - * 219 MaintenanceDuration - * 221 .. + * 218 SunFadeDuration + * 219 MaintenanceDuration (2 byte) + * 221 Esp32CamIP (16 byte) + * 237 ... * */ @@ -165,6 +166,8 @@ bool loadEEPROM() { EEPROM.get(215, UseFANrelais); // size is 2 byte EEPROM.get(219, MaintenanceDuration); + // size is 16 byte + EEPROM.get(221, Esp32CamIP); } // TODO auth does not work atm // EEPROM.get(160, WebUiUsername); diff --git a/Arduino/CanGrow/CanGrow_WebFunctions.h b/Arduino/CanGrow/CanGrow_WebFunctions.h index 0a6990b..0a51bfe 100644 --- a/Arduino/CanGrow/CanGrow_WebFunctions.h +++ b/Arduino/CanGrow/CanGrow_WebFunctions.h @@ -324,7 +324,16 @@ void WEBroot() { body += valSoilmoisture; body += "'); "; - body += ""; + body += "
\n"; + + // when an ESP32-Cam IP is given, display picture from it + if(strlen(Esp32CamIP) > 0) { + body += "Image capture from ESP32CAM at ";
+      body += Esp32CamIP;
+      body += "\n
\n"; + } body += "Grow started: "; body += returnStrDateFromEpoch(GrowStart); @@ -575,7 +584,13 @@ void WEBsystemSettings() { body += "Maintenance Duration: Seconds
\n"; - + + + body += "ESP32-Cam IP (optional):
\n"; + + body += "\n"; body += "\n"; @@ -764,6 +779,9 @@ void POSTsystemSettings() { UseFANrelais = webserver.arg("UseFANrelais").toInt(); TemperatureSensor_Type = webserver.arg("TemperatureSensor_Type").toInt(); MaintenanceDuration = webserver.arg("MaintenanceDuration").toInt(); + String Esp32CamIP_tmp = webserver.arg("Esp32CamIP"); + Esp32CamIP_tmp.toCharArray(Esp32CamIP, 221); + configured = true; @@ -788,6 +806,7 @@ void POSTsystemSettings() { // size is 1 byte EEPROM.put(215, UseFANrelais); EEPROM.put(219, MaintenanceDuration); + EEPROM.put(221, Esp32CamIP); // write data to EEPROM EEPROM.commit(); diff --git a/playground/html/root/index.html b/playground/html/root/index.html index f6557ab..ed67ad9 100644 --- a/playground/html/root/index.html +++ b/playground/html/root/index.html @@ -15,10 +15,16 @@ body { } .center { - width: 100%; - margin: auto; + width: 100%; + margin: auto; } +.centered { + display: block; + margin-left: auto; + margin-right: auto; +} + h1, h2, h3, h4, h5 { text-align: center; } @@ -106,7 +112,7 @@ a:active { background: #026b45; color: #fff; border-radius: 3px; - padding: 8px 16px; + padding: 6px 12px; text-align: center; text-decoration: none; display: inline-block; @@ -138,7 +144,7 @@ input[type=text], input[type=date], input[type=number], input[type=password], se
  • ⚙ System settings
  • 📡 WiFi settings
  • ❓ Help
  • -
  • 23:39:48
  • +
  • 01:53:31
  • CanGrow v0.1
  • 🌱 Ruderalis Indica

    @@ -198,10 +204,13 @@ input[type=text], input[type=date], input[type=number], input[type=password], se var gaugeSoilmoisture = new Gauge(document.getElementById('gaugeSoilmoisture')); -Grow started: 2024-04-12
    -Day of Grow: 33
    +
    +Image capture from ESP32CAM at 192.168.30.6 +
    +Grow started: 2024-04-12
    +Day of Grow: 41
    Pump water level: Critical
    -Growlight brightness: 69 %
    +Growlight brightness: 100 %
    MOSFET