Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * IRremoteESP8266: IRServer - demonstrates sending IR codes controlled from a webserver
- * An IR LED must be connected to ESP8266 pin 0.
- * Version 0.1 June, 2015
- */
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266mDNS.h>
- #include <IRremoteESP8266.h>
- const char* ssid = "xxxxx";
- const char* password = "xxxxx";
- MDNSResponder mdns;
- ESP8266WebServer server(80);
- IRsend irsend(2);
- void handleRoot() {
- server.send(200, "text/html", "<html><head> <title>ESP8266 IR Remote</title></head><body><h1>ESP8266 IR Remote</h1><p><a href=\"ir?code=554108155\">Send 210704FB (TV ON/OFF)</a></p><p><a href=\"ir?raw=123456789\">FAN ON AND OSC</a></p><p><a href=\"ir?raw=414094305\">Send F6D1C6CE (FAN ON/OFF)</a></p><p><a href=\"ir?raw=146495997\">Send 575183E6 (FAN OSC)</a></p><p><a href=\"ir?raw=288285118\">Send ABD4D16E (FAN Add timer +1)</a></p></body></html>");
- }
- void handleIr(){
- for (uint8_t i=0; i<server.args(); i++){
- if(server.argName(i) == "code")
- {
- // unsigned long code = server.arg(i).toInt();
- // irsend.sendNEC(code, 32);
- unsigned int tv[67] = {8850,4450, 600,600, 550,600, 600,1700, 600,600, 600,600, 600,600, 600,600, 550,1700, 600,600, 600,600, 600,600, 600,600, 600,600, 600,1700, 600,1700, 600,1700, 600,600, 600,600, 600,600, 550,600, 600,600, 600,1700, 600,600, 600,600, 600,1700, 600,1700, 600,1700, 600,1700, 600,1700, 600,600, 550,1700, 600,1700, 600}; // NEC 210704FB
- irsend.sendRaw(tv, 67, 38);
- }
- else if(server.argName(i) == "raw")
- {
- unsigned long raw = server.arg(i).toInt();
- if (raw == 123456789) { // fan on and osc
- unsigned int fanOn[99] = {1300,450, 1300,450, 450,1250, 1300,450, 1300,450, 450,1250, 450,1250, 500,1250, 450,1250, 450,1250, 400,1300, 1250,7250, 1250,500, 1250,500, 400,1300, 1250,500, 1250,500, 400,1300, 400,1300, 400,1300, 400,1300, 400,1300, 400,1300, 1250,7250, 1250,500, 1250,500, 400,1300, 1300,500, 1250,500, 400,1300, 400,1300, 400,1300, 400,1300, 400,1300, 400,1250, 1300,7250, 1250,500, 1250,500, 400,1300, 1250,500, 1300,450, 450,1300, 400,1300, 400,1250, 450,1300, 400,1300, 400,1300, 1250,7250, 1250,500, 1300}; // UNKNOWN F6D1C6CE
- irsend.sendRaw(fanOn, 99, 38);
- delay(1000);
- unsigned int fanOsc[99] = {1300,400, 1400,400, 500,1200, 1300,450, 1400,350, 500,1250, 550,1200, 550,1200, 1400,400, 500,1250, 500,1200, 550,7950, 1400,350, 1400,350, 550,1200, 1350,400, 1350,350, 550,1200, 550,1200, 500,1250, 1400,350, 550,1200, 500,1250, 500,8000, 1300,450, 1350,400, 500,1250, 1400,350, 1350,400, 450,1300, 500,1200, 550,1250, 1250,450, 500,1250, 500,1250, 550,8000, 1350,400, 1350,400, 500,1250, 1350,400, 1350,400, 500,1250, 550,1250, 450,1300, 1400,350, 550,1200, 550,1250, 500,7950, 1400,350, 1400}; // UNKNOWN 7A2823E9
- irsend.sendRaw(fanOsc, 99, 38);
- }
- if (raw == 414094305) { // fan on/off
- unsigned int fanOnOff[99] = {1300,450, 1300,450, 450,1250, 1300,450, 1300,450, 450,1250, 450,1250, 500,1250, 450,1250, 450,1250, 400,1300, 1250,7250, 1250,500, 1250,500, 400,1300, 1250,500, 1250,500, 400,1300, 400,1300, 400,1300, 400,1300, 400,1300, 400,1300, 1250,7250, 1250,500, 1250,500, 400,1300, 1300,500, 1250,500, 400,1300, 400,1300, 400,1300, 400,1300, 400,1300, 400,1250, 1300,7250, 1250,500, 1250,500, 400,1300, 1250,500, 1300,450, 450,1300, 400,1300, 400,1250, 450,1300, 400,1300, 400,1300, 1250,7250, 1250,500, 1300}; // UNKNOWN F6D1C6CE
- irsend.sendRaw(fanOnOff, 99, 38);
- }
- if (raw == 146495997) { // fan osc
- unsigned int fanOsc[99] = {1300,400, 1400,400, 500,1200, 1300,450, 1400,350, 500,1250, 550,1200, 550,1200, 1400,400, 500,1250, 500,1200, 550,7950, 1400,350, 1400,350, 550,1200, 1350,400, 1350,350, 550,1200, 550,1200, 500,1250, 1400,350, 550,1200, 500,1250, 500,8000, 1300,450, 1350,400, 500,1250, 1400,350, 1350,400, 450,1300, 500,1200, 550,1250, 1250,450, 500,1250, 500,1250, 550,8000, 1350,400, 1350,400, 500,1250, 1350,400, 1350,400, 500,1250, 550,1250, 450,1300, 1400,350, 550,1200, 550,1250, 500,7950, 1400,350, 1400}; // UNKNOWN 7A2823E9
- irsend.sendRaw(fanOsc, 99, 38);
- }
- if (raw == 288285118) { // fan add timer
- unsigned int rawData[99] = {1350,400, 1350,400, 500,1250, 1350,400, 1350,400, 500,1250, 500,1250, 500,1250, 500,1250, 500,1250, 1350,400, 500,8000, 1350,400, 1350,400, 500,1250, 1350,400, 1350,400, 500,1250, 500,1250, 500,1250, 500,1250, 500,1250, 1350,400, 500,8000, 1350,400, 1300,400, 500,1250, 1350,400, 1350,400, 500,1250, 500,1250, 500,1250, 500,1250, 500,1250, 1350,400, 500,7950, 1350,450, 1300,400, 550,1200, 1350,400, 1350,400, 500,1250, 550,1200, 500,1250, 500,1250, 500,1250, 1350,450, 450,8000, 1350,400, 1350}; // UNKNOWN ABD4D16E
- irsend.sendRaw(rawData, 99, 38);
- }
- }
- }
- handleRoot();
- }
- 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<server.args(); i++){
- message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
- }
- server.send(404, "text/plain", message);
- }
- void setup(void){
- irsend.begin();
- 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", WiFi.localIP())) {
- Serial.println("MDNS responder started");
- }
- server.on("/", handleRoot);
- server.on("/ir", handleIr);
- server.on("/inline", [](){
- server.send(200, "text/plain", "this works as well");
- });
- server.onNotFound(handleNotFound);
- server.begin();
- Serial.println("HTTP server started");
- }
- void loop(void){
- server.handleClient();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement