Reading a txt file from a server

Warning I am a beginner programmer and this is my first real arduino project :) I have uploaded a txt file containing only an epoch time on a server. The idea behind my project is that the time is revived by the arduino as a variable and then manipulated to give a countdown from the time downloaded to the current time.

I have used the following code to retrieve the epoch time

  if (client.connect(server, 80)) {
    // Make a HTTP request:
    client.println("GET /u/9243715/arduino.txt HTTP/1.0") ;

and on the void loop

  if (client.available()) {
    char k =;

the problem is that k holds not only the time but also the server header ,

HTTP/1.1 200 OK
Server: nginx/1.0.14
Date: Sun, 01 Jul 2012 11:22:56 GMT
Content-Type: text/plain; charset=ascii
Connection: close
content-length: 10
x-robots-tag: noindex,nofollow
accept-ranges: bytes
etag: 19n
pragma: public
cache-control: max-age=0


Is there a way to remove the header from the variable or transfer only the time to another variable?

Thank you Yiangos

You must parse the return from the server at the double cr-lf (blank line). That denotes the end of the header.

could you help with some code plz?

The web server code in the IDE examples shows how to read a client request until the blank line. The client puts any POST form data there in a client request to the server.

The server responds with a header separated from the body by a blank line. You can modify that routine to parse the server response. Disregard anything before the blank line.

I've used the below to capture a single line by counting the line feeds from the start of the header to the desired line. There is also a "textfinder" library available that waits for a specific string of characters to be encountered to start capturing (good for RSS and large web pages).

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

thank you guys, I tried something different, I used bildr Getting Data From The Web - Arduino + Ethernet - bildr and added my time between <>

however if i try to display it on my lcd, either by lcd.print(inString);


long k;
k = atol(inString);

The value outputs on serial but not on the lcd. here is my complete code

#include <Ethernet.h>
#include <SPI.h>
#include <LiquidCrystal.h>
byte server[] = { 204,236,227,215 }; //ip Address of the server you will connect to

//The location to go to on the server
//make sure to keep HTTP/1.0 at the end, this is telling it what type of file it is
String location = "/u/9243715/arduino.html HTTP/1.0";
LiquidCrystal lcd(12, 11, 6, 5, 3, 2);
// if need to change the MAC address (Very Rare)
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x14, 0xEC };
long k;
EthernetClient client;

char inString[32]; // string for incoming serial data
int stringPos = 0; // string index counter
boolean startRead = false; // is reading?

void setup(){
 lcd.begin(20, 4);

void loop(){

  String pageValue = connectAndRead(); //connect to the server and read the output

  Serial.println(pageValue); //print out the findings.

  k = atol (inString);
  delay(5000); //wait 5 seconds before connecting again

String connectAndRead(){
  //connect to the server


  //port 80 is typical of a www page
  if (client.connect(server, 80)) {
    client.print("GET ");

    //Connected - Read the page
    return readPage(); //go and read the output

    return "connection failed";


String readPage(){
  //read the page, and capture & return everything between '<' and '>'

  stringPos = 0;
  memset( &inString, 0, 32 ); //clear inString memory


    if (client.available()) {
      char c =;

      if (c == '<' ) { //'<' is our begining character
        startRead = true; //Ready to start reading the part 
      }else if(startRead){

        if(c != '>'){ //'>' is our ending character
          inString[stringPos] = c;
          stringPos ++;
          //got what we need here! We can disconnect now
          startRead = false;
          return inString;




  Serial.println(pageValue); //print out the findings.

So, how do you know which value is which? All you see is two collections of digits appear in the serial monitor.

that was just a debug to be sure that the inString value has been transferred to the k variable my problem now is that neither inString or k is displaying on the lcd even though am sure thay are not empty

What I like to do is:

  Serial.print("pageValue = [");

This way, the value is in delimiters, so I can see where it actually starts and ends, and is preceded by an identifier that defines what variable contains the value. No ambiguity at all.

Can you get ANYTHING to display on the LCD?

if i place in the void setup() lcd.print("helloworld") it displaces but if i place it anywhere in the void loop() it does not

LiquidCrystal lcd(12, 11, 6, 5, 3, 2);

You don't seem to be aware that the ethernet shield uses pins 11, 12, and 13 to communicate with the Arduino. No wonder the LCD doesn't work after you initialize the Ethernet connection.

thank you Paul , clearly I wasn't aware of that, the display works perfectly now :)