Hi im trying to parse some data from an HTTP request I have tried diferent codes but my problem is that the server also have to respond to other request like page stuff from SD card so I think that the GET from files and the GET to parse are interacting in the wrong way here is my code so far
if someone could help me please
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
// limit the size of the stored received HTTP request
// buffer first part of HTTP request in HTTP_req array (string)
// leave last element in array as 0 to null terminate string (REQ_BUF_SZ - 1)
if (req_index < (REQ_BUF_SZ - 1)) {
HTTP_req[req_index] = c; // save HTTP request character
req_index++;
}
if( client.find("?") ) { // search for '?'
// find tokens starting with "?" and stop on the first blank line
// search to the end of line for 'pin'
while(client.findUntil("joy", "\n\r")){
char type = client.read(); // D or A
// the next ascii integer value in the stream is the pin
float value = client.parseFloat();
if( type == 't') {
Serial.print("Throttle ");
throt = value;
int t1 = int (throt * 100);
contr[0] = t1;
}
else if( type == 'y'){
Serial.print("Steer ");
steer = value;
int t2 = int (steer * 100);
contr[1] = t2;
}
else {
Serial.print("Unexpected type ");
Serial.print(type);
}
}
Mirf.setTADDR((byte *)"clie1");
Mirf.payload = sizeof(contr);
Mirf.send(contr);
while(Mirf.isSending()){
}
}
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
// remainder of header follows below, depending on if
// web page or XML page is requested
// Ajax request - send XML file
/*if (StrContains(HTTP_req, "ajax_inputs")) {
// send rest of HTTP header
client.println("Content-Type: text/xml");
client.println("Connection: keep-alive");
client.println();
SetLEDs();
// send XML file containing input states
XML_response(client);
}
else*/ if (StrContains(HTTP_req, "GET /cont.htm")) {
// send rest of HTTP header
client.println("Content-Type: text/html");
client.println("Connection: keep-alive");
client.println();
// send web page
webFile = SD.open("cont.htm"); // open web page file
// send web page to client
if (webFile) {
while(webFile.available()) {
client.write(webFile.read());
}
webFile.close();
}
}