#include #include #include #include #include const char* ssid = ""; const char* password = ""; ESP8266WebServer server(80); int p = 0; int dataPin = 13; #include RCSwitch mySwitch = RCSwitch(); // constants won't change. They're used here to // set pin numbers: const int buttonPin = 0; // the number of the pushbutton pin const int ledPin = 2; // the number of the LED pin // variables will change: int buttonState = 0; // variable for reading the pushbutton status void handleRoot() { if (server.args() > 0 ) { for ( uint8_t i = 0; i < server.args(); i++ ) { if (server.argName(i) == "switch") { server.send(200, "text/plain", server.arg(i)); int code = server.arg(i).toInt(); /* Same switch as above, but using decimal code */ mySwitch.send(code, 24); delay(1000); } } }else{ server.send(200, "text/plain", "hello from esp8266!"); } } void handleNotFound(){ String message = "File Not Found\n\n"; message += "URI: "; message += server.uri(); message += "\nMethod: "; message += (server.method() == HTTP_GET)?"GET":"POST"; message += "\nArguments: "; message += server.args(); message += "\n"; for (uint8_t i=0; i/cgi-bin/doorbell.cgi"); int httpCode = http.GET(); http.end(); delay(5000); } void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); Serial.begin(9600); 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")) { Serial.println("MDNS responder started"); } server.on("/", handleRoot); server.onNotFound(handleNotFound); server.begin(); Serial.println("HTTP server started"); // Transmitter is connected to Arduino Pin 'dataPin' mySwitch.enableTransmit(dataPin); // Optional set pulse length. mySwitch.setPulseLength(185); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: p=0; digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); p++; Serial.println(p); if(p > 50){ Serial.println("Ring!!!"); p=0; ring(); } } //webserver server.handleClient(); }