Skip to content

Instantly share code, notes, and snippets.

@nckltcha
Created January 28, 2016 19:07
Show Gist options
  • Select an option

  • Save nckltcha/59d09675b9f3172b924c to your computer and use it in GitHub Desktop.

Select an option

Save nckltcha/59d09675b9f3172b924c to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
MDNSResponder mdns;
// Replace with your network credentials
const char* ssid = "";
const char* password = "";
ESP8266WebServer server(80);
String webPage = "";
void setup(void){
mySwitch.enableTransmit(5);
mySwitch.setPulseLength(313);
delay(1000);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (mdns.begin("esp8266-livingroom", WiFi.localIP())) {
Serial.println("MDNS responder started");
}
server.on("/", [](){
server.send(200, "text/html", webPage);
});
server.on("/socketOn", [](){
server.send(200, "text/html", webPage);
mySwitch.switchOn(1, 1);
delay(1000);
});
server.on("/socketOff", [](){
server.send(200, "text/html", webPage);
mySwitch.switchOff(1, 1);
delay(1000);
});
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment