Skip to content

Instantly share code, notes, and snippets.

@kittipongint
Last active March 25, 2017 20:32
Show Gist options
  • Save kittipongint/e6ac453fa06384f250108e4e0d3f694e to your computer and use it in GitHub Desktop.
Save kittipongint/e6ac453fa06384f250108e4e0d3f694e to your computer and use it in GitHub Desktop.
Sample for AC Remote - LG with 4 button, Power On, Off, Temp. 20°C, and 25°C
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <IRremoteESP8266.h>
const char* ssid = "xxxx"; //your wifi's ssid
const char* password = "xxxx"; //your wifi's password
MDNSResponder mdns;
ESP8266WebServer server(80);
IRsend irsend(0);
void handleRoot() {
server.send(200, "text/html", "<html> <head> <title>kittipongint AC Remote Control</title> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><style type=\"text/css\"> * {-webkit-touch-callout: none; -webkit-user-select: none; box-sizing: border-box; } *:before, *:after {box-sizing: border-box; } html {background: linear-gradient(141deg, #0fb8ad 0%, #1fc8db 51%, #2cb5e8 75%); } html, body {margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; font-family: serif; } .remoter .btn {width: 60px; height: 60px; border-radius: 50%; border: 3px solid #2d2f2e; margin: 10px 0 0 10px; position: relative; } .remoter .btn:hover {cursor: pointer; border-color: #464948; } .remoter .btn.active {border-color: #5f6361; } .remoter .dark {background: #2d2f2e; } .remoter .icon {font-size: 2em; font-weight: bold; position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); -webkit-transform: translate(-50%, -50%) scale(0.6); transform: translate(-50%, -50%) scale(0.6); } .remoter .icon a {text-decoration: none; color: #2d2f2e; } .remoter .dark .icon a {text-decoration: none; color: #a3a3a3; } .remoter .vol-label {font-size: 12px; font-weight: bold; position: absolute; top: 230px; right: 15px; -webkit-transform: scale(0.7); transform: scale(0.7); } </style></head> <body> <div> <div class=\"remoter\"> <div class=\"btn btn-on dark\"> <div class=\"icon\"><a href=\"ir?code=142607621\">ON</a></div> </div> <div class=\"btn btn-off dark\"> <div class=\"icon\"><a href=\"ir?code=143392849\">OFF</a></div> </div> <div class=\"btn btn-20\"> <div class=\"icon\"><a href=\"ir?code=142640397\">20&#8451;</a></div> </div> <div class=\"btn btn-25\"> <div class=\"icon\"><a href=\"ir?code=142641666\">25&#8451;</a></div> </div> <label class=\"vol-label\">kittipongint AC Remote</label> </div> </div> </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.sendLG(code, 28);
}
}
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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment