-
Notifications
You must be signed in to change notification settings - Fork 1
/
Homeautomation_0_3.ino
170 lines (153 loc) · 3.27 KB
/
Homeautomation_0_3.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
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <TextFinder.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x94, 0x2A };
byte ip[] = { 192, 168, 1, 20 };
byte sdPin = 4;
short rc_pin=8;
EthernetServer server(80);
File webFile;
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(9600);
SD.begin(sdPin);
pinMode(rc_pin, OUTPUT);
}
void loop() {
EthernetClient client = server.available();
//////////
//SENDEN//
//////////
if(client){
TextFinder finder(client);
if(finder.find("GET")){
while(finder.findUntil("pin", "\n\r")){
char typ = client.read();
if(typ == 'A'){
sendCode("111010111101");
}
else if(typ == 'B'){
sendCode("111010111110");
}
else if(typ == 'C'){
sendCode("111011011101");
}
else if(typ == 'D'){
sendCode("111011011110");
}
else if(typ == 'E'){
sendCode("111100111101");
}
else if(typ == 'F'){
sendCode("111100111110");
}
else if(typ == 'G'){
sendCode("111101011101");
}
else if(typ == 'H'){
sendCode("111101011110");
}
else if(typ == 'I'){
sendCode("111101101101");
}
else if(typ == 'J'){
sendCode("111101101110");
}
else if(typ == 'K'){
sendCode("111101110101");
}
else if(typ == 'L'){
sendCode("111101110110");
}
}
}
}
/////////////
//WEBSERVER//
/////////////
boolean current_line_is_blank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
if (c == '\n' && current_line_is_blank)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
webFile = SD.open("index.htm");
if (webFile)
{
while(webFile.available())
{
client.write(webFile.read());
}
webFile.close();
}
break;
}
if (c == '\n')
{
current_line_is_blank = true;
}
else if (c != '\r')
{
current_line_is_blank = false;
}
}
}
delay(1);
client.stop();
}
////////////
//Funkcode//
////////////
boolean sendCode(char code[]){
for(short z = 0; z<9; z++){
for(short i = 0; i<12; i++){
sendByte(code[i]);
}
sendByte('x');
}
return true;
}
void sendByte(char i) {
switch(i){
case '1':{
digitalWrite(rc_pin,HIGH);
wait(1);
digitalWrite(rc_pin,LOW);
wait(3);
digitalWrite(rc_pin,HIGH);
wait(3);
digitalWrite(rc_pin,LOW);
wait(1);
return;
}
case '0':{
digitalWrite(rc_pin,HIGH);
wait(1);
digitalWrite(rc_pin,LOW);
wait(3);
digitalWrite(rc_pin,HIGH);
wait(1);
digitalWrite(rc_pin,LOW);
wait(3);
return;
}
case 'x':{
digitalWrite(rc_pin,HIGH);
wait(1);
digitalWrite(rc_pin,LOW);
wait(31);
}
}
}
void wait(int x) {
delayMicroseconds(x*320);
}