firmware - webui changes, move pump settings to grow settings, add debug json
This commit is contained in:
parent
a4c0d060e1
commit
d0ea1588b5
5 changed files with 140 additions and 84 deletions
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -210,15 +210,26 @@ void Syslogout() {
|
|||
void SysMaintenance() {
|
||||
String body = returnHTMLheader();
|
||||
|
||||
if( (webserver.hasArg("DimmOn")) ) {
|
||||
MaintenanceMode = true;
|
||||
MaintenanceStarted = millis();
|
||||
body += "<div class='infomsg'>⏸️ Dimm LED On for ";
|
||||
body += MaintenanceDuration;
|
||||
body += "s</div>";
|
||||
} else if (webserver.hasArg("DimmOff")){
|
||||
MaintenanceMode = false;
|
||||
body += "<div class='infomsg'>⏸️ Dimm LED Off</div>";
|
||||
// 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 += "<div class='infomsg'>⛅ Dimm LED On for ";
|
||||
body += MaintenanceDuration;
|
||||
body += "s</div>";
|
||||
} else if( (webserver.hasArg("DimmOff")) ) {
|
||||
MaintenanceMode = false;
|
||||
body += "<div class='infomsg'>⛅ Dimm LED Off</div>";
|
||||
}
|
||||
} else {
|
||||
// otherwise nice error
|
||||
body += "<div class='warnmsg'>⛅ LED setting <pre>Use relais for LED (disable PWM)<pre> is set to <b>Yes</b> in 🔆 Grow settings</div>";
|
||||
|
||||
}
|
||||
} else if(webserver.hasArg("PumpOnManual")) {
|
||||
if(UsePump == true) {
|
||||
PumpOnManual = true;
|
||||
|
@ -226,15 +237,15 @@ void SysMaintenance() {
|
|||
body += PumpOnTime;
|
||||
body += "s</div>";
|
||||
} else {
|
||||
body += "<div class='warnmsg'>💧 Pump mode is set to <b>Off</b> in ⚙ System settings</div>";
|
||||
body += "<div class='warnmsg'>💧 Pump mode is set to <b>Off</b> in 🔆 Grow settings</div>";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
body += "<h2>🧰 Maintenance</h2>";
|
||||
|
||||
body += "Dimm LED <a class='button' href='/system/maintenance?DimmOn=1'>On</a> <a class='button' href='/system/maintenance?DimmOff=1'>Off</a><br><br><br>";
|
||||
body += "Pump manual <a class='button' href='/system/maintenance?PumpOnManual=1'>Activate for ";
|
||||
body += "Dimm LED <a class='button' href='/system/maintenance?DimmOn=1'>⛅ On</a> <a class='button' href='/system/maintenance?DimmOff=1'>☀️ Off</a><br><br><br>";
|
||||
body += "Pump manual <a class='button' href='/system/maintenance?PumpOnManual=1'>💧 Activate for ";
|
||||
body += PumpOnTime;
|
||||
body += "s</a><br>";
|
||||
|
||||
|
@ -523,26 +534,24 @@ void WEBgrowSettings() {
|
|||
|
||||
|
||||
|
||||
|
||||
body += "<b>Grow duration</b><br>";
|
||||
body += "Vegetation duration: <input class='inputShort' type='number' name='DaysVeg' min='0' max='255' value='";
|
||||
body += DaysVeg;
|
||||
body+= "' required> days<br>\n";
|
||||
body+= "' required> Days<br>\n";
|
||||
|
||||
body += "Bloom duration: <input class='inputShort' type='number' name='DaysBloom' min='0' max='255' value='";
|
||||
body += DaysBloom;
|
||||
body+= "' required> days<br><br>\n";
|
||||
body+= "' required> Days<br><br>\n";
|
||||
|
||||
|
||||
|
||||
body += "Time LED ON vegetation: <input class='inputShort' type='number' name='LighthoursVeg' min='0' max='255' value='";
|
||||
body += "<b>Light configuration</b><br>";
|
||||
body += "LED ON vegetation: <input class='inputShort' type='number' name='LighthoursVeg' min='0' max='255' value='";
|
||||
body += LighthoursVeg;
|
||||
body+= "' required> hours<br>\n";
|
||||
body+= "' required> Hours<br>\n";
|
||||
|
||||
body += "Time LED ON bloom: <input class='inputShort' type='number' name='LighthoursBloom' min='0' max='255' value='";
|
||||
body += "LED ON bloom: <input class='inputShort' type='number' name='LighthoursBloom' min='0' max='255' value='";
|
||||
body += LighthoursBloom;
|
||||
body+= "' required> hours<br><br>\n";
|
||||
|
||||
|
||||
body+= "' required> Hours<br>\n";
|
||||
|
||||
body += "Sunrise: <input class='inputShort' type='number' name='SunriseHour' min='0' max='23' value='";
|
||||
body += SunriseHour;
|
||||
|
@ -559,7 +568,7 @@ void WEBgrowSettings() {
|
|||
|
||||
body += "Fade duration: <input class='inputShort' type='number' name='SunFadeDuration' min='1' max='255' value='";
|
||||
body += SunFadeDuration;
|
||||
body+= "' required> Minutes<br><br>\n";
|
||||
body+= "' required> Minutes<br>\n";
|
||||
|
||||
if(UseLEDrelais == false) {
|
||||
body += "LED brightness: <input type='range' id='PinLEDPWM' name='PinLEDPWM' min='0' max='255' value='";
|
||||
|
@ -571,7 +580,9 @@ void WEBgrowSettings() {
|
|||
body += "<option value='0'" + returnStrSelected(PinLEDPWM, 0) + ">Off</option>\n";
|
||||
body += "</select><br>\n";
|
||||
}
|
||||
body += "<br>";
|
||||
|
||||
body += "<b>Fan configuration</b><br>";
|
||||
if(UseFANrelais == false) {
|
||||
body += "FAN1 speed: <input type='range' id='PinFANPWM' name='PinFANPWM' min='0' max='255' value='";
|
||||
body += PinFANPWM;
|
||||
|
@ -588,17 +599,52 @@ void WEBgrowSettings() {
|
|||
body += "'/> %<br><br>\n";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
body += "<b>Pump configuration</b><br>";
|
||||
|
||||
// PumpMode byte
|
||||
body += "Pump mode: <select id='UsePump' name='UsePump' required>\n";
|
||||
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
||||
body += "<option value='0'" + returnStrSelected(UsePump, 0) + ">Off</option>\n";
|
||||
body += "<option value='1'" + returnStrSelected(UsePump, 1) + ">1</option>\n";
|
||||
body += "<option value='2'" + returnStrSelected(UsePump, 2) + ">2</option>\n";
|
||||
body += "<option value='3'" + returnStrSelected(UsePump, 3) + ">3</option>\n";
|
||||
body += "</select><br><p class='helpbox'><b>1:</b> Water every few days.<br> \
|
||||
<b>2:</b> Water if the soil moisture falls below <i>Soilmoisture low</i> value<br> \
|
||||
<b>3:</b> Water every few days if the soil moisture falls below <i>Soilmoisture low</i> value.</p>\n";
|
||||
|
||||
// TODO ugly. can this done be better?
|
||||
// PumpOnTime int
|
||||
body += "Pump ON time: <input class='inputShort' type='number' name='PumpOnTime' min='0' max='255' value='";
|
||||
body += PumpOnTime;
|
||||
body += "' required> Seconds<br>\n";
|
||||
|
||||
// SoilmoistureLow byte
|
||||
body += "Soilmoisture low: <input class='inputShort' type='number' name='SoilmoistureLow' min='0' value='";
|
||||
body += SoilmoistureLow;
|
||||
body += "' required> %<br>\n";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
body += "Pump interval vegetation: every <input class='inputShort' type='number' name='PumpIntervalVeg' min='0' max='255' value='";
|
||||
body += PumpIntervalVeg;
|
||||
body += "' required ";
|
||||
if( (UsePump != 1) && UsePump != 3) { body += "readonly"; }
|
||||
body += "> days<br>\n";
|
||||
body += "' required> Days<br>\n";
|
||||
|
||||
body += "Pump interval bloom: every <input class='inputShort' type='number' name='PumpIntervalBloom' min='0' max='255' value='";
|
||||
body += PumpIntervalBloom;
|
||||
body += "' required ";
|
||||
if((UsePump != 1) && (UsePump != 3)) { body += "readonly"; }
|
||||
body += "> days<br>\n";
|
||||
body += "' required> Days<br><br>\n";
|
||||
|
||||
|
||||
body += "<input type='submit' value='💾 Save settings'>\n";
|
||||
|
@ -657,23 +703,23 @@ void WEBsystemSettings() {
|
|||
// OutputInvert bool
|
||||
body += "Invert Outputs: <select id='OutputInvert' name='OutputInvert' required>\n";
|
||||
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
||||
body += "<option value='1'" + returnStrSelected(OutputInvert, 1) + ">Yes</option>\n";
|
||||
body += "<option value='0'" + returnStrSelected(OutputInvert, 0) + ">No</option>\n";
|
||||
body += "<option value='1'" + returnStrSelected(OutputInvert, 1) + ">Yes</option>\n";
|
||||
body += "</select><br>\n";
|
||||
body += "<p class='helpbox'>When using CanGrow PCB v0.6, set to <b>Yes</b></p>\n";
|
||||
|
||||
// UseLEDrelais bool
|
||||
body += "Use relais for LED (disable PWM): <select id='UseLEDrelais' name='UseLEDrelais' required>\n";
|
||||
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
||||
body += "<option value='1'" + returnStrSelected(UseLEDrelais, 1) + ">Yes</option>\n";
|
||||
body += "<option value='0'" + returnStrSelected(UseLEDrelais, 0) + ">No</option>\n";
|
||||
body += "<option value='1'" + returnStrSelected(UseLEDrelais, 1) + ">Yes</option>\n";
|
||||
body += "</select><br>\n";
|
||||
|
||||
// UseFANrelais bool
|
||||
body += "Use relais for FAN1 (disable PWM): <select id='UseFANrelais' name='UseFANrelais' required>\n";
|
||||
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
||||
body += "<option value='1'" + returnStrSelected(UseFANrelais, 1) + ">Yes</option>\n";
|
||||
body += "<option value='0'" + returnStrSelected(UseFANrelais, 0) + ">No</option>\n";
|
||||
body += "<option value='1'" + returnStrSelected(UseFANrelais, 1) + ">Yes</option>\n";
|
||||
body += "</select><br><br>\n";
|
||||
|
||||
|
||||
|
@ -732,36 +778,11 @@ void WEBsystemSettings() {
|
|||
body += "</select><br><br>\n";
|
||||
|
||||
|
||||
body += "<b>Pump configuration</b><br>";
|
||||
|
||||
// PumpMode byte
|
||||
body += "Pump mode: <select id='UsePump' name='UsePump' required>\n";
|
||||
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
||||
body += "<option value='0'" + returnStrSelected(UsePump, 0) + ">Off</option>\n";
|
||||
body += "<option value='1'" + returnStrSelected(UsePump, 1) + ">1</option>\n";
|
||||
body += "<option value='2'" + returnStrSelected(UsePump, 2) + ">2</option>\n";
|
||||
body += "<option value='3'" + returnStrSelected(UsePump, 3) + ">3</option>\n";
|
||||
body += "</select><br><p class='helpbox'><b>1:</b> Water every few days.<br> \
|
||||
<b>2:</b> Water if the soil moisture falls below <i>Soilmoisture low</i> value<br> \
|
||||
<b>3:</b> Water every few days if the soil moisture falls below <i>Soilmoisture low</i> value.</p>\n";
|
||||
|
||||
// TODO ugly. can this done be better?
|
||||
// PumpOnTime int
|
||||
body += "Pump ON time: <input class='inputShort' type='number' name='PumpOnTime' min='0' max='255' value='";
|
||||
body += PumpOnTime;
|
||||
body += "' required> Seconds<br>\n";
|
||||
|
||||
// SoilmoistureLow byte
|
||||
body += "Soilmoisture low: <input class='inputShort' type='number' name='SoilmoistureLow' min='0' value='";
|
||||
body += SoilmoistureLow;
|
||||
body += "' required> %<br><br>\n";
|
||||
|
||||
|
||||
|
||||
body += "<b>General configuration</b><br>";
|
||||
|
||||
// NtpOffset int
|
||||
body += "NTP offset: <input class='inputShort' type='number' name='NtpOffset' min='-12' max='14' value='";
|
||||
body += "NTP offset/UTC timezone: <input class='inputShort' type='number' name='NtpOffset' min='-12' max='14' value='";
|
||||
body += NtpOffset;
|
||||
body+= "' required> Hours<br>\n";
|
||||
|
||||
|
@ -782,7 +803,7 @@ void WEBsystemSettings() {
|
|||
|
||||
body += "ESP32-Cam IP (optional): <input type='text' name='Esp32CamIP' maxlength='16' value='";
|
||||
body += Esp32CamIP;
|
||||
body += "' ><br>\n";
|
||||
body += "' ><br><br>\n";
|
||||
|
||||
|
||||
body += "<input type='submit' value='💾 Save settings'>\n";
|
||||
|
@ -851,7 +872,7 @@ void WEBwifiSettings() {
|
|||
body += "IP: <input type='text' name='WIFIip'><br>\n";
|
||||
body += "Subnet mask: <input type='text' name='WIFInetmask'><br>\n";
|
||||
body += "Gateway: <input type='text' name='WIFIgateway'><br>\n";
|
||||
body += "DNS: <input type='text' name='WIFIdns'><br>\n";
|
||||
body += "DNS: <input type='text' name='WIFIdns'><br><br>\n";
|
||||
body += "<input type='submit' value='💾 Save settings'>\n";
|
||||
body += "</form>\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
|
||||
|
@ -955,6 +990,20 @@ void POSTgrowSettings() {
|
|||
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<JsonObject>();
|
||||
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<JsonObject>();
|
||||
|
|
Loading…
Reference in a new issue