-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse.ino
50 lines (46 loc) · 1.4 KB
/
response.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
void responseHandler(WiFiClient cli){
Serial.println("Found, waiting for newline");
cli.setTimeout(400);
const int timeoutAfter = 1000;
unsigned long timeBegin = millis();
String reqHeader = "";
/*if(millis() - timeBegin > timeoutAfter){
Serial.print("Stopping");
String msg = "Didn't recieve a newline in time";
writeHeaders(cli, msg.length());
cli.print(msg);
cli.stop();
return;
}*/
while (cli.connected() && millis() - timeBegin <= timeoutAfter) {
Serial.println("<<<watiing");
String line = cli.readStringUntil('\n');
if(line.length() == 0){
Serial.print("line = 0len");
break;
}
Serial.print(" " + line);
reqHeader += line;
if (line.length() != 1) {
// Serial.println("Skipping line");
continue;
}
Serial.println("--Whole request header read--");
//When client has sent whole request header
if(reqHeader.indexOf("GET") > -1){
handleGet(cli, reqHeader);
}
else if(reqHeader.indexOf("POST") > -1){
handlePost(cli);
}
else {
String msg = "not post nor get";
writeHeaders(cli, msg.length());
cli.print(msg);
}
break;
}
//Now we have sent response
cli.stop();
Serial.println("end o func");
}