Go Down

Topic: Reading last value of a csv-file (Read 212 times) previous topic - next topic

Bett123

Hello

I've a project where I want to registrate the operating hours of a pump. I'm using an Arduino Mega  2560 and a data logging shield inclusive the RTC.
I store the total operating hours expressed in unix time on the SD card in a CSV-file. For example:

54354
56742
58842


Now is my question how can I read the last value of the CSV-file in a variable in my program? So that I've a backup from the time when the power is shut-off and that I can count the next time interval up to the total the pump already operates. After a reset it's also possible that the time value will be 0.

-   I was thinking about a while loop, but what will be the condition?
-   The parseInt() function, gave me the first value, but not the last.
 
Opening and write on the file works fine, but I've still problems with the reading.

First, I want to apologize myself if I made mistakes in my English!
Thank you in advance!


Juraj

would it not be enough to store the last value in EEPROM?

Bett123

would it not be enough to store the last value in EEPROM?
Thank you for answering my topic,

Unfortunately it isn't possible, because I want to read and process the data periodic on my computer. That's why I need a SD-card. I also want to log the operating hours of the pump for maybe 10 years or longer and that will be tricky on the EEPROM I think.

Juraj

#3
Mar 19, 2019, 11:38 am Last Edit: Mar 19, 2019, 06:17 pm by Juraj
for processing in computer, log raw data, not calculations

Lucario448

If there's only a value per line, and the file always end with a blank line; then I think this is how:

Code: [Select]
file.seek(file.size() - 2); // Get to the end but avoid the last two characters (line-separator of the blank one)

while (file.peek() != '\n') // Go backwards until we detect the previous line separator
  file.seek(file.position() - 1);

file.read(); // Not yet into the last value, we have to advance just one single character

Go Up