Browse Source

small changes

master
Lukas Bachschwell 1 year ago
parent
commit
c8ac9c2bd4
3 changed files with 19 additions and 15 deletions
  1. +1
    -1
      .vscode/arduino.json
  2. +12
    -8
      src/controller_main.cpp
  3. +6
    -6
      src/light_main.cpp

+ 1
- 1
.vscode/arduino.json View File

@@ -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"
}

+ 12
- 8
src/controller_main.cpp View File

@@ -8,6 +8,7 @@

#include <ETH.h>

#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 += "<h3>Audio2 Cabin Light System</h3><br>Current Status: <br><table>";
statusHTML += "<tr><td>Lamp</td><td>Status</td><td>";
statusHTML += "<html><h3>Audio2 Cabin Light System</h3><br>Current Status: <br><table border='1'>";
statusHTML += "<tr><td>Lamp</td><td>Status</td></tr>";

for (int i = 0; i < 4; i++) {
statusHTML += "<tr><td>Lamp ";
@@ -156,9 +157,12 @@ void setup() {
statusHTML += "</b><br>";
statusHTML += "Input clear: <b>";
statusHTML += clearActive ? "inactive (high)" : "active (low)";
statusHTML += "</b><br>";
statusHTML += "<br>Timeout: <b>";
statusHTML += (activateTimeout == 0 || millis() - activateTimeout >= TRIGGER_TIMEOUT) ? "active" : "inactive";

statusHTML += "</b><br></html>";

request->send(200, "text/plain", 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);
}

///////////////////////////

+ 6
- 6
src/light_main.cpp View File

@@ -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);
}
}
}


Loading…
Cancel
Save