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 = "xxxxxxxxx";
- const char* password = "yyyyyyyyyy";
- MDNSResponder mdns;
- ESP8266WebServer server(80);
- IRsend irsend(4);
- unsigned long code;
- String Teclado = "";
- //------------------------------------------------
- unsigned long stringToLong(String CodeStr)
- {
- char MyArray[12];
- CodeStr.toCharArray(MyArray, sizeof(MyArray));
- return strtoul(MyArray, NULL, 0);
- }
- //------------------------------------------------
- void handleRoot()
- {
- server.send(200, "text/html", Teclado);
- }
- //------------------------------------------------
- void handleIr()
- {
- for (uint8_t i = 0; i < server.args(); i++)
- {
- if (server.argName(i) == "code")
- {
- String CodeTransl = (server.arg(i));
- code = stringToLong(CodeTransl);
- irsend.sendNEC(code, 32);
- }
- }
- 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)
- {
- Teclado += "<html><head> <title>ESP8266 IR</title></head><body><h1>CR Wifi</h1>";
- Teclado += "<p><a href=\"ir?code=3782871287\"><button style=\"background-color: rgb( 0, 255, 0);height: 50px; width: 150px;\"><h2>+Canal</h2></button></a>";
- Teclado += "<a href=\"ir?code=3782891687\"><button style=\"background-color: rgb(255, 0, 0);height: 50px; width: 150px;\"><h2>-Canal</h2></button></a></p>";
- Teclado += "<p><a href=\"ir?code=3782914127\"><button style=\"background-color: rgb( 0, 0, 255);height: 50px; width: 150px;\"><h2>+Vol</h2></button></a>";
- Teclado += "<a href=\"ir?code=3782897807\"><button style=\"background-color: rgb(128,128, 0);height: 50px; width: 150px;\"><h2>-Vol</h2></button></a></p>";
- Teclado += "<p><a href=\"ir?code=3782932487\"><button style=\"background-color: rgb(128,128,128);height: 25px; width: 70px;\"><h2>Mute</h2></button></a>";
- Teclado += " ";
- Teclado += "<a href=\"ir?code=3782903927\"><button style=\"background-color: rgb(160, 0,128);height: 25px; width: 70px;\"><h2>Voltar</h2></button></a>";
- Teclado += " ";
- Teclado += "<a href=\"ir?code=3782879447\"><button style=\"background-color: rgb(160, 0,128);height: 25px; width: 70px;\"><h2>Grade</h2></button></a></p>";
- Teclado += "<p><a href=\"ir?code=3782922287\"><button style=\"background-color: rgb(0,255,255);height: 50px; width: 300px;\"><h2>Up</h2></button></a></p>";
- Teclado += "<p><a href=\"ir?code=3782924327\"><button style=\"background-color: rgb(128,160,0);height: 50px; width: 100px;\"><h2>Left</h2></button></a>";
- Teclado += "<a href=\"ir?code=3782912087\"><button style=\"background-color: rgb(160, 0,128);height: 50px; width: 100px;\"><h2>Ok</h2></button></a>";
- Teclado += "<a href=\"ir?code=3782883527\"><button style=\"background-color: rgb(160,160, 96);height: 50px; width: 100px;\"><h2>Right</h2></button></a></p>";
- Teclado += "<p><a href=\"ir?code=3782881487\"><button style=\"background-color: rgb(0,255,255);height: 50px; width: 300px;\"><h2>Down</h2></button></a></p>";
- Teclado += "<p><a href=\"ir?code=3782916167\"><button style=\"background-color: rgb(255, 0, 0);height: 25px; width: 70px;\"><h2>Fav</h2></button></a>";
- Teclado += " ";
- Teclado += " ";
- Teclado += " ";
- Teclado += "<a href=\"ir?code=3782889647\"><button style=\"background-color: rgb(128,128,128);height: 25px; width: 70px;\"><h2>Sair</h2></button></a></p>";
- Teclado += "<p><a href=\"ir?code=3782901887\"><button style=\"background-color: rgb(255,255,0);height: 25px; width: 70px;\"><h2>1</h2></button></a>";
- Teclado += " ";
- Teclado += "<a href=\"ir?code=3782885567\"><button style=\"background-color: rgb(255,255,0);height: 25px; width: 70px;\"><h2>2</h2></button></a>";
- Teclado += " ";
- Teclado += "<a href=\"ir?code=3782918207\"><button style=\"background-color: rgb(255,255,0);height: 25px; width: 70px;\"><h2>3</h2></button></a></p>";
- Teclado += "<p><a href=\"ir?code=3782877407\"><button style=\"background-color: rgb(255,255,0);height: 25px; width: 70px;\"><h2>4</h2></button></a>";
- Teclado += " ";
- Teclado += "<a href=\"ir?code=3782910047\"><button style=\"background-color: rgb(255,255,0);height: 25px; width: 70px;\"><h2>5</h2></button></a>";
- Teclado += " ";
- Teclado += "<a href=\"ir?code=3782893727\"><button style=\"background-color: rgb(255,255,0);height: 25px; width: 70px;\"><h2>6</h2></button></a></p>";
- Teclado += "<p><a href=\"ir?code=3782926367\"><button style=\"background-color: rgb(255,255,0);height: 25px; width: 70px;\"><h2>7</h2></button></a>";
- Teclado += " ";
- Teclado += "<a href=\"ir?code=3782873327\"><button style=\"background-color: rgb(255,255,0);height: 25px; width: 70px;\"><h2>8</h2></button></a>";
- Teclado += " ";
- Teclado += "<a href=\"ir?code=3782905967\"><button style=\"background-color: rgb(255,255,0);height: 25px; width: 70px;\"><h2>9</h2></button></a></p>";
- Teclado += "<p> ";
- Teclado += " ";
- Teclado += " ";
- Teclado += "<a href=\"ir?code=3782869247\"><button style=\"background-color: rgb(255,255,0);height: 25px; width: 70px;\"><h2>0</h2></button></a></p>";
- irsend.begin();
- Serial.begin(115200);
- WiFi.begin(ssid, password);
- Serial.println("");
- while (WiFi.status() != WL_CONNECTED) // Wait for connection
- {
- 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("MDNSponder 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