-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.ino
91 lines (81 loc) · 2.78 KB
/
routes.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
void setRoutes() {
server.on("/", handleRoot);
server.on("/brightness", []() { // Set brightness
brightness = server.arg(0).toInt();
FastLED.setBrightness( brightness );
FastLED.show();
server.send(200);
});
server.on("/color/single", []() { // Single color
for ( int i = 0; i < 3; i++) {
rgbSingleColor[i] = server.arg(i).toInt();
}
modeChar = 's';
singleColor(rgbSingleColor);
server.send(200);
});
server.on("/color/double", []() { // Double color
for ( int i = 0; i < 6; i++) {
rgbDoubleColor[i] = server.arg(i).toInt();
}
modeChar = 'd';
doubleColor(rgbDoubleColor);
server.send(200);
});
server.on("/color/rainbow", []() { // Rainbow color
modeChar = 'r';
server.send(200);
});
server.on("/color/custom", HTTP_POST, []() { // Custom color
String data;
data = server.arg(0);
for ( int i = 0; i < 3*NUM_LEDS; i = i + 3) {
leds[(i/3)].setRGB( (uint8_t) data[i], (uint8_t) data[i+1], (uint8_t) data[i+2]);
}
FastLED.show();
server.send(200);
});
server.on("/animation", []() { // Animation Selection
String animation = server.arg(0);
animationChar = animation.charAt(0);
server.send(200);
if ( animationChar == 'b') {
delayBreathing = server.arg(1).toInt();
breathCount = 0;
}
});
server.on("/status", []() { // turn on and off, and get current mode
//server.send(200, "text/plain", animationChar);
server.send(200, "text/plain", (String) brightness);
});
server.on("/connect", []() { // conenct to wifi
ssid = server.arg(0);
server.send(200);
ssid.replace("%20", " ");
password = server.arg(1);
server.send(200, "text/plain", WiFi.macAddress());
Serial.println(ssid);
Serial.println(password);
wifiMode = 's'; // inserir validação para ssid e password
server.stop();
WiFiconfig(wifiMode);
});
server.onNotFound(handleNotFound);
}
void handleRoot() {
server.send(200, "text/plain", "XX XXXXX XXXXXXXX XX XXXXXX XXXXXX\nXX XX XX XX XX XX XX XX\nXX XX XX XX XX XXXXX XX XX\nXX XX XX XX XX XX XX XX\nXX XXXXX XX XXXXXX XXXXXX XXXXXX");
}
void handleNotFound() {
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);
}