Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By bubba198
#34140 Hi everyone,

I'm using native Arduino code (not the AT firmware) compiled with the Arduino IDE for ESP 8266.

I was hoping to get some advice on How to filter all those HTTP headers in a GET response which arrive from the web server. I really only need the value for which I am seeding the GET request in the first place but instead my ESP 8266 is filling up its incoming array with headers and only at the end I see the value of interest.

For example here is what the API at Thingspeak responds with to a GET request:

Code: Select allOST data to URL: /apps/thinghttp/send_request?api_key=LKGQ123123123121
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Status: 200 OK
X-Frame-Options: ALLOWALL
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE, PATCH
Access-Control-Allow-Headers: origin, content-type, X-Requested-With
Access-Control-Max-Age: 1800
ETag: "f7635f54b0bd41fb88a1bf6d98af3c5f"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 32432325324-10aa-42e6-12312141323412312
X-Runtime: 0.267168
X-Powered-By: Phusion Passenger 4.0.57
Date: Mon, 16 Nov 2015 00:59:48 GMT
Server: nginx/1.9.3 + Phusion


The value I am looking for follows once the header mess is sent back to the client (my esp 8266).

If I have to dig into string search business so be it but somehow I was hoping there is a way to suppress the headers in Thinkspeak's response?

Thanks
User avatar
By torntrousers
#34228 The HTTP headers are separated from the body by two sets of carriage return / line feed's - "\r\n\r\n" so you could read/discard the beginning of the response until you find the \r\n\r\n characters and only then start processing your response value.
User avatar
By bubba198
#34324 Thank you,

Ultimately I ended up figuring out which line of the response contains my stuff (it happens to be line 14 when using ubidots headers=false which reduces but it doesn't eliminate headers) so I only copied line 14 and that works well for me:

Code: Select allint lines_received = 0;
while(client.available()) {
String line = client.readStringUntil('
');
if (lines_received == 14) {
module1640.setDisplayToString(line.substring(1,line.length()));
}
lines_received++;
}