lotsa changes
This commit is contained in:
@@ -38,7 +38,8 @@ while True:
|
|||||||
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjYjY5NjA5NmY0N2E0NmZlOGEzYjczOGYzYmUzOTk5ZSIsImlhdCI6MTY2MTM0NDgxOSwiZXhwIjoxOTc2NzA0ODE5fQ.z9fzbVOA1Pbur3Zb07481n-SoYesj8cetw-CX6WPmTs"
|
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjYjY5NjA5NmY0N2E0NmZlOGEzYjczOGYzYmUzOTk5ZSIsImlhdCI6MTY2MTM0NDgxOSwiZXhwIjoxOTc2NzA0ODE5fQ.z9fzbVOA1Pbur3Zb07481n-SoYesj8cetw-CX6WPmTs"
|
||||||
}
|
}
|
||||||
data = json.dumps({'payload': 'RING', 'topic': 'lewe/doorbell', 'retain': 'False'}).encode('utf8')
|
data = json.dumps({'payload': 'RING', 'topic': 'lewe/doorbell', 'retain': 'False'}).encode('utf8')
|
||||||
reqest = urllib.request.Request("https://www.nodebucket.de:8123/api/services/mqtt/publish", data, headers)
|
request = urllib.request.Request("localhost:8123/api/services/mqtt/publish", data, headers)
|
||||||
|
# request = urllib.request.Request("https://www.nodebucket.de:8123/api/services/mqtt/publish", data, headers)
|
||||||
response = urllib.request.urlopen(reqest)
|
response = urllib.request.urlopen(reqest)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error("Could not ring doorbell")
|
logger.error("Could not ring doorbell")
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
const int ledPin = LED_BUILTIN;
|
const int ledPin = LED_BUILTIN;
|
||||||
const int buttonPin = 2; // Button connected to D2
|
const int buttonPin = 2; // Button connected to D2
|
||||||
const int flare_threshold = 20;
|
const int flare_threshold = 120;
|
||||||
|
|
||||||
bool active = false;
|
bool active = false;
|
||||||
|
|
||||||
|
|||||||
+2094
-4
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 202 KiB After Width: | Height: | Size: 291 KiB |
Binary file not shown.
Binary file not shown.
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Sources:
|
Sources:
|
||||||
* https://randomnerdtutorials.com/esp32-esp8266-web-server-physical-button/
|
https://randomnerdtutorials.com/esp32-esp8266-web-server-physical-button/
|
||||||
* https://randomnerdtutorials.com/esp32-pushover-notifications-arduino/
|
https://randomnerdtutorials.com/esp32-pushover-notifications-arduino/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
@@ -19,27 +19,27 @@ 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"
|
||||||
"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fv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls\n"
|
||||||
"YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n"
|
"YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n"
|
||||||
"CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n"
|
"CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n"
|
||||||
"-----END CERTIFICATE-----\n";
|
"-----END CERTIFICATE-----\n";
|
||||||
|
|
||||||
|
|
||||||
const int PIN_LED = 2; // esp32 dev board integrated LED
|
const int PIN_LED = 2; // esp32 dev board integrated LED
|
||||||
@@ -50,7 +50,7 @@ const int PIN_GARAGE = 22; // relais pin for garage door
|
|||||||
const int PIN_GATE = 23; // relais pin for gate
|
const int PIN_GATE = 23; // relais pin for gate
|
||||||
const int PIN_DOOR_OPEN = 18; // sensor pin for garage door in position 'open'
|
const int PIN_DOOR_OPEN = 18; // sensor pin for garage door in position 'open'
|
||||||
const int PIN_DOOR_CLOSED = 19; // sensor pin for garage door in position 'closed'
|
const int PIN_DOOR_CLOSED = 19; // sensor pin for garage door in position 'closed'
|
||||||
const int PIN_SENSOR_GATE= 21; // sensor pin for gate (HIGH is open)
|
const int PIN_SENSOR_GATE = 21; // sensor pin for gate (HIGH is open)
|
||||||
const int PIN_SPRINKLER1 = 25; // relais pin for sprinkler 1
|
const int PIN_SPRINKLER1 = 25; // relais pin for sprinkler 1
|
||||||
const int PIN_SPRINKLER2 = 33; // relais pin for sprinkler 2
|
const int PIN_SPRINKLER2 = 33; // relais pin for sprinkler 2
|
||||||
const int PIN_SPRINKLER3 = 32; // relais pin for sprinkler 3
|
const int PIN_SPRINKLER3 = 32; // relais pin for sprinkler 3
|
||||||
@@ -70,31 +70,31 @@ int programStatus = 0;
|
|||||||
|
|
||||||
|
|
||||||
void pushover(String message) {
|
void pushover(String message) {
|
||||||
StaticJsonDocument<512> notification;
|
StaticJsonDocument<512> notification;
|
||||||
notification["token"] = apiToken;
|
notification["token"] = apiToken;
|
||||||
notification["user"] = userToken;
|
notification["user"] = userToken;
|
||||||
notification["title"] = "Garage"; //optional
|
notification["title"] = "Garage"; //optional
|
||||||
notification["message"] = message;
|
notification["message"] = message;
|
||||||
|
|
||||||
// Serialize the JSON object to a string
|
// Serialize the JSON object to a string
|
||||||
String jsonStringNotification;
|
String jsonStringNotification;
|
||||||
serializeJson(notification, jsonStringNotification);
|
serializeJson(notification, jsonStringNotification);
|
||||||
|
|
||||||
WiFiClientSecure client;
|
WiFiClientSecure client;
|
||||||
client.setCACert(PUSHOVER_ROOT_CA);
|
client.setCACert(PUSHOVER_ROOT_CA);
|
||||||
|
|
||||||
HTTPClient https;
|
HTTPClient https;
|
||||||
https.begin(client, pushoverApiEndpoint);
|
https.begin(client, pushoverApiEndpoint);
|
||||||
https.addHeader("Content-Type", "application/json");
|
https.addHeader("Content-Type", "application/json");
|
||||||
int httpResponseCode = https.POST(jsonStringNotification);
|
int httpResponseCode = https.POST(jsonStringNotification);
|
||||||
|
|
||||||
if (httpResponseCode > 0) {
|
if (httpResponseCode > 0) {
|
||||||
String response = https.getString();
|
String response = https.getString();
|
||||||
Serial.println("Pushover response: " + String(httpResponseCode) + ", " + String(response));
|
Serial.println("Pushover response: " + String(httpResponseCode) + ", " + String(response));
|
||||||
} else {
|
} else {
|
||||||
Serial.printf("Pushover HTTP response code: %d\n", httpResponseCode);
|
Serial.printf("Pushover HTTP response code: %d\n", httpResponseCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
https.end();
|
https.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,38 +104,38 @@ void notFound(AsyncWebServerRequest *request) {
|
|||||||
|
|
||||||
void pinStatus(AsyncWebServerRequest *request) {
|
void pinStatus(AsyncWebServerRequest *request) {
|
||||||
String status = "esp32garage\n\nPIN_LED (" + String(PIN_LED) + ") = " + String(digitalRead(PIN_LED)) + "\n" +
|
String status = "esp32garage\n\nPIN_LED (" + String(PIN_LED) + ") = " + String(digitalRead(PIN_LED)) + "\n" +
|
||||||
"PIN_GARAGE_BUTTON (" + String(PIN_GARAGE_BUTTON) + ") = " + String(digitalRead(PIN_GARAGE_BUTTON)) + "\n" +
|
"PIN_GARAGE_BUTTON (" + String(PIN_GARAGE_BUTTON) + ") = " + String(digitalRead(PIN_GARAGE_BUTTON)) + "\n" +
|
||||||
"PIN_GATE_BUTTON (" + String(PIN_GATE_BUTTON) + ") = " + String(digitalRead(PIN_GATE_BUTTON)) + "\n" +
|
"PIN_GATE_BUTTON (" + String(PIN_GATE_BUTTON) + ") = " + String(digitalRead(PIN_GATE_BUTTON)) + "\n" +
|
||||||
"PIN_MOWER_ACTIVE (" + String(PIN_MOWER_ACTIVE) + ") = " + String(digitalRead(PIN_MOWER_ACTIVE)) + "\n" +
|
"PIN_MOWER_ACTIVE (" + String(PIN_MOWER_ACTIVE) + ") = " + String(digitalRead(PIN_MOWER_ACTIVE)) + "\n" +
|
||||||
"PIN_GARAGE (" + String(PIN_GARAGE) + ") = " + String(digitalRead(PIN_GARAGE)) + "\n" +
|
"PIN_GARAGE (" + String(PIN_GARAGE) + ") = " + String(digitalRead(PIN_GARAGE)) + "\n" +
|
||||||
"PIN_GATE (" + String(PIN_GATE) + ") = " + String(digitalRead(PIN_GATE)) + "\n" +
|
"PIN_GATE (" + String(PIN_GATE) + ") = " + String(digitalRead(PIN_GATE)) + "\n" +
|
||||||
"PIN_DOOR_OPEN (" + String(PIN_DOOR_OPEN) + ") = " + String(digitalRead(PIN_DOOR_OPEN)) + "\n" +
|
"PIN_DOOR_OPEN (" + String(PIN_DOOR_OPEN) + ") = " + String(digitalRead(PIN_DOOR_OPEN)) + "\n" +
|
||||||
"PIN_DOOR_CLOSED (" + String(PIN_DOOR_CLOSED) + ") = " + String(digitalRead(PIN_DOOR_CLOSED)) + "\n" +
|
"PIN_DOOR_CLOSED (" + String(PIN_DOOR_CLOSED) + ") = " + String(digitalRead(PIN_DOOR_CLOSED)) + "\n" +
|
||||||
"PIN_SENSOR_GATE (" + String(PIN_SENSOR_GATE) + ") = " + String(digitalRead(PIN_SENSOR_GATE)) + "\n" +
|
"PIN_SENSOR_GATE (" + String(PIN_SENSOR_GATE) + ") = " + String(digitalRead(PIN_SENSOR_GATE)) + "\n" +
|
||||||
"PIN_SPRINKLER1 (" + String(PIN_SPRINKLER1) + ") = " + String(digitalRead(PIN_SPRINKLER1)) + "\n" +
|
"PIN_SPRINKLER1 (" + String(PIN_SPRINKLER1) + ") = " + String(digitalRead(PIN_SPRINKLER1)) + "\n" +
|
||||||
"PIN_SPRINKLER2 (" + String(PIN_SPRINKLER2) + ") = " + String(digitalRead(PIN_SPRINKLER2)) + "\n" +
|
"PIN_SPRINKLER2 (" + String(PIN_SPRINKLER2) + ") = " + String(digitalRead(PIN_SPRINKLER2)) + "\n" +
|
||||||
"PIN_SPRINKLER3 (" + String(PIN_SPRINKLER3) + ") = " + String(digitalRead(PIN_SPRINKLER3)) + "\n" +
|
"PIN_SPRINKLER3 (" + String(PIN_SPRINKLER3) + ") = " + String(digitalRead(PIN_SPRINKLER3)) + "\n" +
|
||||||
"PIN_SPRINKLER4 (" + String(PIN_SPRINKLER4) + ") = " + String(digitalRead(PIN_SPRINKLER4)) + "\n" +
|
"PIN_SPRINKLER4 (" + String(PIN_SPRINKLER4) + ") = " + String(digitalRead(PIN_SPRINKLER4)) + "\n" +
|
||||||
"PIN_MOISTURE_ANALOG (" + String(PIN_MOISTURE_ANALOG) + ") = " + String(analogRead(PIN_MOISTURE_ANALOG)) + "\n" +
|
"PIN_MOISTURE_ANALOG (" + String(PIN_MOISTURE_ANALOG) + ") = " + String(analogRead(PIN_MOISTURE_ANALOG)) + "\n" +
|
||||||
"PIN_MOISTURE_DIGITAL (" + String(PIN_MOISTURE_DIGITAL) + ") = " + String(digitalRead(PIN_MOISTURE_DIGITAL)) + "\n\n" +
|
"PIN_MOISTURE_DIGITAL (" + String(PIN_MOISTURE_DIGITAL) + ") = " + String(digitalRead(PIN_MOISTURE_DIGITAL)) + "\n\n" +
|
||||||
"programStatus = " + String(programStatus) + "\n" +
|
"programStatus = " + String(programStatus) + "\n" +
|
||||||
"sprinklerDuration = " + String(sprinklerDuration) + "\n" +
|
"sprinklerDuration = " + String(sprinklerDuration) + "\n" +
|
||||||
"sprinklerStartMillis = " + String(sprinklerStartMillis) + "\n\n" +
|
"sprinklerStartMillis = " + String(sprinklerStartMillis) + "\n\n" +
|
||||||
"/ \n" +
|
"/ \n" +
|
||||||
"/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";
|
"/sprinkler/program[?action=(stop|(start&duration={int}))] \n";
|
||||||
|
|
||||||
request->send(200, "text/plain", status);
|
request->send(200, "text/plain", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mowerSafety() {
|
void mowerSafety() {
|
||||||
Serial.println("mowerSafety()");
|
Serial.println("mowerSafety()");
|
||||||
|
|
||||||
if (http.begin(webClient, "http://192.168.178.54/json?cmd=status&user=lewe&pass=nFdcX3sMD115WAap")) {
|
if (http.begin(webClient, "http://192.168.178.54/json?cmd=status&user=lewe&pass=nFdcX3sMD115WAap")) {
|
||||||
int httpCode = http.GET();
|
int httpCode = http.GET();
|
||||||
|
|
||||||
if (httpCode > 0) {
|
if (httpCode > 0) {
|
||||||
if (httpCode == HTTP_CODE_OK) {
|
if (httpCode == HTTP_CODE_OK) {
|
||||||
String payload = http.getString();
|
String payload = http.getString();
|
||||||
@@ -148,7 +148,7 @@ void mowerSafety() {
|
|||||||
Serial.println("Stop mower");
|
Serial.println("Stop mower");
|
||||||
if (http.begin(webClient, "http://192.168.178.54/json?cmd=stop&user=lewe&pass=nFdcX3sMD115WAap")) {
|
if (http.begin(webClient, "http://192.168.178.54/json?cmd=stop&user=lewe&pass=nFdcX3sMD115WAap")) {
|
||||||
int httpCode = http.GET();
|
int httpCode = http.GET();
|
||||||
|
|
||||||
if (httpCode < 0) {
|
if (httpCode < 0) {
|
||||||
Serial.printf("Mower (STOP) HTTP Error: ", http.errorToString(httpCode).c_str());
|
Serial.printf("Mower (STOP) HTTP Error: ", http.errorToString(httpCode).c_str());
|
||||||
pushover("Mower (STOP) HTTP Error: " + http.errorToString(httpCode));
|
pushover("Mower (STOP) HTTP Error: " + http.errorToString(httpCode));
|
||||||
@@ -179,10 +179,10 @@ void mowerSafety() {
|
|||||||
|
|
||||||
void mowerAuto() {
|
void mowerAuto() {
|
||||||
Serial.println("mowerAuto()");
|
Serial.println("mowerAuto()");
|
||||||
|
|
||||||
if (http.begin(webClient, "http://192.168.178.54/json?cmd=mode&mode=auto&user=lewe&pass=nFdcX3sMD115WAap")) {
|
if (http.begin(webClient, "http://192.168.178.54/json?cmd=mode&mode=auto&user=lewe&pass=nFdcX3sMD115WAap")) {
|
||||||
int httpCode = http.GET();
|
int httpCode = http.GET();
|
||||||
|
|
||||||
if (httpCode < 0) {
|
if (httpCode < 0) {
|
||||||
Serial.printf("Mower (AUTO) HTTP Error: ", http.errorToString(httpCode).c_str());
|
Serial.printf("Mower (AUTO) HTTP Error: ", http.errorToString(httpCode).c_str());
|
||||||
pushover("Mower (AUTO) HTTP Error: " + http.errorToString(httpCode));
|
pushover("Mower (AUTO) HTTP Error: " + http.errorToString(httpCode));
|
||||||
@@ -197,7 +197,7 @@ void mowerAuto() {
|
|||||||
|
|
||||||
void triggerGarage() {
|
void triggerGarage() {
|
||||||
Serial.println("Trigger garage door");
|
Serial.println("Trigger garage door");
|
||||||
|
|
||||||
digitalWrite(PIN_GARAGE, LOW);
|
digitalWrite(PIN_GARAGE, LOW);
|
||||||
digitalWrite(PIN_LED, HIGH);
|
digitalWrite(PIN_LED, HIGH);
|
||||||
delay(400);
|
delay(400);
|
||||||
@@ -207,12 +207,12 @@ void triggerGarage() {
|
|||||||
|
|
||||||
void triggerGate() {
|
void triggerGate() {
|
||||||
Serial.println("Trigger gate");
|
Serial.println("Trigger gate");
|
||||||
|
|
||||||
bool toSafety = false;
|
bool toSafety = false;
|
||||||
if (not digitalRead(PIN_SENSOR_GATE)) {
|
if (not digitalRead(PIN_SENSOR_GATE)) {
|
||||||
toSafety = true;
|
toSafety = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
digitalWrite(PIN_GATE, LOW);
|
digitalWrite(PIN_GATE, LOW);
|
||||||
digitalWrite(PIN_LED, HIGH);
|
digitalWrite(PIN_LED, HIGH);
|
||||||
delay(400);
|
delay(400);
|
||||||
@@ -235,7 +235,7 @@ void triggerGate() {
|
|||||||
|
|
||||||
void stopSprinklers() {
|
void stopSprinklers() {
|
||||||
Serial.println("Stopping sprinklers");
|
Serial.println("Stopping sprinklers");
|
||||||
|
|
||||||
digitalWrite(PIN_SPRINKLER1, HIGH);
|
digitalWrite(PIN_SPRINKLER1, HIGH);
|
||||||
digitalWrite(PIN_SPRINKLER2, HIGH);
|
digitalWrite(PIN_SPRINKLER2, HIGH);
|
||||||
digitalWrite(PIN_SPRINKLER3, HIGH);
|
digitalWrite(PIN_SPRINKLER3, HIGH);
|
||||||
@@ -246,7 +246,7 @@ void setup() {
|
|||||||
// start serial output
|
// start serial output
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
btStop(); // turn off bluetooth
|
btStop(); // turn off bluetooth
|
||||||
|
|
||||||
pinMode(PIN_LED, OUTPUT);
|
pinMode(PIN_LED, OUTPUT);
|
||||||
@@ -265,14 +265,14 @@ void setup() {
|
|||||||
pinMode(PIN_MOISTURE_DIGITAL, INPUT);
|
pinMode(PIN_MOISTURE_DIGITAL, INPUT);
|
||||||
|
|
||||||
digitalWrite(PIN_LED, HIGH);
|
digitalWrite(PIN_LED, HIGH);
|
||||||
|
|
||||||
digitalWrite(PIN_GARAGE, HIGH);
|
digitalWrite(PIN_GARAGE, HIGH);
|
||||||
digitalWrite(PIN_GATE, HIGH);
|
digitalWrite(PIN_GATE, HIGH);
|
||||||
digitalWrite(PIN_SPRINKLER1, HIGH);
|
digitalWrite(PIN_SPRINKLER1, HIGH);
|
||||||
digitalWrite(PIN_SPRINKLER2, HIGH);
|
digitalWrite(PIN_SPRINKLER2, HIGH);
|
||||||
digitalWrite(PIN_SPRINKLER3, HIGH);
|
digitalWrite(PIN_SPRINKLER3, HIGH);
|
||||||
digitalWrite(PIN_SPRINKLER4, HIGH);
|
digitalWrite(PIN_SPRINKLER4, HIGH);
|
||||||
|
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
@@ -281,12 +281,12 @@ void setup() {
|
|||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
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();
|
||||||
@@ -313,7 +313,7 @@ void setup() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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();
|
||||||
@@ -340,7 +340,7 @@ void setup() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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();
|
||||||
@@ -377,30 +377,23 @@ void setup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
stopSprinklers();
|
stopSprinklers();
|
||||||
request->send(200, "application/json", "{ \"action\": \"stop\" }");
|
request->send(200, "application/json", "{ \"action\": \"stop\" }");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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")) {
|
||||||
|
|
||||||
Serial.println("action");
|
|
||||||
action = request->getParam("action")->value();
|
action = request->getParam("action")->value();
|
||||||
|
|
||||||
Serial.println(action.equals("start"));
|
|
||||||
Serial.println(request->hasParam("duration"));
|
|
||||||
|
|
||||||
if (action.equals("start") and request->hasParam("duration")) {
|
if (action.equals("start") and request->hasParam("duration")) {
|
||||||
String duration = request->getParam("duration")->value();
|
String duration = request->getParam("duration")->value();
|
||||||
sprinklerDuration = duration.toInt();
|
sprinklerDuration = duration.toInt();
|
||||||
sprinklerDuration = sprinklerDuration * 60 * 1000;
|
sprinklerDuration = sprinklerDuration * 60 * 500; // XXX Terrasse nur halb so lange bewässern
|
||||||
sprinklerStartMillis = millis();
|
sprinklerStartMillis = millis();
|
||||||
|
|
||||||
programStatus = 4;
|
programStatus = 4;
|
||||||
digitalWrite(PIN_SPRINKLER4, LOW);
|
digitalWrite(PIN_SPRINKLER4, LOW);
|
||||||
sprinklerStartMillis = sprinklerStartMillis + ((sprinklerDuration / 2) * 60 * 1000); // XXX Terrasse nur halb so lange bewässern
|
|
||||||
request->send(200, "application/json", "{ \"action\": \"start\" }");
|
request->send(200, "application/json", "{ \"action\": \"start\" }");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -409,7 +402,7 @@ void setup() {
|
|||||||
request->send(200, "application/json", "{ \"action\": \"stop\" }");
|
request->send(200, "application/json", "{ \"action\": \"stop\" }");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String statusString = "false";
|
String statusString = "false";
|
||||||
if (programStatus > 0) {
|
if (programStatus > 0) {
|
||||||
statusString = "true";
|
statusString = "true";
|
||||||
@@ -436,9 +429,14 @@ void loop() {
|
|||||||
if ((sprinklerDuration > 0) and ((millis() - sprinklerStartMillis) > sprinklerDuration)) {
|
if ((sprinklerDuration > 0) and ((millis() - sprinklerStartMillis) > sprinklerDuration)) {
|
||||||
stopSprinklers();
|
stopSprinklers();
|
||||||
if (programStatus > 0) {
|
if (programStatus > 0) {
|
||||||
|
|
||||||
|
if (programStatus == 4) {
|
||||||
|
sprinklerDuration = sprinklerDuration * 2; // XXX Terrasse nur halb so lange bewässern
|
||||||
|
}
|
||||||
|
|
||||||
programStatus--;
|
programStatus--;
|
||||||
sprinklerStartMillis = millis();
|
sprinklerStartMillis = millis();
|
||||||
|
|
||||||
if (programStatus == 3) {
|
if (programStatus == 3) {
|
||||||
digitalWrite(PIN_SPRINKLER3, LOW);
|
digitalWrite(PIN_SPRINKLER3, LOW);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Soil moisture sensor on Wemos D1
|
||||||
|
*/
|
||||||
|
|
||||||
|
// the analog input on the Wemos D1 accepts up to 3.3V
|
||||||
|
const int analogPin = A2;
|
||||||
|
int val = 0;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
Serial.println("Starting moisture measurement");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
val = analogRead(analogPin);
|
||||||
|
Serial.println(val);
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user