From d0ea1588b593ce0f9e1ccfe8aeb7fd496b6e8295 Mon Sep 17 00:00:00 2001 From: DeltaLima Date: Wed, 11 Dec 2024 22:59:25 +0100 Subject: [PATCH] firmware - webui changes, move pump settings to grow settings, add debug json --- Arduino/CanGrow/CanGrow.ino | 2 +- Arduino/CanGrow/CanGrow_Init.h | 15 +- Arduino/CanGrow/CanGrow_Sensors.h | 2 +- Arduino/CanGrow/CanGrow_SysFunctions.h | 1 + Arduino/CanGrow/CanGrow_WebFunctions.h | 204 ++++++++++++++++--------- 5 files changed, 140 insertions(+), 84 deletions(-) diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index 6ef6c52..a874db7 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -6,7 +6,7 @@ // set CANGROW_VER and CANGROW_BUILD if not already done as Compiler Flag #ifndef CANGROW_VER - #define CANGROW_VER "v0.0.0-dev" + #define CANGROW_VER "0.0.0-dev" #endif #ifndef CANGROW_BUILD #define CANGROW_BUILD "1a2b3c4-0000000000000" diff --git a/Arduino/CanGrow/CanGrow_Init.h b/Arduino/CanGrow/CanGrow_Init.h index 74de3d1..50d6c83 100644 --- a/Arduino/CanGrow/CanGrow_Init.h +++ b/Arduino/CanGrow/CanGrow_Init.h @@ -20,12 +20,20 @@ const bool APhidden = false; // valSoilmoisture - contains the value of getSoilmoisture() unsigned short valSoilmoisture; +// helper variable for pump control with soilmoisture +// average of last readings +unsigned short valSoilmoistureAvg = 0; +unsigned short valSoilmoistureAvg_tmp = 0; +byte valSoilmoistureAvg_count = 0; +short valSoilmoistureRaw; + // valTemperature - contains the value of getTemperature() float valTemperature; // valTemperature - contains the value of getHumidity() float valHumidity; // valWaterlevel - contains the value of getWaterlevel() byte valWaterlevel; + // do we need a restart? (e.g. after wifi settings change) bool NeedRestart; bool FirstRun; @@ -49,12 +57,7 @@ unsigned long MaintenanceStarted = 0; byte PumpOnTimePassed = 0; bool PumpOnManual = false; -// helper variable for pump control with soilmoisture -// average of last readings -unsigned short valSoilmoistureAvg = 0; -unsigned short valSoilmoistureAvg_tmp = 0; -byte valSoilmoistureAvg_count = 0; -//unsigned short + /* * millis timer diff --git a/Arduino/CanGrow/CanGrow_Sensors.h b/Arduino/CanGrow/CanGrow_Sensors.h index 0b5e001..1399d23 100644 --- a/Arduino/CanGrow/CanGrow_Sensors.h +++ b/Arduino/CanGrow/CanGrow_Sensors.h @@ -203,7 +203,7 @@ int getSoilmoisture(byte moistureSensor, bool returnRAW = false) { 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 diff --git a/Arduino/CanGrow/CanGrow_SysFunctions.h b/Arduino/CanGrow/CanGrow_SysFunctions.h index 481b0c9..faf7e90 100644 --- a/Arduino/CanGrow/CanGrow_SysFunctions.h +++ b/Arduino/CanGrow/CanGrow_SysFunctions.h @@ -567,6 +567,7 @@ void refreshSensors() { byte soilmoistureAvgSampleCount = 5; valSoilmoisture = getSoilmoisture(MoistureSensor_Type); + valSoilmoistureRaw = getSoilmoisture(MoistureSensor_Type, true); valHumidity = getHumidity(HumiditySensor_Type); valTemperature = getTemperature(TemperatureSensor_Type); valWaterlevel = getWaterlevel(); diff --git a/Arduino/CanGrow/CanGrow_WebFunctions.h b/Arduino/CanGrow/CanGrow_WebFunctions.h index 1c3976b..2e16cbd 100644 --- a/Arduino/CanGrow/CanGrow_WebFunctions.h +++ b/Arduino/CanGrow/CanGrow_WebFunctions.h @@ -210,15 +210,26 @@ void Syslogout() { void SysMaintenance() { String body = returnHTMLheader(); - if( (webserver.hasArg("DimmOn")) ) { - MaintenanceMode = true; - MaintenanceStarted = millis(); - body += "
⏸️ Dimm LED On for "; - body += MaintenanceDuration; - body += "s
"; - } else if (webserver.hasArg("DimmOff")){ - MaintenanceMode = false; - body += "
⏸️ Dimm LED Off
"; + // when requesting to handle Dimming + if( (webserver.hasArg("DimmOn")) || (webserver.hasArg("DimmOff")) ) { + // check first if PWM is disabled / relais is used + if(UseLEDrelais == true) { + // if not, do it + if( (webserver.hasArg("DimmOn")) ) { + MaintenanceMode = true; + MaintenanceStarted = millis(); + body += "
⛅ Dimm LED On for "; + body += MaintenanceDuration; + body += "s
"; + } else if( (webserver.hasArg("DimmOff")) ) { + MaintenanceMode = false; + body += "
⛅ Dimm LED Off
"; + } + } else { + // otherwise nice error + body += "
⛅ LED setting
Use relais for LED (disable PWM)
 is set to Yes in 🔆 Grow settings
