Reading contents of file from NAS (repeatedly)

Hi,

I'm lost finding a solution to what I try to achieve :

I want to read a temperature value from a file on my 1wire sort of nas station. I can get the value, but i can't trim the leading spaces from it.
I also want to repeat the reading of the whole file, which i can only achieve by resetting the arduino.

Anyone who can guide me into the right direction ?

The code :

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

byte mac[] = { 0xDE, 0xDE, 0xDE, 0xDE, 0xDE, 0x01 };
IPAddress ip(10,10,10,150);

byte server[] = { 10, 10, 10, 9 };

EthernetClient client;

void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);

Serial.println("starting simple arduino client test");
Serial.println();
Serial.println("connecting...");

if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET http://10.10.10.9/temperature");
client.println();
} else {
Serial.println("connection failed");
}

}

void loop()
{

if (client.available()) {
char temp = client.read();
Serial.print(temp);
}

if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
delay(2000);
void (*softReset) (void) = 0; //declare reset function @ address 0
softReset();
}
}

This is the output i get, the leading spaces are in the file, but I want to trim them away, how ??? Any other method to get the looping whithout resetting the arduino ? T

starting simple arduino client test

connecting...
connected
60.0625

disconnecting.
starting simple arduino client test

connecting...
connected
60.0625

disconnecting.

  if (client.available()) {
     char temp = client.read();
     Serial.print(temp);
   }

Read whatever comes in, and print it out. You are making no effort to "trim the white space". Why not? Don't print the character if it is a space, tab, new line, line feed, etc.

I also want to repeat the reading of the whole file, which i can only achieve by resetting the arduino.

Then don't do this crap:

     void (*softReset) (void) = 0; //declare reset function @ address 0
     softReset();
   }

At the moment you only send the request in setup() so the sketch will only make one request. If you want to read the file repeatedly then put the code to submit the request in loop (you could do it at regular intervals, or whenever you have completed processing of the results from the previous request).

Hi,

Just to let all of you know that i've got it working thanks to the tips on my post. Here is the code (it's only basic, printing a few lines based on the value. I'm gonna add some code to control relais) :

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

byte mac[] = { 0xDE, 0xDE, 0xDE, 0xDE, 0xDE, 0x01 };
IPAddress ip(10,10,10,150);

byte server[] = { 10, 10, 10, 9 }; // NOAA

EthernetClient client;

void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);

Serial.println("starting simple arduino client test");
Serial.println();
Serial.println("connecting...");
}

void loop()
{
String temp = "";
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET http://10.10.10.9/temperature");
client.println();
} else {
Serial.println("connection failed");
}

while(client.connected() && !client.available()) delay(1);
while(client.available()) {
char c = client.read();
if (c != ' ') {
Serial.print(c);
temp = temp + c;
}
}
client.stop();
delay(1000);
Serial.print("De temperatuur is : ");
Serial.println(temp);
int getal = temp.toInt();
Serial.print("Getal is : ");
Serial.println(getal);
Serial.println(" ");
Serial.println(" ");
if (getal >=85) {
Serial.println("Getal is groter of gelijk aan 85");
}
else {
Serial.println("Getal is kleiner dan 85");
}
delay(5000);

}

The output is now like this :

connected
89.0625
De temperatuur is : 89.0625

Getal is : 89

Getal is groter of gelijk aan 85

connected
68.0625
De temperatuur is : 68.0625

Getal is : 68

Getal is kleiner dan 85

All this is gonna serve one purpose, cooling my solar boiler over the central heating radiators when the temperature of my boiler is greater than let's say 85 or 90° Celsius. In this case, the solar tubes will never stagnate, which is better for the glycol fluid.

Thanks guys !

Bart

while(client.connected() && !client.available()) delay(1);

Lose the delay(). There is NO reason not to loop a bazillion times waiting.

  String temp = "";

Lose the String. Learn to get the client response properly, using a NULL terminated char array. Learn to use the C string handling functions to parse the string.