-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
330 lines (299 loc) · 10.9 KB
/
main.cpp
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/* Modified by Randy Tsuchiyama for my setup
* Based on
* WiFi IR Blaster by Buddy Crotty
* Use an ESP8266 module or dev board to receive HTTP GET request
* and then send IR codes to an attached IR LED based on those requests.
* This works best with another web server acting as a front end that
* sends cURL requests based on which buttons are pressed.
* cURL format: http://ESP8266/IRcode
Codes were determined by using the adafruit guide found there
https://learn.adafruit.com/using-an-infrared-library/hardware-needed
using irlib2
this worked for sony tv and onkyo receiver, but not for panasonic blu ray
so I had to read raw codes for panny
Sony TV codes
off = F50 = dec 3920
on = 750 = dec 1872
pwr toggle = A90 = 2704
v+ = 490 = 1168
v- = c90 = 3216
mute = 290 = 656
used this for rx of raw rawData
https://github.com/cyborg5/IRLib2/blob/master/IRLib2/examples/rawRecv/rawRecv.ino
*/
#include <ESP8266WiFi.h>
#include <IRremoteESP8266.h>
///////////////////////////////////////////////////////
//added to make work
#include <IRsend.h> // Needed if you want to send IR commands.
#include <IRrecv.h> // Needed if you want to receive IR commands.
///////////////////////////////////////////////////////
#include <ESP8266mDNS.h>
// Wifi ssid and password here
const char* ssid = "";
const char* password = "";
MDNSResponder mdns;
int khz = 38; // 38kHz carrier frequency for both NEC and Samsung
IRsend irsend(4); //an IR led is connected to GPIO4 (pin D2 on NodeMCU)
//////////////////////////////////////////////////
// changed types to uint16_t for all of the arrays below with the raw ir codes
// Insert RAW IR signal for panny blu ray power toggle
uint16_t irDVDpwr[100]={
3450, 1778, 398, 502, 374, 1346, 398, 498,
370, 502, 374, 498, 366, 506, 374, 498,
366, 506, 370, 502, 374, 498, 370, 502,
374, 498, 370, 502, 374, 1342, 402, 498,
366, 506, 370, 502, 366, 506, 370, 502,
366, 506, 370, 1346, 398, 1350, 390, 506,
370, 1350, 394, 506, 370, 502, 366, 506,
370, 502, 366, 506, 370, 498, 366, 506,
374, 498, 366, 506, 370, 1350, 394, 502,
374, 1346, 398, 502, 374, 498, 370, 502,
374, 498, 366, 506, 374, 1342, 398, 502,
366, 1350, 402, 1346, 398, 1346, 398, 502,
374, 1342, 450, 1000};
uint16_t irDVDpwroff[]={ 3456U, 1728U, 432U, 432U, 432U, 1296U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 1296U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 1296U, 432U, 1296U, 432U, 432U, 432U, 1296U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 1296U, 432U, 432U, 432U, 1296U, 432U, 1296U, 432U, 1296U, 432U, 1296U, 432U, 432U, 432U, 432U, 432U, 1296U, 432U, 432U, 432U, 1296U, 432U, 1296U, 432U, 432U, 432U, 432U, 432U, 432U, 432U, 1296U, 432U, 65535U };
uint16_t irDVDplay[100]={
3450, 1778, 398, 502, 374, 1346, 398, 498,
370, 502, 374, 498, 366, 506, 374, 498,
366, 506, 370, 502, 374, 498, 370, 502,
374, 498, 370, 502, 374, 1342, 402, 498,
366, 506, 370, 502, 366, 506, 370, 502,
366, 506, 370, 1346, 398, 1350, 390, 506,
370, 1350, 394, 506, 370, 502, 366, 506,
370, 502, 366, 506, 370, 498, 366, 506,
374, 498, 366, 506, 370, 1350, 394, 502,
374, 1346, 398, 502, 374, 498, 370, 502,
374, 498, 366, 506, 374, 1342, 398, 502,
366, 1350, 402, 1346, 398, 1346, 398, 502,
374, 1342, 450, 1000};
uint16_t irDVDpause[100]={
3454, 1806, 370, 502, 374, 1342, 402, 498,
366, 506, 370, 502, 366, 506, 370, 502,
366, 506, 370, 502, 366, 506, 370, 502,
374, 494, 370, 502, 378, 1342, 398, 502,
366, 506, 370, 502, 366, 506, 370, 498,
366, 506, 374, 1346, 394, 1350, 394, 506,
370, 1346, 398, 502, 374, 498, 370, 502,
374, 498, 366, 506, 370, 502, 366, 506,
370, 502, 366, 506, 370, 1346, 398, 1350,
390, 506, 374, 498, 366, 506, 370, 502,
374, 498, 370, 502, 374, 1346, 398, 1346,
398, 502, 374, 1342, 402, 1346, 394, 502,
378, 1342, 398, 1000};
uint16_t irDVDff[100]={
3446, 1786, 402, 498, 370, 1346, 394, 506,
370, 502, 366, 506, 370, 502, 366, 506,
370, 502, 362, 510, 370, 498, 378, 494,
370, 502, 374, 498, 370, 1378, 366, 506,
370, 502, 362, 506, 374, 498, 366, 506,
370, 502, 374, 1374, 370, 1346, 398, 502,
374, 1342, 402, 498, 366, 506, 374, 498,
366, 506, 370, 502, 366, 506, 370, 502,
374, 498, 370, 1374, 366, 506, 374, 1342,
398, 502, 374, 498, 370, 502, 374, 498,
370, 502, 374, 1346, 398, 498, 378, 1342,
398, 502, 366, 1350, 402, 1342, 402, 498,
370, 1350, 402, 1000};
uint16_t irDVDrev[100]={
3450, 1778, 398, 502, 374, 1346, 398, 498,
366, 506, 374, 498, 366, 506, 370, 502,
374, 498, 370, 502, 374, 498, 370, 502,
374, 498, 366, 506, 374, 1342, 398, 502,
366, 506, 370, 502, 374, 498, 370, 502,
374, 498, 366, 1350, 394, 1354, 398, 498,
370, 1350, 394, 506, 370, 502, 374, 498,
370, 502, 374, 494, 370, 502, 374, 498,
370, 502, 374, 498, 370, 502, 374, 1346,
398, 498, 378, 494, 370, 502, 374, 498,
370, 502, 374, 498, 370, 502, 374, 1346,
450, 450, 426, 1290, 398, 1346, 398, 502,
374, 1346, 398, 1000};
uint16_t irDVDstop[100]={
3454, 1778, 398, 502, 366, 1350, 402, 498,
370, 502, 374, 498, 366, 506, 370, 502,
366, 506, 370, 502, 366, 506, 370, 502,
366, 506, 370, 498, 378, 1342, 402, 498,
366, 506, 370, 502, 366, 506, 370, 502,
366, 502, 374, 1346, 394, 1350, 394, 506,
370, 1350, 394, 502, 374, 498, 370, 502,
374, 498, 366, 506, 374, 498, 366, 506,
370, 502, 366, 506, 370, 502, 374, 498,
370, 502, 374, 498, 366, 506, 374, 498,
366, 502, 374, 498, 370, 502, 374, 498,
370, 502, 374, 1346, 398, 1346, 394, 506,
370, 1346, 398, 1000};
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
irsend.begin();
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi Connected");
// Start the server
server.begin();
Serial.println("HTTP Server Started");
// Print the IP address
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
if (mdns.begin("IRBlasterLR", WiFi.localIP())) {
Serial.println("MDNS Responder Started");
}
Serial.println();
Serial.println();
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
client.print("command received");
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
// Match the request
if (req.indexOf("/irTVpon") != -1){
irsend.sendSony(1872, 12); //1872 = $750
Serial.println("IRreq irTVpon sent");
}
else if (req.indexOf("/irTVpoff") != -1){
irsend.sendSony(3920, 12); //3920 = $f50
Serial.println("IRreq irTVpoff sent");
}
else if (req.indexOf("/irTVmute") != -1){
irsend.sendSony(656, 12);
Serial.println("IRreq irTVmute sent");
}
else if (req.indexOf("/irTVvdn") != -1){
irsend.sendSony(3216, 12);
Serial.println("IRreq irTVvdn sent");
}
else if (req.indexOf("/irTVvup") != -1){
irsend.sendSony(1168, 12);
Serial.println("IRreq irTVvup sent");
}
else if (req.indexOf("/irTVvid1") != -1){
irsend.sendSony(48, 12);
Serial.println("IRreq video 1 sent");
}
else if (req.indexOf("/irTVvid2") != -1){
irsend.sendSony(2096, 12);
Serial.println("IRreq video 2 sent");
}
else if (req.indexOf("/irTVvid3") != -1){
irsend.sendSony(1072, 12);
Serial.println("IRreq video 3 sent");
}
else if (req.indexOf("/irTVvid4") != -1){
irsend.sendSony(3632, 12);
Serial.println("IRreq video 4 sent");
}
else if (req.indexOf("/irTVvid5") != -1){
irsend.sendSony(304, 12);
Serial.println("IRreq video 5 sent");
}
else if (req.indexOf("/irTVvid6") != -1){
irsend.sendSony(2352, 12);
Serial.println("IRreq video 6 sent");
}
else if (req.indexOf("/irTVvid7") != -1){
irsend.sendSony(8681, 15);
Serial.println("IRreq video 7 sent");
}
else if (req.indexOf("/irTVvid8") != -1){
irsend.sendSony(2640, 12);
Serial.println("IRreq video 8 sent");
}
else if (req.indexOf("/irTVvid9") != -1){
irsend.sendSony(13294, 15);
Serial.println("IRreq video 9 sent");
}
//else if (req.indexOf("/irALLpwr") != -1){
// irsend.sendRaw(irRECpwrON, sizeof(irRECpwrON) / sizeof(irRECpwrON[0]), khz);
// irsend.sendRaw(irTVpwr, sizeof(irTVpwr) / sizeof(irTVpwr[0]), khz);
// delay(2000);
// irsend.sendRaw(irRECsrc, sizeof(irRECsrc) / sizeof(irRECsrc[0]), khz);
// Serial.println("IRreq irALLpwr sent");
// }
else if (req.indexOf("/irDVD1pwr") != -1){
irsend.sendRaw(irDVDpwroff, 100U, 37U);
Serial.println("IRreq irDVDpwr0 sent");
}
else if (req.indexOf("/irDVDplay") != -1){
irsend.sendRaw(irDVDplay, 100U, 37U);
Serial.println("IRreq irDVDplay sent");
}
else if (req.indexOf("/irDVDstop") != -1){
irsend.sendRaw(irDVDstop, 100U, 37U);
Serial.println("IRreq irDVDstop sent");
}
else if (req.indexOf("/irRECpwrON") != -1){
irsend.sendNEC(1270227167, 32);
Serial.println("IRreq irRECpwrON sent");
}
else if (req.indexOf("/irRECpwrOFF") != -1){
irsend.sendNEC(1261888029, 32);
Serial.println("IRreq irRECpwrOFF sent");
}
else if (req.indexOf("/irRECmute") != -1){
irsend.sendNEC(1270227167, 32);
Serial.println("IRreq irRECmute sent");
}
else if (req.indexOf("/irRECvdn") != -1){
irsend.sendNEC(1270267967, 32);
Serial.println("IRreq irRECvdn sent");
}
else if (req.indexOf("/irRECvup") != -1){
irsend.sendNEC(1270235327, 32);
Serial.println("IRreq irRECvup sent");
}
else if (req.indexOf("/irRECTV") != -1){
irsend.sendNEC(1270263887, 32);
Serial.println("IRreq irRECTV sent");
}
else if (req.indexOf("/irRECAux") != -1){
irsend.sendNEC(1270282502, 32);
Serial.println("IRreq irRECAux sent");
}
else if (req.indexOf("/irRECCBL") != -1){
irsend.sendNEC(1270247567, 32);
Serial.println("IRreq irRECCBL sent");
}
else if (req.indexOf("/irRECDVD") != -1){
irsend.sendNEC(1261842894, 32);
Serial.println("IRreq irRECDVD sent");
}
else {
Serial.println("invalid request");
client.stop();
return;
}
client.flush();
// Send the response to the client
//client.print(s);
client.print("HTTP/1.1 200 OK\r\n");
delay(1);
Serial.println("Client Disconnected");
Serial.println();
// The client will actually be disconnected
// when the function returns and 'client' object is detroyed
}