"; + + } } else if(webserver.hasArg("PumpOnManual")) { if(UsePump == true) { PumpOnManual = true; @@ -226,15 +237,15 @@ void SysMaintenance() { body += PumpOnTime; body += "s"; } else { - body += "
💧 Pump mode is set to Off in ⚙ System settings
"; + body += "
💧 Pump mode is set to Off in 🔆 Grow settings
"; } } body += "

🧰 Maintenance

"; - body += "Dimm LED On  Off


"; - body += "Pump manual Activate for "; + body += "Dimm LED ⛅ On  ☀️ Off


"; + body += "Pump manual 💧 Activate for "; body += PumpOnTime; body += "s
"; @@ -523,26 +534,24 @@ void WEBgrowSettings() { - + body += "Grow duration
"; body += "Vegetation duration: days
\n"; + body+= "' required> Days
\n"; body += "Bloom duration: days

\n"; + body+= "' required> Days

\n"; - - body += "Time LED ON vegetation: hours
\n"; + body+= "' required> Hours
\n"; - body += "Time LED ON bloom: hours

\n"; - - + body+= "' required> Hours
\n"; body += "Sunrise: Minutes

\n"; + body+= "' required> Minutes
\n"; if(UseLEDrelais == false) { body += "LED brightness: Off\n"; body += "
\n"; } + body += "
"; + body += "Fan configuration
"; if(UseFANrelais == false) { body += "FAN1 speed: %

\n"; + + + + + + + + + + body += "Pump configuration
"; + + // PumpMode byte + body += "Pump mode:

1: Water every few days.
\ +2: Water if the soil moisture falls below Soilmoisture low value
\ +3: Water every few days if the soil moisture falls below Soilmoisture low value.

\n"; + + // TODO ugly. can this done be better? + // PumpOnTime int + body += "Pump ON time: Seconds
\n"; + + // SoilmoistureLow byte + body += "Soilmoisture low: %
\n"; + + + + + + + body += "Pump interval vegetation: every Yes\n"; body += "\n"; + body += "\n"; body += "
\n"; body += "

When using CanGrow PCB v0.6, set to Yes

\n"; // UseLEDrelais bool body += "Use relais for LED (disable PWM):
\n"; // UseFANrelais bool body += "Use relais for FAN1 (disable PWM):

\n"; @@ -732,36 +778,11 @@ void WEBsystemSettings() { body += "

\n"; - body += "Pump configuration
"; - - // PumpMode byte - body += "Pump mode:

1: Water every few days.
\ -2: Water if the soil moisture falls below Soilmoisture low value
\ -3: Water every few days if the soil moisture falls below Soilmoisture low value.

\n"; - - // TODO ugly. can this done be better? - // PumpOnTime int - body += "Pump ON time: Seconds
\n"; - - // SoilmoistureLow byte - body += "Soilmoisture low: %

\n"; - - body += "General configuration
"; // NtpOffset int - body += "NTP offset: Hours
\n"; @@ -782,7 +803,7 @@ void WEBsystemSettings() { body += "ESP32-Cam IP (optional):
\n"; + body += "' >

\n"; body += "\n"; @@ -851,7 +872,7 @@ void WEBwifiSettings() { body += "IP:
\n"; body += "Subnet mask:
\n"; body += "Gateway:
\n"; - body += "DNS:
\n"; + body += "DNS:

