-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUGreen_IR_Remote_Arduino.ino
174 lines (141 loc) · 5.98 KB
/
UGreen_IR_Remote_Arduino.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
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
#include <Arduino.h>
#define DISABLE_CODE_FOR_RECEIVER // Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not used.
//#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM.
//#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition
#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc.
#include <IRremote.hpp>
#include <SPI.h>
#include <Ethernet.h>
#define DEBUG 0 //1 for print debug information in Serial monitor. 0 for hide all.
#define COMMAND_ARRAY_SIZE 14
byte mac[] = { 0x01, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE }; //physical mac address
byte ip[] = { 192, 168, 3, 237 }; // IP address in LAN – need to change according to your Network address
byte gateway[] = { 192, 168, 3, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
void setup(){
pinMode(LED_BUILTIN, OUTPUT);
IrSender.begin(DISABLE_LED_FEEDBACK); // Start with IR_SEND_PIN as send pin and disable feedback LED at default feedback LED pin
if(DEBUG)
{
Serial.begin(115200);
}
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
}
uint8_t sCommand = 0x47;
const uint8_t sCommands[COMMAND_ARRAY_SIZE] =
{ 0x45, //Power
0x47, //ScreenShow
0x44, //In 1
0x40, //In 2
0x07, //In 3
0x15, //In 4
0x43, //Channel -
0x09, //Channel +
0xC, //2 sources in 1 view
0x18, //4 sources in 1 view
0x08, //1 big + 3 small sources in 1 view
0x1c, //Fullscreen
0x5e, //Audio
0x5a //720or1080p resolution change
};
uint8_t sRepeats = 0;
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 30) {
//store characters to string
readString += c;
}
//if HTTP request has ended– 0x0D is Carriage Return \n ASCII
if (c == 0x0D) {
// control arduino pin
if(readString.indexOf("/run/") > -1) //checks for /run/(index) url
{
if(DEBUG)
{
Serial.print(readString);
Serial.print("\n");
Serial.print(readString.length());
Serial.print("\n");
Serial.print(readString.substring(9,readString.length()-10));
Serial.print("\n");
}
String runID = readString.substring(9,readString.length()-10);
int runIDint = 0;
if(runID.endsWith("/")){
runIDint = runID.substring(0, runID.length()-1).toInt();
if(DEBUG) Serial.print("With /");
if(DEBUG) Serial.print("\n");
}
else
{
runIDint = runID.toInt();
if(DEBUG) Serial.print("Without /");
if(DEBUG) Serial.print("\n");
}
if(DEBUG)
{
Serial.print("ID int: ");
Serial.print(runIDint);
Serial.print("\n");
}
//run irSend
if(runIDint< COMMAND_ARRAY_SIZE)
{
mySendIR(sCommands[runIDint]);
client.println("HTTP/1.1 200 OK"); //send 200 back
//client.println("Content-Type: text/html");
client.println();
client.stop();
}
else
{
client.println("HTTP/1.1 406 Not Acceptable"); //send 406 back
//client.println("Content-Type: text/html");
client.println();
client.stop();
}
}
else
{
client.println("HTTP/1.1 400 Bad Request"); //send erreur request
//client.println("Content-Type: text/html");
client.println();
client.stop();
}
//clearing string for next read
readString="";
}
}
}
}
}
void mySendIR(uint8_t _cmd){
/*
* Print current send values
*/
Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(_cmd, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats);
Serial.println();
Serial.println(F("Send standard NEC with 8 bit address"));
Serial.flush();
// Receiver output for the first loop must be: Protocol=NEC Address=0x102 Command=0x34 Raw-Data=0xCB340102 (32 bits)
IrSender.sendNEC(0x00, _cmd, sRepeats);
sRepeats++;
// clip repeats at 3
if (sRepeats > 3) {
sRepeats = 3;
}
}