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();
}