-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.ino
129 lines (100 loc) · 2.22 KB
/
web.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
#define STA_SSID "SSID"
#define STA_PSK "PASSWORD"
WebServer server(80);
void web_setup() {
WiFi.mode(WIFI_STA);
WiFi.begin(STA_SSID, STA_PSK);
int dots = -1;
while(WiFi.status() != WL_CONNECTED) {
if(dots == -1 || dots > 3) {
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("Press any key");
lcd.setCursor(0, 3);
lcd.print("to cancel.");
lcd.setCursor(0, 0);
lcd.print("Connecting");
dots = 0;
}
delay(500);
lcd.print(".");
dots++;
if(keypad.getKey()) {
// A key has been pressed. Cancel!
break;
}
}
server.begin();
web_configureEndpoints();
// Print stuff to lcd
lcd.clear();
lcd.setCursor(0, 0);
if(WiFi.status() == WL_CONNECTED) {
lcd.print("Connected!");
}else{
lcd.print("Cancelled.");
}
lcd.setCursor(0, 1);
lcd.print("IP: ");
lcd.print(WiFi.localIP());
lcd.setCursor(0, 3);
lcd.print("Press any key..");
while(!keypad.getKey()) {
delay(1);
}
lcd.clear();
beep(30, 1);
}
void web_loop() {
if(WiFi.status() == WL_CONNECTED) {
server.handleClient();
}
}
void web_configureEndpoints() {
server.on("/info", web_info);
}
void web_info() {
String out = "";
String state;
switch(currentState) {
case STATE_DISARMED:
state = "disarmed";
break;
case STATE_ARMED:
state = "armed";
break;
case STATE_DEFUSED:
state = "defused";
break;
case STATE_EXPLODED:
state = "exploded";
break;
case STATE_SETUP:
state = "setup";
break;
default:
state = currentState;
break;
}
// General data
out += "\nmillis=";
out += millis();
out += "\nstate=";
out += state;
// Config data
out += "\nconfig_brightness=";
out += config_brightness;
out += "\nconfig_explodeTime=";
out += config_explodeTime;
out += "\nconfig_defuseTime=";
out += config_defuseTime;
// Disarmed state
out += "\nenteredCode=";
out += enteredCode;
// Armed state
out += "\nmillisArmed=";
out += currentState == STATE_ARMED ? millisArmed() : 0;
out += "\nmillisDefusing=";
out += currentState == STATE_ARMED ? millisDefusing() : 0;
server.send(200, "text/plain", out);
}