garage_esp32 - v0.1
This commit is contained in:
@@ -42,19 +42,21 @@ const char *PUSHOVER_ROOT_CA = "-----BEGIN CERTIFICATE-----\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
|
||||||
const int PIN_GARAGE_BUTTON = 4; // button to open/close the garage door
|
const int PIN_GARAGE_BUTTON = 4; // button to open/close the garage door
|
||||||
const int PIN_GATE_BUTTON = 16; // button to open/close the gate
|
const int PIN_GATE_BUTTON = 16; // button to open/close the gate
|
||||||
const int PIN_MOWER_ACTIVE = 15; // only contact mower if pin is HIGH
|
const int PIN_MOWER_ACTIVE = 12; // only contact mower if pin is LOW
|
||||||
const int PIN_GARAGE = 17; // relais pin for garage door
|
const int PIN_GARAGE = 22; // relais pin for garage door
|
||||||
const int PIN_GATE = 5; // 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 = 26; // relais pin for sprinkler 1
|
const int PIN_SPRINKLER1 = 26; // relais pin for sprinkler 1
|
||||||
const int PIN_SPRINKLER2 = 25; // relais pin for sprinkler 2
|
const int PIN_SPRINKLER2 = 25; // relais pin for sprinkler 2
|
||||||
const int PIN_SPRINKLER3 = 33; // relais pin for sprinkler 3
|
const int PIN_SPRINKLER3 = 33; // relais pin for sprinkler 3
|
||||||
const int PIN_SPRINKLER4 = 32; // relais pin for sprinkler 4
|
const int PIN_SPRINKLER4 = 32; // relais pin for sprinkler 4
|
||||||
|
const int PIN_MOISTURE_ANALOG = 14; // moisture sensor analog value // XXX currently blocked by WiFi
|
||||||
|
const int PIN_MOISTURE_DIGITAL = 27; // moisture sensor digital value
|
||||||
|
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
const char* PARAM_MESSAGE = "message";
|
const char* PARAM_MESSAGE = "message";
|
||||||
@@ -111,7 +113,9 @@ void pinStatus(AsyncWebServerRequest *request) {
|
|||||||
"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\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_DIGITAL (" + String(PIN_MOISTURE_DIGITAL) + ") = " + String(digitalRead(PIN_MOISTURE_DIGITAL)) + "\n\n" +
|
||||||
"sprinklerDuration = " + String(sprinklerDuration) + "\n" +
|
"sprinklerDuration = " + String(sprinklerDuration) + "\n" +
|
||||||
"sprinklerStartMillis = " + String(sprinklerStartMillis) + "\n\n" +
|
"sprinklerStartMillis = " + String(sprinklerStartMillis) + "\n\n" +
|
||||||
"/ \n" +
|
"/ \n" +
|
||||||
@@ -212,7 +216,7 @@ void triggerGate() {
|
|||||||
digitalWrite(PIN_LED, LOW);
|
digitalWrite(PIN_LED, LOW);
|
||||||
|
|
||||||
// DEAKTIVIEREN FÜR WINTERPAUSE:
|
// DEAKTIVIEREN FÜR WINTERPAUSE:
|
||||||
if (digitalRead(PIN_MOWER_ACTIVE)) {
|
if (digitalRead(PIN_MOWER_ACTIVE) == LOW) {
|
||||||
if (toSafety) {
|
if (toSafety) {
|
||||||
mowerSafety();
|
mowerSafety();
|
||||||
}
|
}
|
||||||
@@ -243,18 +247,19 @@ void setup() {
|
|||||||
btStop(); // turn off bluetooth
|
btStop(); // turn off bluetooth
|
||||||
|
|
||||||
pinMode(PIN_LED, OUTPUT);
|
pinMode(PIN_LED, OUTPUT);
|
||||||
pinMode(PIN_GARAGE_BUTTON, INPUT);
|
pinMode(PIN_GARAGE_BUTTON, INPUT_PULLUP);
|
||||||
pinMode(PIN_GATE_BUTTON, INPUT);
|
pinMode(PIN_GATE_BUTTON, INPUT_PULLUP);
|
||||||
pinMode(PIN_MOWER_ACTIVE, INPUT);
|
pinMode(PIN_MOWER_ACTIVE, INPUT_PULLUP);
|
||||||
pinMode(PIN_GARAGE, OUTPUT);
|
pinMode(PIN_GARAGE, OUTPUT);
|
||||||
pinMode(PIN_GATE, OUTPUT);
|
pinMode(PIN_GATE, OUTPUT);
|
||||||
pinMode(PIN_DOOR_OPEN, INPUT);
|
pinMode(PIN_DOOR_OPEN, INPUT_PULLUP);
|
||||||
pinMode(PIN_DOOR_CLOSED, INPUT);
|
pinMode(PIN_DOOR_CLOSED, INPUT_PULLUP);
|
||||||
pinMode(PIN_SENSOR_GATE, INPUT);
|
pinMode(PIN_SENSOR_GATE, INPUT_PULLUP);
|
||||||
pinMode(PIN_SPRINKLER1, OUTPUT);
|
pinMode(PIN_SPRINKLER1, OUTPUT);
|
||||||
pinMode(PIN_SPRINKLER2, OUTPUT);
|
pinMode(PIN_SPRINKLER2, OUTPUT);
|
||||||
pinMode(PIN_SPRINKLER3, OUTPUT);
|
pinMode(PIN_SPRINKLER3, OUTPUT);
|
||||||
pinMode(PIN_SPRINKLER4, OUTPUT);
|
pinMode(PIN_SPRINKLER4, OUTPUT);
|
||||||
|
pinMode(PIN_MOISTURE_DIGITAL, INPUT);
|
||||||
|
|
||||||
digitalWrite(PIN_GARAGE, HIGH);
|
digitalWrite(PIN_GARAGE, HIGH);
|
||||||
digitalWrite(PIN_GATE, HIGH);
|
digitalWrite(PIN_GATE, HIGH);
|
||||||
@@ -263,6 +268,7 @@ void setup() {
|
|||||||
digitalWrite(PIN_SPRINKLER3, HIGH);
|
digitalWrite(PIN_SPRINKLER3, HIGH);
|
||||||
digitalWrite(PIN_SPRINKLER4, HIGH);
|
digitalWrite(PIN_SPRINKLER4, HIGH);
|
||||||
|
|
||||||
|
digitalWrite(PIN_LED, HIGH);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
@@ -271,6 +277,7 @@ void setup() {
|
|||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
WiFi.setAutoReconnect(true);
|
WiFi.setAutoReconnect(true);
|
||||||
WiFi.persistent(true);
|
WiFi.persistent(true);
|
||||||
|
digitalWrite(PIN_LED, LOW);
|
||||||
|
|
||||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
pinStatus(request);
|
pinStatus(request);
|
||||||
@@ -341,21 +348,22 @@ void setup() {
|
|||||||
request->send(200, "application/json", "{ \"action\": \"stop\" }");
|
request->send(200, "application/json", "{ \"action\": \"stop\" }");
|
||||||
}
|
}
|
||||||
else if (action.equals("start") and (request->hasParam("device")) and (request->hasParam("duration"))) {
|
else if (action.equals("start") and (request->hasParam("device")) and (request->hasParam("duration"))) {
|
||||||
|
stopSprinklers(); // only run one sprinkler at a time
|
||||||
String device = request->getParam("device")->value();
|
String device = request->getParam("device")->value();
|
||||||
String duration = request->getParam("duration")->value();
|
String duration = request->getParam("duration")->value();
|
||||||
sprinklerDuration = duration.toInt();
|
sprinklerDuration = duration.toInt();
|
||||||
sprinklerStartMillis = millis();
|
sprinklerStartMillis = millis();
|
||||||
if (device.equals("1")) {
|
if (device.equals("1")) {
|
||||||
digitalWrite(PIN_SPRINKLER1, HIGH);
|
digitalWrite(PIN_SPRINKLER1, LOW);
|
||||||
}
|
}
|
||||||
else if (device.equals("2")) {
|
else if (device.equals("2")) {
|
||||||
digitalWrite(PIN_SPRINKLER2, HIGH);
|
digitalWrite(PIN_SPRINKLER2, LOW);
|
||||||
}
|
}
|
||||||
else if (device.equals("3")) {
|
else if (device.equals("3")) {
|
||||||
digitalWrite(PIN_SPRINKLER3, HIGH);
|
digitalWrite(PIN_SPRINKLER3, LOW);
|
||||||
}
|
}
|
||||||
else if (device.equals("4")) {
|
else if (device.equals("4")) {
|
||||||
digitalWrite(PIN_SPRINKLER4, HIGH);
|
digitalWrite(PIN_SPRINKLER4, LOW);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sprinklerDuration = 0;
|
sprinklerDuration = 0;
|
||||||
@@ -386,8 +394,8 @@ void setup() {
|
|||||||
|
|
||||||
unsigned long lastDebounceTime = 0;
|
unsigned long lastDebounceTime = 0;
|
||||||
unsigned long debounceDelay = 80;
|
unsigned long debounceDelay = 80;
|
||||||
int lastValGarage = LOW;
|
int lastValGarage = HIGH;
|
||||||
int lastValGate = LOW;
|
int lastValGate = HIGH;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
@@ -397,15 +405,14 @@ void loop() {
|
|||||||
|
|
||||||
int newVal = digitalRead(PIN_GARAGE_BUTTON);
|
int newVal = digitalRead(PIN_GARAGE_BUTTON);
|
||||||
if (newVal != lastValGarage) {
|
if (newVal != lastValGarage) {
|
||||||
Serial.print("Garage Button: ");
|
Serial.println("Garage Button");
|
||||||
lastDebounceTime = millis();
|
lastDebounceTime = millis();
|
||||||
while (((millis() - lastDebounceTime) < debounceDelay) and digitalRead(PIN_GARAGE_BUTTON) != lastValGarage) {
|
while (((millis() - lastDebounceTime) < debounceDelay) and digitalRead(PIN_GARAGE_BUTTON) != lastValGarage) {
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
if (digitalRead(PIN_GARAGE_BUTTON) != lastValGarage) {
|
if (digitalRead(PIN_GARAGE_BUTTON) != lastValGarage) {
|
||||||
Serial.println("REAL");
|
|
||||||
lastValGarage = newVal;
|
lastValGarage = newVal;
|
||||||
if (newVal == HIGH) {
|
if (newVal == LOW) {
|
||||||
triggerGarage();
|
triggerGarage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,15 +423,14 @@ void loop() {
|
|||||||
|
|
||||||
newVal = digitalRead(PIN_GATE_BUTTON);
|
newVal = digitalRead(PIN_GATE_BUTTON);
|
||||||
if (newVal != lastValGate) {
|
if (newVal != lastValGate) {
|
||||||
Serial.print("Gate Button: ");
|
Serial.print("Gate Button");
|
||||||
lastDebounceTime = millis();
|
lastDebounceTime = millis();
|
||||||
while (((millis() - lastDebounceTime) < debounceDelay) and digitalRead(PIN_GATE_BUTTON) != lastValGate) {
|
while (((millis() - lastDebounceTime) < debounceDelay) and digitalRead(PIN_GATE_BUTTON) != lastValGate) {
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
if (digitalRead(PIN_GATE_BUTTON) != lastValGate) {
|
if (digitalRead(PIN_GATE_BUTTON) != lastValGate) {
|
||||||
Serial.println("REAL");
|
|
||||||
lastValGate = newVal;
|
lastValGate = newVal;
|
||||||
if (newVal == HIGH) {
|
if (newVal == LOW) {
|
||||||
triggerGate();
|
triggerGate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user