/
IRServer.ino
122 lines (106 loc) · 7.79 KB
/
IRServer.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* 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 = "foo";
const char* password = "foo";
MDNSResponder mdns;
ESP8266WebServer server(80);
IRsend irsend(4);
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?tv=power\">TV POWER</a></p><p><a href=\"ir?fan=on\">FAN ON AND OSC</a></p><p><a href=\"ir?fan=power\">FAN ON/OFF</a></p><p><a href=\"ir?fan=osc\">FAN OSC</a></p><p><a href=\"ir?fan=timeradd\">FAN Timer +1</a></p><p><a href=\"ir?fan=timerminus\">FAN Timer -1</a></p><p><a href=\"ir?fan=speed\">FAN SPEED</a></p><p><a href=\"ir?fan=mode\">FAN MODE</a></p></body></html>");
}
void handleIr(){
for (uint8_t i=0; i<server.args(); i++){
if(server.argName(i) == "tv")
{
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) == "fan")
{
if (server.arg(i) == "on") { // 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 (server.arg(i) == "power") { // 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 (server.arg(i) == "osc") { // 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 (server.arg(i) == "timeradd") { // 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);
}
if (server.arg(i) == "timerminus") { // fan minus timer
unsigned int rawData[99] = {1300,450, 1300,450, 450,1250, 1300,450, 1300,450, 450,1250, 1300,450, 450,1250, 450,1250, 450,1250, 400,1300, 450,8050, 1300,450, 1300,450, 400,1300, 1300,450, 1300,450, 450,1250, 1300,450, 450,1250, 450,1300, 450,1250, 400,1300, 450,8050, 1250,500, 1300,450, 450,1250, 1300,450, 1300,450, 450,1250, 1250,500, 450,1250, 450,1250, 450,1250, 400,1300, 450,8050, 1250,500, 1300,450, 450,1250, 1300,450, 1300,450, 450,1250, 1300,450, 450,1250, 400,1300, 450,1250, 450,1300, 450,8050, 1250,500, 1300}; // UNKNOWN 27A36066
irsend.sendRaw(rawData, 99, 38);
}
if (server.arg(i) == "speed") { // fan speed
unsigned int rawData[99] = {1300,450, 1250,500, 400,1350, 1250,500, 1250,500, 400,1350, 400,1350, 400,1350, 400,1350, 1250,500, 400,1350, 400,8100, 1250,500, 1250,500, 400,1350, 1250,500, 1250,500, 400,1350, 400,1350, 400,1350, 400,1300, 1300,500, 400,1350, 400,8100, 1250,500, 1250,500, 400,1300, 1250,500, 1250,500, 400,1350, 400,1350, 400,1300, 450,1350, 1250,500, 400,1300, 450,8100, 1250,500, 1250,500, 400,1300, 1300,500, 1250,500, 400,1300, 450,1300, 450,1300, 450,1300, 1300,500, 400,1300, 450,8050, 1300,500, 1250}; // UNKNOWN DB05A496
irsend.sendRaw(rawData, 99, 38);
}
if (server.arg(i) == "mode") { // fan speed
unsigned int rawData[99] = {1300,450, 1300,450, 450,1300, 1300,450, 1300,450, 450,1300, 450,1300, 1300,450, 450,1300, 450,1300, 450,1300, 450,8050, 1300,450, 1300,450, 450,1300, 1300,450, 1300,450, 450,1300, 450,1300, 1300,450, 450,1300, 450,1300, 450,1300, 450,8050, 1300,450, 1300,450, 450,1300, 1300,450, 1300,450, 450,1300, 450,1300, 1300,450, 450,1300, 450,1300, 450,1300, 450,8050, 1300,450, 1300,450, 450,1300, 1300,450, 1300,450, 450,1300, 450,1300, 1300,450, 450,1300, 450,1300, 450,1300, 450,8050, 1300,450, 1300}; // UNKNOWN D8E4DC16
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();
}