/.ino Secret
Created
March 16, 2024 10:11
ESP8266 IR Led Remote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <Arduino.h> | |
#include <IRremoteESP8266.h> | |
#include <IRsend.h> | |
#define IR_BPLUS 0xF700FF | |
#define IR_BMINUS 0xF7807F | |
#define IR_OFF 0xF740BF | |
#define IR_ON 0xF7C03F | |
#define IR_R 0xF720DF | |
#define IR_G 0xF7A05F | |
#define IR_B 0xF7609F | |
#define IR_W 0xF7E01F | |
#define IR_B1 0xF710EF | |
#define IR_B2 0xF7906F | |
#define IR_B3 0xF750AF | |
#define IR_FLASH 0xF7D02F | |
#define IR_B4 0xF730CF | |
#define IR_B5 0xF7B04F | |
#define IR_B6 0xF7708F | |
#define IR_STROBE 0xF7F00F | |
#define IR_B7 0xF708F7 | |
#define IR_B8 0xF78877 | |
#define IR_B9 0xF748B7 | |
#define IR_FADE 0xF7C837 | |
#define IR_B10 0xF728D7 | |
#define IR_B11 0xF7A857 | |
#define IR_B12 0xF76897 | |
#define IR_SMOOTH 0xF7E817 | |
unsigned int irCodes[] = { | |
IR_BPLUS, | |
IR_BMINUS, | |
IR_OFF, | |
IR_ON, | |
IR_R, | |
IR_G, | |
IR_B, | |
IR_W, | |
IR_B1, | |
IR_B2, | |
IR_B3, | |
IR_FLASH, | |
IR_B4, | |
IR_B5, | |
IR_B6, | |
IR_STROBE, | |
IR_B7, | |
IR_B8, | |
IR_B9, | |
IR_FADE, | |
IR_B10, | |
IR_B11, | |
IR_B12, | |
IR_SMOOTH | |
}; | |
const int numIrCodes = sizeof(irCodes) / sizeof(irCodes[0]); | |
const char* ssid = ""; | |
const char* password = ""; | |
WiFiServer server(80); | |
String header; | |
unsigned long currentTime = millis(); | |
unsigned long previousTime = 0; | |
const long timeoutTime = 2000; | |
const uint16_t kIrLed = 4; | |
IRsend irsend(kIrLed); | |
void setup() { | |
irsend.begin(); | |
Serial.begin(9600); | |
Serial.print("Connecting to "); | |
Serial.println(ssid); | |
WiFi.hostname("ESP8266_LediNauha"); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.println("WiFi connected."); | |
Serial.println("IP address: "); | |
Serial.println(WiFi.localIP()); | |
server.begin(); | |
} | |
void loop() { | |
WiFiClient client = server.available(); | |
if (client) { | |
Serial.println("New Client."); | |
String currentLine = ""; | |
currentTime = millis(); | |
previousTime = currentTime; | |
while (client.connected() && currentTime - previousTime <= timeoutTime) { | |
currentTime = millis(); | |
if (client.available()) { | |
char c = client.read(); | |
Serial.write(c); | |
header += c; | |
if (c == '\n') { | |
if (currentLine.length() == 0) { | |
client.println("HTTP/1.1 200 OK"); | |
client.println("Content-type:text/html"); | |
client.println("Connection: close"); | |
client.println(); | |
int buttonIndex = header.indexOf("GET /button/"); | |
if (buttonIndex >= 0) { | |
String buttonSubstring = header.substring(buttonIndex + 11); | |
int spaceIndex = buttonSubstring.indexOf(' '); | |
if (spaceIndex >= 0) { | |
String buttonNumberString = buttonSubstring.substring(0, spaceIndex); | |
int buttonNumber = buttonNumberString.toInt(); | |
if (buttonNumber >= 0 && buttonNumber < sizeof(irCodes) / sizeof(irCodes[0])) { | |
irsend.sendNEC(irCodes[buttonNumber], 32); | |
} | |
} | |
} | |
client.println("<!DOCTYPE html><html>"); | |
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"); | |
client.println("<style>table{font-family:Arial,sans-serif;border:1px solid #000;border-radius:5px;padding:4px}table td a{color:#fff;text-shadow:1px 1px 1px #000;font-size:13px;text-decoration:none;--c:white;display:grid;width:32px;height:32px;text-align:center;align-items:center;border:1px solid #000;border-radius:50%;background-color:var(--c)}</style>"); | |
client.println("</head>"); | |
client.println("<body><h1>ESP8266 LediNauha</h1>"); | |
client.println("<table>"); | |
client.println("<tr></tr>"); | |
client.println("<tr>"); | |
client.println("<td><a href=\"/button/00\">+</a></td>"); | |
client.println("<td><a href=\"/button/01\">–</a></td>"); | |
client.println("<td><a href=\"/button/02\">OFF</a></td>"); | |
client.println("<td><a href=\"/button/03\">ON</a></td>"); | |
client.println("</tr>"); | |
client.println("<tr>"); | |
client.println("<td><a href=\"/button/04\" style=\"--c:red\">R</a></td>"); | |
client.println("<td><a href=\"/button/05\" style=\"--c:green\">G</a></td>"); | |
client.println("<td><a href=\"/button/06\" style=\"--c:blue\">B</a></td>"); | |
client.println("<td><a href=\"/button/07\">W</a></td>"); | |
client.println("</tr>"); | |
client.println("<tr>"); | |
client.println("<td><a href=\"/button/08\" style=\"--c:#ff4000\">08</a></td>"); | |
client.println("<td><a href=\"/button/09\" style=\"--c:#40ba00\">09</a></td>"); | |
client.println("<td><a href=\"/button/10\" style=\"--c:#5d40ff\">10</a></td>"); | |
client.println("<td><a href=\"/button/11\">FLA</a></td>"); | |
client.println("</tr>"); | |
client.println("<tr>"); | |
client.println("<td><a href=\"/button/12\" style=\"--c:#ff6200\">12</a></td>"); | |
client.println("<td><a href=\"/button/13\" style=\"--c:#06c995\">13</a></td>"); | |
client.println("<td><a href=\"/button/14\" style=\"--c:#8c40ff\">14</a></td>"); | |
client.println("<td><a href=\"/button/15\">STR</a></td>"); | |
client.println("</tr>"); | |
client.println("<tr>"); | |
client.println("<td><a href=\"/button/16\" style=\"--c:#ff8c00\">16</a></td>"); | |
client.println("<td><a href=\"/button/17\" style=\"--c:#00b096\">17</a></td>"); | |
client.println("<td><a href=\"/button/18\" style=\"--c:#cf40ff\">18</a></td>"); | |
client.println("<td><a href=\"/button/19\">FDE</a></td>"); | |
client.println("</tr>"); | |
client.println("<tr>"); | |
client.println("<td><a href=\"/button/20\" style=\"--c:yellow\">20</a></td>"); | |
client.println("<td><a href=\"/button/21\" style=\"--c:#0072b0\">21</a></td>"); | |
client.println("<td><a href=\"/button/22\" style=\"--c:#ff40df\">22</a></td>"); | |
client.println("<td><a href=\"/button/23\">SMO</a></td>"); | |
client.println("</tr>"); | |
client.println("</table>"); | |
client.println("</body></html>"); | |
client.println(); | |
break; | |
} else { | |
currentLine = ""; | |
} | |
} else if (c != '\r') { | |
currentLine += c; | |
} | |
} | |
} | |
header = ""; | |
client.stop(); | |
Serial.println("Client disconnected."); | |
Serial.println(""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment