Author Topic: Going beyond end of the file  (Read 2097 times)

Techno

  • Newbie
  • *
  • Posts: 26
Going beyond end of the file
« on: March 27, 2014, 05:41:50 pm »
Suggestions?



Code: [Select]

            webFile = SD.open("log.txt");

if(webFile){

  while(webFile.available()){ //read till file end is reached
     
for (int i = 0;i < 93;i++){ //read 93 bytes into buffer before sending
buffer[i] = webFile.read();
}
server.write(buffer,93);  //send file to browser
} //end while (webFile.available())
webFile.close();
} //end if (webFile)
else{
Serial.println("File error");
}[code]

Produces the following text in notepad (65KB plus file size:

[code]03/26/2014 , 13:45:00,37.70 %, 66.56  F., 29.33 in. Hg. , 993.09 millibars , 0.98, 565.01 Ft.
03/26/2014 , 14:00:00,37.40 %, 66.38  F., 29.32 in. Hg. , 992.88 millibars , 0.98, 571.04 Ft.
03/26/2014 , 14:15:00,37.50 %, 66.56  F., 29.31 in. Hg. , 992.51 millibars , 0.98, 581.76 Ft.
03/26/2014 , 14:30:00,37.60 %, 66.74  F., 29.31 in. Hg. , 992.44 millibars , 0.98, 583.74 Ft.
03/26/2014 , 14:45:00,37.30 %, 66.74  F., 29.30 in. Hg. , 992.20 millibars , 0.98, 590.75 Ft.
03/26/2014 , 15:00:00,36.90 %, 66.92  F., 29.29 in. Hg. , 991.83 millibars , 0.98, 601.28 Ft.
03/26/2014 , 15:15:00,36.50 %, 66.92  F., 29.28 in. Hg. , 991.63 millibars , 0.98, 607.16 Ft.
03/26/2014 , 15:30:00,36.70 %, 67.28  F., 29.28 in. Hg. , 991.50 millibars , 0.98, 611.03 Ft.
03/26/2014 , 15:45:00,36.80 %, 67.28  F., 29.27 in. Hg. , 991.16 millibars , 0.98, 620.94 Ft.
03/26/2014 , 16:00:00,36.90 %, 67.46  F., 29.26 in. Hg. , 990.78 millibars , 0.98, 632.08 Ft.
��������������������������������������������������������HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 467
Connection: close
Refresh: 30

<!DOCTYPE HTML>
<html>
<h2>Weather Observations</h2><br />Treyburn Lakes<br />Indianapolis, IN 46239<br />Date,Time:  03/26/2014 , 19:28:25 EST<br />Temperature:  67.46 Deg. F.<br />Humidity:  37.00 %<br />Barometric Pressure:  29.23 in. Hg.<br />Barometric Pressure:  989.98 mb.<br />Atmosphere:  0.98 Atm<br />Altitude:  654.46 Feet<br /><br /><br /><h2>Collected Observations</h2><a href='log.txt' download='log.txt' >Download: log.txt</a><br /><br />
</html>

What is the best way to check for end of file?  Is it possible to check for a unused byte "FF"?

HTML code is being appended somehow; it does not matter whether the file is opened or saved.