garage_esp32.ino bugfixes

This commit is contained in:
2026-07-17 22:43:55 +00:00
parent d5046b4ba9
commit 2da7555ce1
+31 -56
View File
@@ -127,7 +127,7 @@ void pinStatus(AsyncWebServerRequest *request) {
"/garage[?action=(open|close)] \n" +
"/gate[?action=(open|close)] \n" +
"/sprinkler[?action=(stop|(start&device={int}&duration={int}))] \n" +
"/sprinkler/program[?action=(stop|(start&duration={int}))] \n";
"/irrigation[?action=(stop|(start&duration={int}))] \n";
request->send(200, "text/plain", status);
}
@@ -156,24 +156,20 @@ void mowerSafety() {
pushover("Mower (STOP) HTTP Error: " + http.errorToString(httpCode));
}
http.end();
}
else {
} else {
Serial.println("Could not send HTTP request (STOP) to mower");
pushover("Could not send HTTP request (STOP) to mower");
}
}
else {
} else {
Serial.println("no status to be stopped");
}
}
}
else {
} else {
Serial.printf("Mower (STATUS) HTTP Error: ", http.errorToString(httpCode).c_str());
pushover("Mower (STATUS) HTTP Error: " + http.errorToString(httpCode));
}
http.end();
}
else {
} else {
Serial.println("Could not send HTTP request (STATUS) to mower");
pushover("Could not send HTTP request (STATUS) to mower");
}
@@ -190,8 +186,7 @@ void mowerAuto() {
pushover("Mower (AUTO) HTTP Error: " + http.errorToString(httpCode));
}
http.end();
}
else {
} else {
Serial.println("Could not send HTTP request (AUTO) to mower");
pushover("Could not send HTTP request (AUTO) to mower");
}
@@ -225,12 +220,10 @@ void triggerGate() {
if (digitalRead(PIN_MOWER_ACTIVE) == LOW) {
if (toSafety) {
mowerSafety();
}
else {
} else {
mowerAuto();
}
}
else {
} else {
Serial.println("Mower set to inactive");
}
}
@@ -281,6 +274,7 @@ void setup() {
Serial.println("Connecting to WiFi...");
}
Serial.println(WiFi.localIP());
Serial.println(WiFi.macAddress());
WiFi.setAutoReconnect(true);
WiFi.persistent(true);
@@ -296,20 +290,16 @@ void setup() {
if (action.equals("open") and digitalRead(PIN_DOOR_CLOSED) and not digitalRead(PIN_DOOR_OPEN)) {
request->send(200, "application/json", "{ \"action\": \"open\" }");
triggerGarage();
}
else if (action.equals("close") and digitalRead(PIN_DOOR_OPEN) and not digitalRead(PIN_DOOR_CLOSED)) {
} else if (action.equals("close") and digitalRead(PIN_DOOR_OPEN) and not digitalRead(PIN_DOOR_CLOSED)) {
request->send(200, "application/json", "{ \"action\": \"close\" }");
triggerGarage();
}
else {
} else {
pinStatus(request);
}
}
else {
} else {
if (digitalRead(PIN_DOOR_OPEN) and not digitalRead(PIN_DOOR_CLOSED)) {
request->send(200, "application/json", "{ \"status\": \"true\" }");
}
else {
} else {
request->send(200, "application/json", "{ \"status\": \"false\" }");
}
}
@@ -323,20 +313,16 @@ void setup() {
if (action.equals("open") and not digitalRead(PIN_SENSOR_GATE)) {
request->send(200, "application/json", "{ \"action\": \"open\" }");
triggerGate();
}
else if (action.equals("close") and digitalRead(PIN_SENSOR_GATE)) {
} else if (action.equals("close") and digitalRead(PIN_SENSOR_GATE)) {
request->send(200, "application/json", "{ \"action\": \"close\" }");
triggerGate();
}
else {
} else {
pinStatus(request);
}
}
else {
} else {
if (digitalRead(PIN_SENSOR_GATE)) {
request->send(200, "application/json", "{ \"status\": \"true\" }");
}
else {
} else {
request->send(200, "application/json", "{ \"status\": \"false\" }");
}
}
@@ -357,31 +343,26 @@ void setup() {
sprinklerStartMillis = millis();
if (device.equals("1")) {
digitalWrite(PIN_SPRINKLER1, LOW);
}
else if (device.equals("2")) {
} else if (device.equals("2")) {
digitalWrite(PIN_SPRINKLER2, LOW);
}
else if (device.equals("3")) {
} else if (device.equals("3")) {
digitalWrite(PIN_SPRINKLER3, LOW);
}
else if (device.equals("4")) {
} else if (device.equals("4")) {
digitalWrite(PIN_SPRINKLER4, LOW);
}
else {
} else {
sprinklerDuration = 0;
}
request->send(200, "application/json", "{ \"action\": \"start\" }");
}
else {
} else {
stopSprinklers();
request->send(200, "application/json", "{ \"action\": \"stop\" }");
}
}
else {
} else {
stopSprinklers();
request->send(200, "application/json", "{ \"action\": \"stop\" }");
}
programStatus = 0;
});
server.on("/irrigation", HTTP_GET, [](AsyncWebServerRequest* request) {
@@ -397,8 +378,7 @@ void setup() {
programStatus = 4;
digitalWrite(PIN_SPRINKLER4, LOW);
request->send(200, "application/json", "{ \"action\": \"start\" }");
}
else {
} else {
stopSprinklers();
programStatus = 0;
request->send(200, "application/json", "{ \"action\": \"stop\" }");
@@ -430,7 +410,7 @@ void loop() {
if ((sprinklerDuration > 0) and ((millis() - sprinklerStartMillis) > sprinklerDuration)) {
stopSprinklers();
if (programStatus > 0) {
if (programStatus > 1) {
if (programStatus == 4) {
sprinklerDuration = sprinklerDuration * 2; // XXX Terrasse nur halb so lange bewässern
@@ -441,15 +421,12 @@ void loop() {
if (programStatus == 3) {
digitalWrite(PIN_SPRINKLER3, LOW);
}
else if (programStatus == 2) {
} else if (programStatus == 2) {
digitalWrite(PIN_SPRINKLER2, LOW);
}
else if (programStatus == 1) {
} else if (programStatus == 1) {
digitalWrite(PIN_SPRINKLER1, LOW);
}
}
else {
} else {
sprinklerDuration = 0;
sprinklerStartMillis = 0;
}
@@ -467,8 +444,7 @@ void loop() {
if (newVal == LOW) {
triggerGarage();
}
}
else {
} else {
Serial.println("fluke");
}
}
@@ -485,8 +461,7 @@ void loop() {
if (newVal == LOW) {
triggerGate();
}
}
else {
} else {
Serial.println("fluke");
}
}