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