-
Notifications
You must be signed in to change notification settings - Fork 29
/
webserver.ino
212 lines (188 loc) · 5.02 KB
/
webserver.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include <WebServer.h>
#ifdef webServer
const char GYRO_PID[] PROGMEM = R"=====(
<!DOCTYPE html>
<html>
<head>
<style>
form,input,h2
{
color: black;
text-align: center;
font-size:6vw;
font-family: monospace;
}
p
{
text-align: center;
font-size:6vw;
}
body
{
background-color: lightblue;
}
</style>
</head>
<body>
<h2>EspCopter Gyro PID</h2>
<form action="/action_page">
Gyro_P: <input type="number" name="pid_p" value="%d" max="200" min="0">
<br>
Gyro_I: <input type="number" name="pid_i" value="%d" max="200" min="0">
<br>
Gyro_D: <input type="number" name="pid_d" value="%d" max="200" min="0">
<br><br>
<input type="submit" value="Submit">
</form>
<p>
<a href="/gyro_page">Gyro PID</a>
<a href="/level_page">Level PID</a>
</p>
</body>
</html>
)=====";
const char ACC_PID[] PROGMEM = R"=====(
<!DOCTYPE html>
<html>
<head>
<style>
form,input,h2
{
color: black;
text-align: center;
font-size:6vw;
font-family: monospace;
}
p
{
text-align: center;
font-size:6vw;
}
body
{
background-color: lightblue;
}
</style>
</head>
<body>
<h2>EspCopter Level PID</h2>
<form action="/action_level">
Level_P: <input type="number" name="lev_p" value="%d" max="200" min="0">
<br>
Level_I: <input type="number" name="lev_i" value="%d" max="200" min="0">
<br>
Level_D: <input type="number" name="lev_d" value="%d" max="200" min="0">
<br><br>
<input type="submit" value="Submit">
</form>
<p>
<a href="/gyro_page">Gyro PID</a>
<a href="/level_page">Level PID</a>
</p>
</body>
</html>
)=====";
//SSID and Password of your WiFi router
const char* ssid = "FSM";
const char* password = "0101010101";
WebServer server(80); //Server on port 80
//===============================================================
// This routine is executed when you open its IP in browser
//===============================================================
void handleRoot()
{
char temp[1000];
snprintf(temp,1000,GYRO_PID, int(P_PID*100.0+0.4),int(I_PID*100.0+0.4),int(D_PID*100.0+0.4));
server.send(200, "text/html", temp); //Send web page
Serial.println("root page served");
}
void handleGyro()
{
char temp[1000];
snprintf(temp,1000,GYRO_PID, int(P_PID*100.0+0.4),int(I_PID*100.0+0.4),int(D_PID*100.0+0.4));
server.send(200, "text/html", temp); //Send web page
Serial.println("gyro page served");
}
void handleLevel()
{
char temp[1000];
snprintf(temp,1000,ACC_PID, int(P_Level_PID*100.0+0.4),int(I_Level_PID*100.0+0.4),int(D_Level_PID*100.0+0.4));
server.send(200, "text/html", temp); //Send web page
Serial.println("level page served");
}
//===============================================================
// This routine is executed when you press submit
//===============================================================
void action_pid()
{
int p = server.arg("pid_p").toInt();
int i = server.arg("pid_i").toInt();
int d = server.arg("pid_d").toInt();
P_PID = float(p) * 0.01 + 0.004;
I_PID = float(i) * 0.01 + 0.004;
D_PID = float(d) * 0.01 + 0.004;
PID_Store();
Serial.println("Gyro pid stored");
handleGyro();
}
void action_level()
{
int pl = server.arg("lev_p").toInt();
int il = server.arg("lev_i").toInt();
int dl = server.arg("lev_d").toInt();
P_Level_PID = float(pl) * 0.01 + 0.004;
I_Level_PID = float(il) * 0.01 + 0.004;
D_Level_PID = float(dl) * 0.01 + 0.004;
PID_Store();
Serial.println("Level pid stored");
handleLevel();
}
/*
void action_calib()
{
Serial.println("Doing ACC calib");
calibratingA = CALSTEPS;
while (calibratingA != 0)
{
delay(CYCLETIME);
ACC_getADC();
}
ACC_Store();
Serial.println("ACC calib Done");
handleCalib();
}
*/
//==============================================================
// SETUP
//==============================================================
void setupwebserver(void)
{
WiFi.begin(ssid, password); //Connect to your WiFi router
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
//If connection successful show IP address in serial monitor
Serial.println("");
Serial.print("Connected to ");
Serial.println("WiFi");
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //IP address assigned to your ESP
server.on("/", handleRoot); //Which routine to handle at root location
server.on("/gyro_page", handleGyro); //Which routine to handle at gyro location
server.on("/level_page", handleLevel); //Which routine to handle at level location
server.on("/action_page", action_pid); //form action is handled here
server.on("/action_level", action_level); //form action is handled here
//server.on("/action_calib", action_calib); //form action is handled here
server.begin(); //Start server
Serial.println("HTTP server started");
}
//==============================================================
// LOOP
//==============================================================
void loopwebserver(void) { server.handleClient(); }
void stopwebserver(void) { server.stop(); }
#endif