From 5b4325cb23139b2ddb29a5f3697b608f9af47a45 Mon Sep 17 00:00:00 2001 From: Phil Pro Date: Sun, 19 Mar 2017 13:47:39 +0100 Subject: [PATCH] Update sinric.ino added basic http get ON/OFF functionallity just type http://yourip/on.html to turn on switch (replace on with off to turn off) http://yourip/status.html simply responds a 1 or 0 for switch status. --- sinric.ino | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/sinric.ino b/sinric.ino index c097fe2..62caac6 100644 --- a/sinric.ino +++ b/sinric.ino @@ -23,6 +23,7 @@ unsigned int portMulti = 1900; // local port to listen on ESP8266WebServer HTTP(80); boolean wifiConnected = false; +boolean switchOn = false; char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet, @@ -30,7 +31,7 @@ String serial; String persistent_uuid; String device_name; -const int relayPin = D1; +const int relayPin = LED_BUILTIN; boolean cannotConnectToWifi = false; @@ -161,6 +162,28 @@ void startHttpServer() { HTTP.send(200, "text/plain", "Hello World!"); }); + HTTP.on("/on.html", HTTP_GET, [](){ + Serial.println("Got Turn on request"); + HTTP.send(200, "text/plain", "turned on"); + turnOnRelay(); + }); + + HTTP.on("/off.html", HTTP_GET, [](){ + Serial.println("Got Turn off request"); + HTTP.send(200, "text/plain", "turned off"); + turnOffRelay(); + }); + + HTTP.on("/status.html", HTTP_GET, [](){ + Serial.println("Got status request"); + + String statrespone = "0"; + if (switchOn) { + statrespone = "1"; + } + HTTP.send(200, "text/plain", statrespone); + + }); HTTP.on("/upnp/control/basicevent1", HTTP_POST, []() { Serial.println("########## Responding to /upnp/control/basicevent1 ... ##########"); @@ -317,8 +340,10 @@ boolean connectUDP(){ void turnOnRelay() { digitalWrite(relayPin, HIGH); // turn on relay with voltage HIGH + switchOn = true; } void turnOffRelay() { digitalWrite(relayPin, LOW); // turn off relay with voltage LOW + switchOn = false; }