From c8ac9c2bd497e315f1443020b186aaae30e0661f Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Sun, 19 May 2019 17:35:40 +0200 Subject: [PATCH] small changes --- .vscode/arduino.json | 2 +- src/controller_main.cpp | 20 ++++++++++++-------- src/light_main.cpp | 12 ++++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.vscode/arduino.json b/.vscode/arduino.json index 0d7bfac..484753f 100644 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -1,5 +1,5 @@ { "board": "esp8266:esp8266:d1", "configuration": "xtal=80,vt=flash,exception=disabled,eesz=4M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=921600", - "port": "/dev/cu.wchusbserial141230" + "port": "/dev/cu.usbserial-141230" } \ No newline at end of file diff --git a/src/controller_main.cpp b/src/controller_main.cpp index 85df97f..8b83256 100644 --- a/src/controller_main.cpp +++ b/src/controller_main.cpp @@ -8,6 +8,7 @@ #include +#define TRIGGER_TIMEOUT 60000 #define PIN_ACTIVATE 5 #define PIN_CLEAR 2 bool inputActive = true; @@ -138,8 +139,8 @@ void setup() { server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { // Print a small status response page with the most important messages String statusHTML = ""; - statusHTML += "

Audio2 Cabin Light System


Current Status:
"; - statusHTML += "
LampStatus"; + statusHTML += "

Audio2 Cabin Light System


Current Status:
"; + statusHTML += ""; for (int i = 0; i < 4; i++) { statusHTML += "
LampStatus
Lamp "; @@ -156,9 +157,12 @@ void setup() { statusHTML += "
"; statusHTML += "Input clear: "; statusHTML += clearActive ? "inactive (high)" : "active (low)"; - statusHTML += "
"; + statusHTML += "
Timeout: "; + statusHTML += (activateTimeout == 0 || millis() - activateTimeout >= TRIGGER_TIMEOUT) ? "active" : "inactive"; - request->send(200, "text/plain", statusHTML); + statusHTML += "
"; + + request->send(200, "text/html", statusHTML); }); server.on("/allblink", HTTP_GET, [](AsyncWebServerRequest *request) { @@ -198,11 +202,13 @@ void loop() { if (digitalRead(PIN_ACTIVATE) != inputActive) { inputActive = digitalRead(PIN_ACTIVATE); - if (!inputActive) { // React when the signal starts - if (millis() - activateTimeout >= 60000) { // 1 Minute timeout + if (!inputActive) { // React when the signal starts + if (activateTimeout == 0 || millis() - activateTimeout >= TRIGGER_TIMEOUT) { // 1 Minute timeout Serial.println("Activate triggered"); ws.textAll("lampon"); lastSent = "ON"; + } else { + Serial.println("Wait 1 minute to retrigger lights"); } } } @@ -221,8 +227,6 @@ void loop() { } } } - - delay(1); } /////////////////////////// diff --git a/src/light_main.cpp b/src/light_main.cpp index 7318f12..2be20d6 100644 --- a/src/light_main.cpp +++ b/src/light_main.cpp @@ -33,7 +33,7 @@ void WiFiEvent(WiFiEvent_t event) { case SYSTEM_EVENT_ETH_START: Serial.println("ETH Started"); // set eth hostname here - ETH.setHostname("a2clight"); + ETH.setHostname("a2clight" + LIGHT_NUMBER); break; case SYSTEM_EVENT_ETH_CONNECTED: Serial.println("ETH Connected"); @@ -105,10 +105,10 @@ void webSocketEvent(WStype_t type, uint8_t *payload, size_t length) { Serial.println("Disable Blinking!"); } else if (strcmp((char *)payload, "lampon") == 0) { lampon(); - Serial.println("Disable Blinking!"); + Serial.println("Lamp on!"); } else if (strcmp((char *)payload, "lampoff") == 0) { lampoff(); - Serial.println("Disable Blinking!"); + Serial.println("Lamp off!"); } break; } @@ -125,7 +125,7 @@ void setup() { delay(1000); } - if (!MDNS.begin("a2clight")) { + if (!MDNS.begin("a2clight" + LIGHT_NUMBER)) { Serial.println("Error setting up MDNS responder!"); while (1) { delay(1000); @@ -162,8 +162,8 @@ void browseService(const char *service, const char *proto) { webSocket.begin(ip.toString(), 80, "/ws"); webSocket.onEvent(webSocketEvent); // webSocket.setAuthorization("user", "Password"); - webSocket.setReconnectInterval(3000); - webSocket.enableHeartbeat(15000, 3000, 2); + webSocket.setReconnectInterval(500); + webSocket.enableHeartbeat(1500, 2000, 2); } } }