Read a text file from server and save the value in a variable

Hi guys!

I have an arduino UNO with a GSM shield and I have already manage to send data from my sensor to my web server.
The problem is that now, I would like to do the opposite procedure. I mean, change a value from the server, send it to a text file (already done), read this number with my Arduino and store it in a variable 'int' or 'long' (here is the problem).

I found the following code for a string, but it doesn't work either when I change the number into a word in my .txt.

Any idea?

Thanks in advanced.

    // libraries
   #include <GSM.h>

   // PIN Number
   #define PINNUMBER ""

   // APN data
   #define GPRS_APN "" // APN del operador de la tarjeta.
   #define GPRS_LOGIN "" // GPRS login. Vacío si no existe.
   #define GPRS_PASSWORD "" // GPRS password. Vacío si no existe.

   // initialize the library instance
   GSMClient client;
   GPRS gprs;
   GSM gsmAccess; 
   
   //Variables Declaration
   char k[30];
   char z = '*';
   int s=0;
   String place;

   // URL, path & port (for example: arduino.cc)

   char server[] = "";
   char path[] = "";
   int port = 80; // port 80 is the default for HTTP


   void setup()
   {
    // initialize serial communications and wait for port to open:
    Serial.begin(9600);
   Serial.println("SMS connected");

    // connection state
    boolean notConnected = true;

    while(notConnected)
      {
         if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
         (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
         notConnected = false;
   
      else {
        Serial.println("Not connected");
             delay(1000);
             }
       }

    Serial.println("GPRS connected...");
    Serial.println(" Connecting to Server ");
   }


   void loop()
   {

    if (client.connect(server, port)){

        client.print("GET /webllenado.txt");
        client.println(" HTTP/1.1");
        client.println("Host: www.ubuwebserver.es");
        client.println("User-Agent: Arduino");
        client.println("Accept: text/html");
        client.println("Connection: close");
        client.println();

        Serial.println("\nCOMPLETE!\n");
        }
        else {
        Serial.println("connection failed");
        }


     while (client.connected()) {
        while(client.available()) {
          char c = client.read();
          //Serial.print(c);
          if (z==c)
          {
             s=1;
          }

          if(s == 1 && c!='*')
          {
             int i=0;
             k[i] = c;
             i=i+1;
            //Serial.print(k);
           }
  
           place +=k;
       }
    }
    Serial.print("place = ");  
    Serial.print(place); 
    client.stop();
  }

Your code

is sloppy as

hell

and
difficult

to follow.

Get rid of the useless blank lines (not all of them; just the useless ones), and use Tools + Auto Format to properly indent your code.

   client.print("GET /webllenado.txt");

The argument to the GET request is the script to execute. I imagine that the server tried to execute that script, with less than stellar results.

PaulS:
Your code

is sloppy as

hell

and
difficult

to follow.

Get rid of the useless blank lines (not all of them; just the useless ones), and use Tools + Auto Format to properly indent your code.

I read your post before reading his and laughed both before and after expanding the code.

jalbo10

How'd you manage to send data from your sensor to your web server using the GSM? Is there any resources you used found most helpful for this ? Did you send the data from the SD or did you just stream it in real-time? I'd like to do both concurrently.

Regards
sjd1