-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsendDataFromServerToBoard.cpp
42 lines (37 loc) · 1 KB
/
sendDataFromServerToBoard.cpp
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
#include "Arduino.h"
#include "ServerExceed.h"
void ServerExceed::sendDataFromServerToBoard() {
// Check if a client has connected
WiFiClient client = server->available();
if (!client) {
return;
}
// Wait until the client sends some data
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
client.flush();
// Match the request
String data;
if (req.indexOf("/") != -1) {
data = req.substring(req.indexOf("/") + 1, req.indexOf(" ", req.indexOf(" ") + 1));
}
else {
client.stop();
return;
}
client.flush();
// Send date to board
Serial.println(data + "\r");
// Prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n";
s += data;
s += "</html>\n";
// Send the response to the client
client.print(s);
delay(1);
// The client will actually be disconnected
// when the function returns and 'client' object is detroyed
}