-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEvo_HTML.ino
268 lines (243 loc) · 8.2 KB
/
Evo_HTML.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
// 5 Web Interface -----------------------------------------------------------
/* >>>>>>>>>>>>>>>>>>>>> Constants and Variables <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
boolean reload = false; // variable to control redirecting, was bugging when I made it local
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
// 5a webLoop - prints data to webserver if there is a request
void webLoop() {
boolean dataRead = false; // flag for if data has been read
boolean reload = false; // suspect it needs to be local to loop
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
parseHttpHeader(client, &dataRead);
if (dataRead == true) { // don't print rest of html code if data has been viewed.
break;
}
if (reload == true) { // redirect to main page if parameter has been changed
if(debugMode) {}
htmlRedirect(client); // refresh page
client.stop();
// delay(5000); // used to break up the network requests to a human legible frequency
webLoop();
break;
} else {
}
htmlHeader(client);
client.print("The Evolvinator");
client.print("<br />");
client.print("<a href=\"http://pterodactyl.ginkgobioworks.com:8081\" target=\"_blank\">View Evolvinator</a>");
client.print("<p>");
displayData(client, "Volume", volume, "ml");
displayData(client, "OD Threshold", ODDesired, "A600");
displayData(client, "OD Zero Value", ODZero, "");
displayData(client, "Maximum Flow", flowMax, "ml/hr");
displayData(client, "Pulse Volume", pulseVol, "ml");
displayData(client, "Max Pulse Frequency", float(feedFrequency / 1000), "seconds");
displayData(client, "Temperature Desired", tempDesired, "C");
client.print("</p>");
// Pre run optionst
if (!tStart) {
submitButton(client, "Begin Evolvination!", "s");
}
// Run Data
// Temp
client.print("<p>");
displayData(client, "One Minute Temperature Average", tempPrintAvg, "C");
client.print("</p>");
if (tStart) {
// Time
client.print("<p>");
displayTime(client, "Run Started", tStart, true, false);
displayTime(client, "Elapsed Time", tElapsed, false, true);
client.print("</p>");
// OD
client.print("<p>");
displayData(client, "Last OD Measurement", ODMin[0], "A600");
displayData(client, "3 Minute OD Average", OD3MinAvg, "A600");
client.print("</p>");
// Flow
client.print("<p>");
if (tPulse) {
displayTime(client, "Last Pulse At", tPulse, true, false);
}
else {
client.print("Last Pulse At: Threshold Not Reached");
}
client.print("</p>");
}
// Buttons
submitButton(client, "Download Data", "d");
fieldSubmitButton(client, "Change OD Threshold:", "o");
fieldSubmitButton(client, "Change Max Flowrate (ml/h):", "f");
fieldSubmitButton(client, "Change Temperature:", "t");
submitButton(client, "Zero OD Sensor", "z");
fieldSubmitButton(client, "Add Media (ml):", "a");
submitButton(client, "Toggle Debug Mode", "i");
if (debugMode) {
client.print("Debug:<br />");
client.print("tstat1v5.5<br />Unix Time ");
client.print(tUnix);
client.print("<br />tElapsed ");
client.print(tElapsed);
client.print("<br />msElapsedPrestart ");
client.print(msElapsedPrestart);
}
htmlFooter(client);
break;
}
}
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection:
}
}
void htmlHeader(EthernetClient client) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>\n<HEAD>");
client.println("<TITLE>The Evolvinator</TITLE>");//
client.println("</HEAD><BODY bgcolor=\"#FFFFFF\">");
}
void htmlFooter(EthernetClient client) {
client.println("</BODY></HTML>");
}
void htmlRedirect(EthernetClient client) {
client.println("<HTML>\n<HEAD>");
client.println("<meta http-equiv='Refresh' content='0;url=http://192.168.1.36:80' />"); // ENTER, if this not changed then no redirects will work
client.println("<BODY>Redirecting</BODY>");
client.println("</HEAD>\n</HTML>");
}
void displayData(EthernetClient client, char *label, float value, char *unit) {
client.print(label);
client.print(" = ");
client.print(value);
client.print(" ");
client.print(unit);
client.print("<br />");
}
void displayTime(EthernetClient client, char *label, unsigned long time, boolean date, boolean days) {
client.print(label);
client.print(": ");
if (days) {
client.print(time / 86400);
client.print(":");
}
client.print(hour(time));
client.print(":");
if (minute(time) < 10) {
client.print("0");
}
client.print(minute(time));
client.print(":");
if (second(time) < 10) {
client.print("0");
}
client.print(second(time));
if (date) {
client.print(" ");
client.print(month(time));
client.print("/");
client.print(day(time));
client.print("/");
client.print(year(time));
}
client.print("<br />");
}
void submitButton(EthernetClient client, char *label, char *identifier) {
client.print("<form method=post action=\"/?");
client.print(identifier);
client.print("\"><input type=submit value=\"");
client.print(label);
client.print("\">");
client.print("</form>");
}
void fieldSubmitButton(EthernetClient client, char *fieldLabel, char *identifier) {
client.print("<form method=get action=\"/?\">");
client.print(fieldLabel);
client.print("<input type=txt name=\"");
client.print(identifier);
client.print("\"> <input type=submit value=\"Submit\">");
client.print("</form>");
}
void parseHttpHeader(EthernetClient client, boolean *dataRead) {
char c;
while((c = client.read()) != '?' && client.available()) { // Skip through until a question mark (first one)
}
if (client.available()) {
c = client.read();
}
else {
return;
}
// Change Parameters
switch (c) { // Change OD
case 'o':
client.read(); // skip = sign
char ODHtml[5]; // 4 character string (3 numbers with decimal)
for (int i=0; i < 4; i++) {
ODHtml[i] = client.read(); // Read and dump data to debug port
}
ODDesired = atof(ODHtml);
reload = true;
break;
case 'f':
client.read(); // skip = sign
char flowHtml[6]; // 5 character string (3 numbers with decimal)
for (int i=0; i < 5; i++) {
flowHtml[i] = client.read(); // Read data
}
flowMax = atof(flowHtml);
flowSet();
reload = true;
break;
case 't':
client.read(); // skip = sign
char tempHtml[5]; // 4 character string (3 numbers with decimal)
for (int i=0; i < 4; i++) {
tempHtml[i] = client.read(); // Read data
}
tempDesired = atof(tempHtml);
tempSet();
reload = true;
break;
case 's':
startRun();
reload = true;
break;
case 'z':
ODCalibrate();
reload = true;
break;
case 'd':
SDWebLoad(client);
*dataRead = true;
break;
case 'e':
c = client.read();
char unixTimeStamp[11];
for (int i=0; i < 10; i++) {
unixTimeStamp[i] = client.read(); //record unix timestamp
}
SDWebLoadLIMS(client, unixTimeStamp);
*dataRead = true;
break;
case 'a':
{
client.read(); // skip = sign
char addMediaHtml[5]; // 4 character string (3 numbers with decimal)
for (int i=0; i < 4; i++) {
addMediaHtml[i] = client.read(); // Read and dump data to debug port
}
float addMediaMl = atof(addMediaHtml);
addMedia(addMediaMl);
reload = true;
break;
}
case 'i':
if (debugMode) debugMode = false;
else debugMode = true;
reload = true;
break;
}
}