Read specific segment from HTML data.

Hi everyone, :slight_smile:

I want to make test project about Wi-Fi renewable temperature monitor using ESP8266 and ThingSpeak. I am getting this HTML output:

+IPD,0,567:HTTP/1.1 200 OK
Server: nginx/1.7.5
Date: Fri, 12 Jun 2015 10:53:38 GMT
Content-Type: text/html; charset=utf-8
Connection: close
Vary: Accept-Encoding
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: "ef29f3bacdabaabe30452bb095c3b899"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 293a3ef1-ccb6-4aa9-9d07-bd698803073e

29°

...and here I need to get temp value, now it's 29. It may be 0, -10... So, can someone help me??

Thanks for all :))))

Best regards,
DADA

Hi DADA

Do you have control over the format of the data being sent? Could you add a prefix to the temperature so that the last line becomes, for example:

temp=29<span> ...

If so, and if you have the data in a C string (e.g. char buffer[MAX_STR_LEN]), you could use the functions strstr() and atoi() to find the "temp=" tag, move past it and convert the temperature string to an integer.

Do you have any code written so far to receive this HTML? If so, please post it.

Regards

Ray

Yeah, without some sort of prefix, it'll be really hard to search for that temperature value.

Hi, :))

Thanks for fast reply...

First off all I doesn't have control to this data format. I am using ESP8266 module as I said and I am sending very simple AT commands to receive this data...

AT+CIPMUX=1

AT+CIPSTART=0,"TCP","IPADDRESS",PORT

AT+CIPSEND=0,96

and then> GET "WebsiteAddress" HTTP/1.0

after that I get this data... I can't add prefix or suffix around temp value, but is there another way to read it???

Another thing. This data contains every time 567 characters. When temp is e.g. 5, it contains 566 characters or if temp is e.g -20, it contains 568 characters.

Can we read temp value with character number??

Please help :wink:

Best regards,
DADA

Daduka:
ThingSpeak. I am getting this HTML output:

That is a HTTP response you get after sending a HTTP request.
And a HTTP response consists of

  • HTTP header lines (multiple lines)
  • one empty line (which signals the end of the HTTP header)
  • contents of what you requested (the contents transmitted by HTTP protocol)

So it's clear what you have to do:

  • skip header lines until the first empty line
  • read the contents following the empty line

If you want to be 'fail safe' then also check for "200 OK" in the first header line of the response code. It's the server status code of what will follow, and only if the status code is "200 OK" you will get what you have requested.

Hi again :slight_smile:

  • skip header lines until the first empty line
  • read the contents following the empty line

Can you please type for me code for that? I am trying to write something but no luck... Please help me :slight_smile: I am beginner in ARDUINO programming and your help will give me good experience :wink:

Thanks for all :smiley:

Best regards,
DADA

Daduka:
Can you please type for me code for that? I am trying to write something but no luck... Please help me :slight_smile: I am beginner in ARDUINO programming and your help will give me good experience :wink:

If you would consider posting the working code so far, then I might consider writing some additional code for that existing sketch to read out the data from the "+IPD" response code.

But I won't write a completely new sketch for you.

You might look at the below textfinder application. In the past I've counted line feeds in the header to get to the line to be captured.

http://playground.arduino.cc/Code/TextFinder