-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.ino
83 lines (68 loc) · 1.96 KB
/
debug.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
#include <DmxMaster.h>
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#define N 24
// Ethernet controller
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0xCD, 0xB1 };
EthernetServer server(80);
// GET variables
char c;
String url;
File web;
void setup() {
Serial.begin(9600);
// DmxMaster.maxChannel(3);
url.reserve(N);
Ethernet.begin(mac);
delay(1000);
server.begin();
if (!SD.begin(4)) {
Serial.println(F("404 SD Card Not Found"));
return;
}
Serial.print(F("All GO @ "));
Serial.println(Ethernet.localIP());
}
void loop() {
EthernetClient client = server.available();
if (client) { // neat!
boolean newLine = true;
while (client.connected()) {
if (client.available()) {
c = client.read(); // will read char-by-char to check for the newline ending
if (url.length() < N) url += c;
if (c == '\n' && newLine) { // the HTTP request has ended, send a reply
// GET
if (url.indexOf('?') >= 0) {
DmxMaster.write(1, url.substring(8, url.indexOf('&', 9)).toInt()); // R
DmxMaster.write(2, url.substring(url.indexOf('g', 10) + 2, url.indexOf('&', 13)).toInt()); // G
DmxMaster.write(3, url.substring(url.indexOf('b', 14) + 2, url.indexOf(' ', 17)).toInt()); // B
}
// HTTP header
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/html"));
client.println(F("Connection: close"));
client.println();
// HTML from SD
web = SD.open("index.htm");
if (web) {
while (web.available()) {
client.write(web.read());
}
web.close();
}
break; // from while
}
if (c == '\n') {
newLine = true;
} else if (c != '\r') {
newLine = false;
}
}
}
delay(1);
url = "";
client.stop();
}
}