firmware wip

This commit is contained in:
Marcus 2024-04-18 02:13:05 +02:00
parent 56ce028b38
commit ce55c874ec
1 changed files with 63 additions and 3 deletions

View File

@ -80,7 +80,7 @@ char WebUiPassword[32] = "cangrow";
// configured - if false, let the user configure system settings first
bool configured = false;
// NTP Offset
int ntpOffset = 0;
int ntpOffset;
// MoistureSensor_Type - contains which moisture sensor to use
// 1: analog capacitive sensor
// 2: I2C chirp sensor from catnip electronics
@ -1037,7 +1037,10 @@ void WebHandler() {
// failed whole page every call. we can save up this 0,5kb traffic :o)
webserver.on("/favicon.ico", [](){ webserver.send(404, "text/html", "404 - not found"); });
webserver.onNotFound(WEB404);
// switching MOSFETs
webserver.on("/switch", HTTP_POST, POSTswitchMOSFET);
}
void WebRestart() {
@ -1245,7 +1248,28 @@ void WEBroot() {
}
}
body += "<form method='post' action='/switch'>";
body += "MOSFET<select id='output' name='output' required>\n";
body += "<option disabled value='' selected hidden>---</option>\n";
body += "<option value='1'>LED</option>\n";
body += "<option value='2'>PUMP</option>\n";
body += "<option value='3'>FAN</option>\n";
body += "</select><br>";
body += "On/Off: <select id='state' name='state' required>\n";
body += "<option disabled value='' selected hidden>---</option>\n";
body += "<option value='1'>On</option>\n";
body += "<option value='0'>Off</option>\n";
body += "</select><br>\n";
body += "<input type='submit' value='Save'>\n";
body += "</form>";
body += "</p>";
body += returnHTMLfooter();
webserver.send(200, "text/html", body);
@ -1529,7 +1553,7 @@ void POSTgrowSettings() {
analogWrite(PINled, PINled_PWM);
//analogWrite(PINled, PINled_PWM);
Serial.println(":: POSTgrowSettings ::");
@ -1678,7 +1702,43 @@ void POSTwifiSettings() {
webserver.send(302, "text/plain", "wifiSettings/save: success!");
}
void POSTswitchMOSFET() {
byte MosfetState = webserver.arg("state").toInt();
byte MosfetNr = webserver.arg("output").toInt();
Serial.println(":: GETswitchMOSFET ::");
Serial.print("MosfetState: ");
Serial.println(MosfetState);
Serial.print("MosfetNr: ");
Serial.println(MosfetNr);
if((MosfetState > 1) || (MosfetState < 0)) {
webserver.send(400, "text/plain", "not valid\n");
} else {
switch(MosfetNr) {
case 1:
if( MosfetState == 1) {
analogWrite(PINled, PINled_PWM);
} else {
digitalWrite(PINled, MosfetState);
}
break;
case 2:
digitalWrite(PINpump, MosfetState);
break;
case 3:
digitalWrite(PINfan, MosfetState);
break;
default:
webserver.send(400, "text/plain", "not valid\n");
break;
}
webserver.sendHeader("Location", String("/?success"), true);
webserver.send(302, "text/plain", "wifiSettings/save: success!");
}
}
/*
String JSreplaceStr(String elementID, String content) {
String jsReturn = "<script>document.getElementById('" + elementID + "').innerHTML='" + content + "';</script>";