Add on and off mode

This commit is contained in:
Lukas Bachschwell 2019-05-19 15:25:36 +02:00
parent 29ec2f7641
commit cda706fdc8
2 changed files with 30 additions and 13 deletions

View File

@ -122,16 +122,26 @@ void setup() {
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { request->send(200, "text/plain", "Current Status: To Be done"); }); server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { request->send(200, "text/plain", "Current Status: To Be done"); });
server.on("/allon", HTTP_GET, [](AsyncWebServerRequest *request) { server.on("/allblink", HTTP_GET, [](AsyncWebServerRequest *request) {
ws.textAll("blinkLamp"); ws.textAll("blinkLamp");
request->send(200, "text/plain", "Alarming All"); request->send(200, "text/plain", "Alarming All");
}); });
server.on("/alloff", HTTP_GET, [](AsyncWebServerRequest *request) { server.on("/allnoblink", HTTP_GET, [](AsyncWebServerRequest *request) {
ws.textAll("noBlinkLamp"); ws.textAll("noBlinkLamp");
request->send(200, "text/plain", "Alarm stopped"); request->send(200, "text/plain", "Alarm stopped");
}); });
server.on("/allon", HTTP_GET, [](AsyncWebServerRequest *request) {
ws.textAll("lampon");
request->send(200, "text/plain", "Alarming All");
});
server.on("/alloff", HTTP_GET, [](AsyncWebServerRequest *request) {
ws.textAll("lampoff");
request->send(200, "text/plain", "Alarm stopped");
});
server.onNotFound(notFound); server.onNotFound(notFound);
server.begin(); server.begin();
@ -149,7 +159,7 @@ void loop() {
if (!inputActive) { // React when the signal starts if (!inputActive) { // React when the signal starts
if (millis() - activateTimeout >= 60000) { // 1 Minute timeout if (millis() - activateTimeout >= 60000) { // 1 Minute timeout
Serial.println("Activate triggered"); Serial.println("Activate triggered");
ws.textAll("blinkLamp"); ws.textAll("lampon");
} }
} }
} }
@ -162,7 +172,7 @@ void loop() {
clearActive = digitalRead(PIN_CLEAR); clearActive = digitalRead(PIN_CLEAR);
if (clearActive) { // React when the signal is over if (clearActive) { // React when the signal is over
Serial.println("Clear triggered"); Serial.println("Clear triggered");
ws.textAll("noBlinkLamp"); ws.textAll("lampoff");
activateTimeout = millis(); activateTimeout = millis();
} }
} }

View File

@ -70,6 +70,16 @@ void noBlinkLamp() {
digitalWrite(lampOutputPin, LOW); digitalWrite(lampOutputPin, LOW);
} }
void lampon() {
isBlinking = false;
digitalWrite(lampOutputPin, HIGH);
}
void lampoff() {
isBlinking = false;
digitalWrite(lampOutputPin, LOW);
}
void webSocketEvent(WStype_t type, uint8_t *payload, size_t length) { void webSocketEvent(WStype_t type, uint8_t *payload, size_t length) {
switch (type) { switch (type) {
@ -91,6 +101,12 @@ void webSocketEvent(WStype_t type, uint8_t *payload, size_t length) {
} else if (strcmp((char *)payload, "noBlinkLamp") == 0) { } else if (strcmp((char *)payload, "noBlinkLamp") == 0) {
noBlinkLamp(); noBlinkLamp();
Serial.println("Disable Blinking!"); Serial.println("Disable Blinking!");
} else if (strcmp((char *)payload, "lampon") == 0) {
lampon();
Serial.println("Disable Blinking!");
} else if (strcmp((char *)payload, "lampoff") == 0) {
lampoff();
Serial.println("Disable Blinking!");
} }
break; break;
} }
@ -155,15 +171,6 @@ void browseService(const char *service, const char *proto) {
void loop() { void loop() {
if (!foundIp && eth_connected && ((millis() - connectTimer) > connectDuration)) { if (!foundIp && eth_connected && ((millis() - connectTimer) > connectDuration)) {
browseService("http", "tcp"); browseService("http", "tcp");
/*
ip = MDNS.queryHost("a2clcontroller");
Serial.println(ip);
foundIp = true;
webSocket.begin(ip, 80, "/ws");
webSocket.onEvent(webSocketEvent);
// webSocket.setAuthorization("user", "Password");
webSocket.setReconnectInterval(3000);
*/
connectTimer = millis(); connectTimer = millis();
} }