Skip to content

Update sinric.ino #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion sinric.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ 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,

String serial;
String persistent_uuid;
String device_name;

const int relayPin = D1;
const int relayPin = LED_BUILTIN;
Copy link
Owner

@kakopappa kakopappa Mar 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work.

Should be D1 ?


boolean cannotConnectToWifi = false;

Expand Down Expand Up @@ -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 ... ##########");

Expand Down Expand Up @@ -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;
}