-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebServerIRSend_AC.ino
108 lines (88 loc) · 4.9 KB
/
WebServerIRSend_AC.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
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <IRsend.h>
#define DELAY_BETWEEN_COMMANDS 1000
IRsend irsend(15); // GPIO 15
const char* ssid = "";
const char* password = "";
const char* hname = "";
ESP8266WebServer server(80);
const int led = BUILTIN_LED;
// AC power on/off
uint16_t acPowerRawData[37] = {8500,4300, 550,1600, 550,1600, 550,1600, 500,600, 550,1600, 550,600, 550,1600, 550,1600, 500,4300, 550,1600, 500,1650, 550,550, 550,1600, 550,550, 550,550, 550,550, 550,550, 600}; // UNKNOWN B5E9B811
uint16_t fanPowerRawData[95] = {1350,400, 1350,400, 500,1250, 1350,400, 1300,400, 500,1250, 500,1250, 450,1250, 500,1250, 1350,400, 500,1250, 450,8000, 1350,400, 1350,400, 500,1250, 1350,400, 1350,400, 500,1250, 500,1250, 450,1250, 500,1250, 1350,400, 500,1250, 500,8000, 1300,400, 1350,400, 500,1250, 1350,400, 1300,400, 500,1250, 450,1250, 500,1250, 500,1250, 1350,400, 500,1250, 500,8000, 1350,400, 1350,400, 500,1250, 1350,400, 1350,400, 500,1250, 450,1250, 500,1250, 450,1250, 1300,400, 500,1250, 450}; // UNKNOWN EF1B843F
uint16_t fanSpeeRawData[85] = {1300,450, 450,1300, 450,1300, 450,1300, 1300,450, 1300,450, 450,8050, 1300,450, 1300,450, 450,1300, 1300,450, 1300,450, 1300,450, 450,1300, 450,1300, 450,1300, 1300,450, 1300,450, 450,8050, 1300,450, 1300,450, 450,1300, 1300,450, 1300,450, 1300,450, 450,1300, 450,1300, 450,1300, 1300,450, 1300,450, 450,8050, 1300,450, 1300,450, 450,1300, 1300,450, 1300,450, 1300,450, 450,1300, 450,1300, 450,1300, 1300,450, 1300,450, 450}; // UNKNOWN 4D704C89
uint16_t fanOscillationRawData[85] = {1300,450, 450,1300, 450,1300, 450,1300, 450,1300, 1300,450, 1300,7200, 1300,450, 1300,450, 450,1300, 1300,450, 1300,450, 1300,450, 450,1300, 450,1300, 450,1300, 450,1300, 1300,450, 1300,7200, 1300,450, 1300,450, 450,1300, 1300,450, 1300,450, 1300,450, 450,1300, 450,1300, 450,1300, 450,1300, 1300,450, 1300,7200, 1300,450, 1300,450, 450,1300, 1300,450, 1300,450, 1300,450, 450,1300, 450,1300, 450,1300, 450,1300, 1300,450, 1300}; // UNKNOWN A063E6FE
uint16_t soundbarPowerRawData[77] = {4500,4550, 550,500, 550,500, 550,500, 550,500, 550,1500, 550,1550, 550,500, 550,500, 550,1550, 550,1550, 550,1550, 550,1550, 550,500, 550,500, 550,500, 550,500, 550,4500, 550,500, 550,500, 550,500, 550,500, 550,500, 550,500, 550,500, 550,500, 550,1550, 550,1550, 550,1400, 650,500, 550,1500, 550,1550, 550,1500, 550,1500, 550,500, 550,500, 550,500, 550,1500, 550}; // UNKNOWN CA31DA45
uint16_t soundbarSourceRawData[77] = {4500,4550, 550,500, 550,500, 500,550, 500,550, 500,1550, 550,1500, 550,500, 500,550, 500,1550, 550,1500, 550,1500, 550,1500, 550,500, 550,500, 500,550, 550,500, 550,4500, 550,500, 550,500, 550,500, 550,500, 550,1500, 550,500, 550,1500, 550,500, 550,1500, 550,1500, 550,1500, 550,500, 550,500, 550,1500, 550,500, 550,1500, 550,500, 550,500, 550,500, 550,1500, 550}; // UNKNOWN 17112D07
void handleNotFound(){
digitalWrite(led, 1);
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);
digitalWrite(led, 1);
}
void setup(void){
irsend.begin();
pinMode(led, OUTPUT);
digitalWrite(led, 1);
Serial.begin(115200);
WiFi.begin(ssid, password);
WiFi.hostname(hname);
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(hname)) {
Serial.println("MDNS Responder Started");
}
server.on("/ac_power", [](){
Serial.println("A/C ON/OFF");
irsend.sendRaw(acPowerRawData, 37, 38);
server.send(200, "text/plain", "A/C ON/OFF");
});
server.on("/fan_power", [](){
Serial.println("Fan ON/OFF");
irsend.sendRaw(fanPowerRawData, 95, 38);
server.send(200, "text/plain", "Fan ON/OFF");
});
server.on("/fan_oscillation", [](){
Serial.println("Fan oscillation ON/OFF");
irsend.sendRaw(fanOscillationRawData, 85, 38);
server.send(200, "text/plain", "Fan oscillation ON/OFF");
});
server.on("/soundbar_power", [](){
Serial.println("Soundbar power ON/OFF");
irsend.sendRaw(soundbarPowerRawData, 77, 38);
server.send(200, "text/plain", "Soundbar power ON/OFF");
});
server.on("/soundbar_source", [](){
Serial.println("Soundbar source ON/OFF");
irsend.sendRaw(soundbarSourceRawData, 77, 38);
server.send(200, "text/plain", "Soundbar source ON/OFF");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP Server Started");
}
void loop(void){
server.handleClient();
}