garage_esp32.ino bugfixes
This commit is contained in:
@@ -20,7 +20,7 @@ const char* apiToken = "a9k1uyzypuaz1yszqqdzmp17s6r5q2";
|
|||||||
const char* userToken = "ukja84pd2n2cmxvdrnfwdrf8eo1wc5";
|
const char* userToken = "ukja84pd2n2cmxvdrnfwdrf8eo1wc5";
|
||||||
const char* pushoverApiEndpoint = "https://api.pushover.net/1/messages.json";
|
const char* pushoverApiEndpoint = "https://api.pushover.net/1/messages.json";
|
||||||
|
|
||||||
const char *PUSHOVER_ROOT_CA = "-----BEGIN CERTIFICATE-----\n"
|
const char* PUSHOVER_ROOT_CA = "-----BEGIN CERTIFICATE-----\n"
|
||||||
"MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n"
|
"MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n"
|
||||||
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n"
|
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n"
|
||||||
"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n"
|
"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n"
|
||||||
@@ -100,7 +100,7 @@ void pushover(String message) {
|
|||||||
https.end();
|
https.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void notFound(AsyncWebServerRequest *request) {
|
void notFound(AsyncWebServerRequest* request) {
|
||||||
request->send(404, "text/plain", "Not found");
|
request->send(404, "text/plain", "Not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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,14 +274,15 @@ 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);
|
||||||
|
|
||||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
pinStatus(request);
|
pinStatus(request);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/garage", HTTP_GET, [] (AsyncWebServerRequest * request) {
|
server.on("/garage", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
String action;
|
String action;
|
||||||
if (request->hasParam("action")) {
|
if (request->hasParam("action")) {
|
||||||
action = request->getParam("action")->value();
|
action = request->getParam("action")->value();
|
||||||
@@ -296,26 +290,22 @@ 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\" }");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/gate", HTTP_GET, [] (AsyncWebServerRequest * request) {
|
server.on("/gate", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
String action;
|
String action;
|
||||||
if (request->hasParam("action")) {
|
if (request->hasParam("action")) {
|
||||||
action = request->getParam("action")->value();
|
action = request->getParam("action")->value();
|
||||||
@@ -323,26 +313,22 @@ 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\" }");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/sprinkler", HTTP_GET, [] (AsyncWebServerRequest * request) {
|
server.on("/sprinkler", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
String action;
|
String action;
|
||||||
if (request->hasParam("action")) {
|
if (request->hasParam("action")) {
|
||||||
action = request->getParam("action")->value();
|
action = request->getParam("action")->value();
|
||||||
@@ -357,34 +343,29 @@ 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) {
|
||||||
String action;
|
String action;
|
||||||
if (request->hasParam("action")) {
|
if (request->hasParam("action")) {
|
||||||
action = request->getParam("action")->value();
|
action = request->getParam("action")->value();
|
||||||
@@ -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