\n"; body += "\n"; body += "\n"; body += FPSTR(HTMLfooter); @@ -891,6 +912,11 @@ void POSTgrowSettings() { SunriseMinute = webserver.arg("SunriseMinute").toInt(); SunFade = webserver.arg("SunFade").toInt(); SunFadeDuration = webserver.arg("SunFadeDuration").toInt(); + + UsePump = webserver.arg("UsePump").toInt(); + PumpOnTime = webserver.arg("PumpOnTime").toInt(); + SoilmoistureLow = webserver.arg("SoilmoistureLow").toInt(); + PumpIntervalVeg = webserver.arg("PumpIntervalVeg").toInt(); PumpIntervalBloom = webserver.arg("PumpIntervalBloom").toInt(); @@ -918,6 +944,15 @@ void POSTgrowSettings() { EEPROM.put(248, PinFAN2PWM); EEPROM.put(217, SunFade); EEPROM.put(218, SunFadeDuration); + + // size is 1 byte + EEPROM.put(163, UsePump); + // size is 1 byte + EEPROM.put(164, PumpOnTime); + // size is 1 byte + EEPROM.put(166, SoilmoistureLow); + + // size is 1 byte EEPROM.put(241, PumpIntervalVeg); // size is 1 byte @@ -954,6 +989,20 @@ void POSTgrowSettings() { Serial.println(PinFANPWM); Serial.print("PinFAN2PWM: "); Serial.println(PinFAN2PWM); + + Serial.print("UsePump: "); + Serial.println(UsePump); + Serial.print("PumpOnTime: "); + Serial.println(PumpOnTime); + Serial.print("SoilmoistureLow: "); + Serial.println(SoilmoistureLow); + + Serial.print("PumpIntervalVeg: "); + Serial.println(PumpIntervalVeg); + Serial.print("PumpIntervalBloom: "); + Serial.println(PumpIntervalBloom); + + webserver.sendHeader("Location", String("/growSettings?success"), true); webserver.send(302, "text/plain", "growSettings/save: success!\n"); @@ -968,9 +1017,8 @@ void POSTsystemSettings() { NtpOffset = webserver.arg("NtpOffset").toInt(); MoistureSensor_Type = webserver.arg("MoistureSensor_Type").toInt(); - SoilmoistureLow = webserver.arg("SoilmoistureLow").toInt(); - UsePump = webserver.arg("UsePump").toInt(); - PumpOnTime = webserver.arg("PumpOnTime").toInt(); + + UseFan = webserver.arg("UseFan").toInt(); UseLEDrelais = webserver.arg("UseLEDrelais").toInt(); UseFANrelais = webserver.arg("UseFANrelais").toInt(); @@ -997,14 +1045,10 @@ void POSTsystemSettings() { EEPROM.put(161, configured); // size is 1 byte EEPROM.put(162, UseFan); - // size is 1 byte - EEPROM.put(163, UsePump); - // size is 1 byte - EEPROM.put(164, PumpOnTime); + // size is 1 byte EEPROM.put(165, MoistureSensor_Type); - // size is 1 byte - EEPROM.put(166, SoilmoistureLow); + // size is 2 byte EEPROM.put(167, NtpOffset); // size is 1 byte @@ -1058,14 +1102,10 @@ void POSTsystemSettings() { Serial.println(configured); Serial.print("UseFan: "); Serial.println(UseFan); - Serial.print("UsePump: "); - Serial.println(UsePump); - Serial.print("PumpOnTime: "); - Serial.println(PumpOnTime); + Serial.print("MoistureSensor_Type: "); Serial.println(MoistureSensor_Type); - Serial.print("SoilmoistureLow: "); - Serial.println(SoilmoistureLow); + Serial.print("NtpOffset: "); Serial.println(NtpOffset); Serial.print("UseLEDrelais: "); @@ -1213,6 +1253,7 @@ void APIgetSensors() { jsonSensors["soilmoisture"] = valSoilmoisture; jsonSensors["soilmoistureAvg"] = valSoilmoistureAvg; + jsonSensors["soilmoistureRaw"] = valSoilmoistureRaw; jsonSensors["temperature"] = valTemperature; jsonSensors["humidity"] = valHumidity; jsonSensors["waterlevel"] = valWaterlevel; @@ -1232,10 +1273,21 @@ void APIgetDebug() { JsonObject objRuntime = jsonDebug["runtime"].add(); objRuntime["PumpOnTimePassed"] = PumpOnTimePassed; objRuntime["PumpOnManual"] = PumpOnManual; + objRuntime["valTemperature"] = valTemperature; + objRuntime["valHumidity"] = valHumidity; + objRuntime["valSoilmoisture"] = valSoilmoisture; + objRuntime["valSoilmoistureRaw"] = valSoilmoistureRaw; objRuntime["valSoilmoistureAvg"] = valSoilmoistureAvg; objRuntime["valSoilmoistureAvg_tmp"] = valSoilmoistureAvg_tmp; objRuntime["valSoilmoistureAvg_count"] = valSoilmoistureAvg_count; - objRuntime["valVPD"] = valVPD; + objRuntime["NeedRestart"] = NeedRestart; + objRuntime["FirstRun"] = FirstRun; + objRuntime["ScreenToDisplay"] = ScreenToDisplay; + objRuntime["ScreenIterationPassed"] = ScreenIterationPassed; + objRuntime["DayNight"] = DayNight; + objRuntime["MaintenanceMode"] = MaintenanceMode; + objRuntime["MaintenanceStarted"] = MaintenanceStarted; + // WiFi JsonObject objWiFi = jsonDebug["wifi"].add();