How to read file from internet to assign value for variable?

Hello. I having a problem about Arduino and Ethernet Shield and I haven't found any way to solve this problem yet. I hope you will help me. My problem:

I have Arduino Uno R3, Module Ethernet Shield. My device was connected with the Internet. I have a variable: "int limit;" and I have text file: Main.txt (link: I want to read file Main.txt and assign the value of Main.txt for "limit" variable. But I cannot do anything. Can you help me please? I need your answer as soon as possible. Thank you very much./. :-[ :-[ :-[ :-[ :confused:

Hi, welcome to the forum.

You need an Ethernet Client and read the file from the server with a "GET". Convert the contents of the file to a number with client.parseInt() or atoi() with a buffer.

Start here :

Your "server" can be an IP number or a name. For you it is "". The "GET" would be like this : "GET /LinkPhanMem/PiKing/Main.txt HTTP/1.0".

The example is confusing, because the request is done in setup() and reading the file is done in the loop(). You better make a single function that reads the file and returns a number. There are better examples, but I can't find one right now.

Thank you, but, can you guide me more concretely please? :'( :'(

I have read about HttpClient in

Can I use it for Arduino Uno R3 and Ethernet Sheild?

Some simple client test code I modified to get the content of your Main.txt file and capture it in the readString variable.

//zoomkat 11-04-13
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test client GET
//for use with W5100 based ethernet shields
//remove SD card if inserted
//data from myIP server captured in readString 

#include <SPI.h>
#include <Ethernet.h>
String readString;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

char serverName[] = ""; // myIP server test web page server
EthernetClient client;


void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:

  Serial.println("client readString test 11/04/13"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
    byte inChar; // sets inChar as a byte
    inChar =; //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
      sendGET(); // call sendGET function below when byte is an e


void sendGET() //client function to send/receive GET request data.
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    client.println("GET /LinkPhanMem/PiKing/Main.txt HTTP/1.1"); //download text
    client.println("Connection: close");  //close 1.1 persistent connection  
    client.println(); //end of get request
  else {
    Serial.println("connection failed"); //error message if no client connect

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c =; //gets byte from ethernet buffer
    readString += c; //places captured byte in readString

  client.stop(); //stop client
  Serial.println("client disconnected.");
  Serial.println("Data from server captured in readString:");
  Serial.print(readString); //prints readString to serial monitor 
  Serial.println("End of readString");
  readString=""; //clear readString variable