boylesg:
OK, makes sense.
But to interpret the form data correctly I am obligated to read the port on char at a time - I need to pick up '%' in order to convert it and the following hex value to the corresponding ASCII character.
This is because I am sending lists of dates and times as values for some hidden form fields.
I ended up reducing the baud rate of the ESP8266 to 74880 bps and I seem to have solved this problem.
However I now have another:
The following are HTTP requests received and dumped in the Serial monitor.
The default HTTP requests 'GET / HTTP/1.1' seem to work just fine.
But as soon as I try and send through a POST request 'POST /program.htm HTTP/1.1' I am getting a timeout error after my post data appears to have been successfully read:
"R=&euny&L=TS=&NRT=&TSD=&Station1=suspend%3A%231%2F1+-+00%3A00%2810%29%231%2F5+-+00%3A00%2810%29%231%2F9+-+00%3A00%2810%29&Station2=suspend%3A%23&Station3=suspend%3A%23&Station4=suspend%3A%23&Station5=suspend%3A%23&Station6=suspend%3A%23&Station7=suspend%3A%23&Station8=suspend%3A%23[WiFiEsp] TIMEOUT: 73"
Changing the timeout values in EspDrv.cpp from the WifiESP library makes no difference.
I notice that there is no \r\n\r\n after my data and I am wondering if bool EspDrv::getData(uint8_t connId, uint8_t data, bool peek, bool connClose) in EspDrv.cpp is expecting this in order to terminate the loop successfully?
And I am also wondering if EspDrv::getData(uint8_t connId, uint8_t data, bool peek, bool connClose) is designed specifically for GET requests only and not POST request?
[WiFiEsp] New client 0
New HTTP request
GET / HTTP/1.1
Host: 10.0.0.79
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1
HTTP request:
GET / HTTP/1.1
Host: 10.0.0.79
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Sending default HTTP response...
RTC battery voltage: 3.4, 351
HTTP response took 17886ms to service...
[WiFiEsp] Disconnecting 0
Client disconnected
[WiFiEsp] New client 0
New HTTP request
POST /program.htm HTTP/1.1
Host: 10.0.0.79
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://10.0.0.79/
Connection: kee-lv
UgaeneueRqet:1CnetTp:plcto/wwfr-rnoe
Ctn-et:25
R=&euny&L=TS=&NRT=&TSD=&Station1=suspend%3A%231%2F1+-+00%3A00%2810%29%231%2F5+-+00%3A00%2810%29%231%2F9+-+00%3A00%2810%29&Station2=suspend%3A%23&Station3=suspend%3A%23&Station4=suspend%3A%23&Station5=suspend%3A%23&Station6=suspend%3A%23&Station7=suspend%3A%23&Station8=suspend%3A%23[WiFiEsp] TIMEOUT: 73
GET and POST transmissions are very similar, GET does not have a body, and parameters are passed by appending them to the web page: See Wiki
GET \pagename?fieldname1=data&fieldname2=data HTTP/1.1
Host: hostname
terminated with a blank line
While a POST moves the parameters into a body:
POST \pagename HTTP/1.1
Host: hostname
fieldname1=data&fieldname2=data
a blank line separates the BODY from the HEADER, and the BODY is Terminated by a blank line. The BODY could be MIME encoded.
It still looks like you are loosing data.
The Post Data should be:
fieldname1=data&fieldname2=data ...
And, many symbols are % escaped. So If i take your example output
R=&euny&L=TS=&NRT=&TSD=&Station1=suspend%3A%231%2F1+-+00%3A00%2810%29%231%2F5+-+00%3A00%2810%29%231%2F9+-+00%3A00%2810%29&Station2=suspend%3A%23&Station3=suspend%3A%23&Station4=suspend%3A%23&Station5=suspend%3A%23&Station6=suspend%3A%23&Station7=suspend%3A%23&Station8=suspend%3A%23
Becomes:
R=
euny // this one is bad
L=TS= // this one is bad
NRT=
TSD=
Station1=suspend:#1/1+-+00:00(10)#1/5+-+00:00(10)#1/9+-+00:00(10)
Station2=suspend:#
Station3=suspend:#
Station4=suspend:#
Station5=suspend:#
Station6=suspend:#
Station7=suspend:#
Station8=suspend:#
How much of this decoded data is what you exected?
The [WiFiEsp] TIMEOUT: 73 message just means that you did not acknowledge the post data to the client within the timeout period.
Code to accept these parameters into a memory buffer with null terminators would be something like this:
#define BUFFLEN 500 // pool for parameters
char pool[BUFFLEN+1]; // + room for final NULL
uint16_t poolPos=0; // next position in pool
bool done=false;
bool blankline=false;
bool error=false;
while(!done&&!error){
if(Serial.available()){
ch=Serial.read();
if(ch=='%'){ // escaped char
while(!Serial.available()); // wait forever for char, needs a timeout!
ch=Serial.read()-48;
pool[poolPos] = (ch>9?ch-7:ch)*16; // convert from hex to Decimal
while(!Serial.available()); // wait forever for char, needs a timeout!
ch=Serial.read()-48;
pool[poolPos++] += (ch>9?ch-7:ch); // convert from hex to Decimal
}
else if (ch=='\n' && blankline){ // done, Yea
done = true;
pool[poolPos++]= '\0'; // terminal null for last param
}
else if (ch=='\n') { // starting new line
blankline = true;
}
else if (ch!='\r') { // non blank line
blankline=false;
if(ch=='&'){ // separator between params
pool[poolPos++]='\0';
}
else pool[poolPos++]=ch;
}
error=!(poolPos<BUFFLEN); // need room for two NULLs, one for the last string, one for the buffer
}
// should have some timeout
}
if(!error) pool[poolPos]='\0'; // Make a double NULL to mark end of params in buffer
// Also, pooPos will indicate end of the 'used' pool.
if (done) send_http_acknowledge (200);
pool[] will have all of the parameters a cstrings, each cstring will be name=value
Chuck.