Go Down

Topic: WiShield + HTTP Headers (Read 5896 times) previous topic - next topic


I'm using the WiShield as a client to retrieve data from a webserver and print to the serial port. I am interested in what might be the best way to remove the http headers from the string being printed. Ex. of what is printed to serial:

HTTP/1.1 200 OK
Date: Sun, 30 Jan 2011 01:57:44 GMT
Server: Apache
Last-Modified: Sun, 30 Jan 2011 01:21:55 GMT
ETag: "5d0c-1-1ff372c0"
Accept-Ranges: bytes
Content-Length: 1
Connection: close
Content-Type: text/plain

variable = XxxX

I want to get variable only



The below code does something similar to capture desired data from a very large ocean weather data file. The code counts line feeds in the received file and capture ~line 14 which contains the desired data. From what you posted your data would probably be somewhere near line 11.

Code: [Select]
//zoomkat 12-22-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor to see what the arduino receives
//push the shield reset button to run client again

#include <SPI.h>
#include <Ethernet.h>
String readString, readString1;
int x=0;
char lf=10;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 102 };
byte server[] = { 140, 90, 238, 27 }; // NOAA

Client client(server, 80);

void setup()
  Ethernet.begin(mac, ip);
  Serial.println("starting simple arduino client test");

  if (client.connect()) {
    client.println("GET /data/5day2/44013_5day.txt HTTP/1.0");
  } else {
    Serial.println("connection failed");

void loop()
  if (client.available()) {
    char c = client.read();
    //Serial.print(c);  // uncomment to see raw feed
    if (c==lf) x=(x+1);
    if (x==14) readString += c;
    //readString += c;

  if (!client.connected()) {

    Serial.println("Current data row:" );
    readString1 = (readString.substring(41,43));
    Serial.print("DPD sec: ");


Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


Instead of counting lines, the OP should be looking for a blank
line (i.e. two LF characters back to back).  Parsing of the variable
and value should commence after the second LF.  This is the proper
way to parse the HTTP server's output and will continue to work
should the server output a different number of header lines in the



Rusty, got any example code?

Go Up