Is it possible to list number of logs?

I have a small custom board that has a SAMD21G processor, microSD card and a few sensors that logs results with a timestamp. Right now I can create the log file, log the sensor data, delete the log file view SD card details. Displaying all the log values on the little Oled display is not helpful but I was wondering it it is possible to view the number of logs in the .csv file? I could store the number of logs in flash on the processor but view the number on the sd card inside the .csv file would be nice if possible.

0miker0:
I have a small custom board that has a SAMD21G processor, microSD card and a few sensors that logs results with a timestamp. Right now I can create the log file, log the sensor data, delete the log file view SD card details. Displaying all the log values on the little Oled display is not helpful but I was wondering it it is possible to view the number of logs in the .csv file? I could store the number of logs in flash on the processor but view the number on the sd card inside the .csv file would be nice if possible.

You have a couple of options:

  • Maintain a current count of log entries in a variable.
  • Scan through the log file counting entries.
  • Structure the log file such that each entry is EXACTLY the same length.
    Then just calculate the number of entries = file.fileSize()/recordLength;

If you maintain a count, you will have to initialize the value every boot cycle.

I would recommend not storing a 'count'. I would scan and display the 'current' entry count.

Chuck.

chucktodd:
You have a couple of options:

  • Maintain a current count of log entries in a variable.
  • Scan through the log file counting entries.
  • Structure the log file such that each entry is EXACTLY the same length.
    Then just calculate the number of entries = file.fileSize()/recordLength;

If you maintain a count, you will have to initialize the value every boot cycle.

I would recommend not storing a 'count'. I would scan and display the 'current' entry count.

Chuck.

Can you, please, elaborate a bit more the third option?

I have this sequence where every time a key (iButton) is read, it is stored in the SD card. I keep the count and incrementing it every time the write function is call but, aditionally, I want to implement an option to open the existing file and append data to it but, of course, my counter is reseted to 0 once the log menu is closed. I want to read the last entry in the file and extract that number from it.

Every entry have an exact length. Someting like:

0001,1234,AAAAAA
0002,1234,BBBBBB
0003,1234,CCCCCC
0004,1234,DDDDDD
...
...
and so on...

I was thinking in read the first four values until the ', ' appears and storing it in the indexEntry variable, but I dont know if it is the right way to do it.
I'm quite interested in your opinion.

By the way, English is not my main language, sorry if there is any mistake :blush:

JXplicits:
Can you, please, elaborate a bit more the third option?

I have this sequence where every time a key (iButton) is read, it is stored in the SD card. I keep the count and incrementing it every time the write function is call but, aditionally, I want to implement an option to open the existing file and append data to it but, of course, my counter is reseted to 0 once the log menu is closed. I want to read the last entry in the file and extract that number from it.

Every entry have an exact length. Someting like:

0001,1234,AAAAAA
0002,1234,BBBBBB
0003,1234,CCCCCC
0004,1234,DDDDDD
...
...
and so on...

I was thinking in read the first four values until the ', ' appears and storing it in the indexEntry variable, but I dont know if it is the right way to do it.
I'm quite interested in your opinion.

By the way, English is not my main language, sorry if there is any mistake :blush:

I managed to do it by myself... :grinning:
Literally just one more line of code.
The power of a new day and a rested mind

JXplicits:
I managed to do it by myself... :grinning:
Literally just one more line of code.
The power of a new day and a rested mind

Glad you solved your problem.

I find that the act of stating a problem generally results in discovering the answer.

If you can explain your problem, you are most of the way to a solution.

Chuck.