small changes

This commit is contained in:
Lukas Bachschwell 2019-05-19 17:35:40 +02:00
parent dc037af217
commit c8ac9c2bd4
3 changed files with 19 additions and 15 deletions

View File

@ -1,5 +1,5 @@
{ {
"board": "esp8266:esp8266:d1", "board": "esp8266:esp8266:d1",
"configuration": "xtal=80,vt=flash,exception=disabled,eesz=4M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=921600", "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"
} }

View File

@ -8,6 +8,7 @@
#include <ETH.h> #include <ETH.h>
#define TRIGGER_TIMEOUT 60000
#define PIN_ACTIVATE 5 #define PIN_ACTIVATE 5
#define PIN_CLEAR 2 #define PIN_CLEAR 2
bool inputActive = true; bool inputActive = true;
@ -138,8 +139,8 @@ void setup() {
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
// Print a small status response page with the most important messages // Print a small status response page with the most important messages
String statusHTML = ""; String statusHTML = "";
statusHTML += "<h3>Audio2 Cabin Light System</h3><br>Current Status: <br><table>"; statusHTML += "<html><h3>Audio2 Cabin Light System</h3><br>Current Status: <br><table border='1'>";
statusHTML += "<tr><td>Lamp</td><td>Status</td><td>"; statusHTML += "<tr><td>Lamp</td><td>Status</td></tr>";
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
statusHTML += "<tr><td>Lamp "; statusHTML += "<tr><td>Lamp ";
@ -156,9 +157,12 @@ void setup() {
statusHTML += "</b><br>"; statusHTML += "</b><br>";
statusHTML += "Input clear: <b>"; statusHTML += "Input clear: <b>";
statusHTML += clearActive ? "inactive (high)" : "active (low)"; statusHTML += clearActive ? "inactive (high)" : "active (low)";
statusHTML += "</b><br>"; statusHTML += "<br>Timeout: <b>";
statusHTML += (activateTimeout == 0 || millis() - activateTimeout >= TRIGGER_TIMEOUT) ? "active" : "inactive";
request->send(200, "text/plain", statusHTML); statusHTML += "</b><br></html>";
request->send(200, "text/html", statusHTML);
}); });
server.on("/allblink", HTTP_GET, [](AsyncWebServerRequest *request) { server.on("/allblink", HTTP_GET, [](AsyncWebServerRequest *request) {
@ -199,10 +203,12 @@ void loop() {
inputActive = digitalRead(PIN_ACTIVATE); inputActive = digitalRead(PIN_ACTIVATE);
if (!inputActive) { // React when the signal starts if (!inputActive) { // React when the signal starts
if (millis() - activateTimeout >= 60000) { // 1 Minute timeout if (activateTimeout == 0 || millis() - activateTimeout >= TRIGGER_TIMEOUT) { // 1 Minute timeout
Serial.println("Activate triggered"); Serial.println("Activate triggered");
ws.textAll("lampon"); ws.textAll("lampon");
lastSent = "ON"; lastSent = "ON";
} else {
Serial.println("Wait 1 minute to retrigger lights");
} }
} }
} }
@ -221,8 +227,6 @@ void loop() {
} }
} }
} }
delay(1);
} }
/////////////////////////// ///////////////////////////

View File

@ -33,7 +33,7 @@ void WiFiEvent(WiFiEvent_t event) {
case SYSTEM_EVENT_ETH_START: case SYSTEM_EVENT_ETH_START:
Serial.println("ETH Started"); Serial.println("ETH Started");
// set eth hostname here // set eth hostname here
ETH.setHostname("a2clight"); ETH.setHostname("a2clight" + LIGHT_NUMBER);
break; break;
case SYSTEM_EVENT_ETH_CONNECTED: case SYSTEM_EVENT_ETH_CONNECTED:
Serial.println("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!"); Serial.println("Disable Blinking!");
} else if (strcmp((char *)payload, "lampon") == 0) { } else if (strcmp((char *)payload, "lampon") == 0) {
lampon(); lampon();
Serial.println("Disable Blinking!"); Serial.println("Lamp on!");
} else if (strcmp((char *)payload, "lampoff") == 0) { } else if (strcmp((char *)payload, "lampoff") == 0) {
lampoff(); lampoff();
Serial.println("Disable Blinking!"); Serial.println("Lamp off!");
} }
break; break;
} }
@ -125,7 +125,7 @@ void setup() {
delay(1000); delay(1000);
} }
if (!MDNS.begin("a2clight")) { if (!MDNS.begin("a2clight" + LIGHT_NUMBER)) {
Serial.println("Error setting up MDNS responder!"); Serial.println("Error setting up MDNS responder!");
while (1) { while (1) {
delay(1000); delay(1000);
@ -162,8 +162,8 @@ void browseService(const char *service, const char *proto) {
webSocket.begin(ip.toString(), 80, "/ws"); webSocket.begin(ip.toString(), 80, "/ws");
webSocket.onEvent(webSocketEvent); webSocket.onEvent(webSocketEvent);
// webSocket.setAuthorization("user", "Password"); // webSocket.setAuthorization("user", "Password");
webSocket.setReconnectInterval(3000); webSocket.setReconnectInterval(500);
webSocket.enableHeartbeat(15000, 3000, 2); webSocket.enableHeartbeat(1500, 2000, 2);
} }
} }
} }