Define filename at runtime using SdCard Log_HandleR

I am developing a device that, among other functions, saves the data it generates in the mSD, but by default it generates a file with the name “00001”.
Is there a function to define a name at runtime?

@rodrigo_santos, can you give a bit more information like the library you are using, the DeviceOS version and maybe post the code you are using to create a file. It’s hard to help otherwise.

Electron type E, Device OS:1.4.2
Complementarily, is there any way to indicate that the data was successfully saved in the mSD? Because sometimes it gets paused if it can’t save the data. I have noticed that if I remove the 00001.txt file from the mSD and don’t formPreformatted textat it, it doesn’t generate or save the file.

#include <LiquidCrystal_I2C_Spark.h>
#include <SdCardLogHandlerRK.h>
#include <SdFat.h>
#include <Particle.h>
#include "application.h"


float Volumen=0;
float Volumen2=0;
float Velocidad=0;
float Caudal=0;

const int SD_CHIP_SELECT = A2;
SdFat sd;

SdCardLogHandler logHandler(sd, SD_CHIP_SELECT, SPI_FULL_SPEED);

void setup() {
    delay(5000);; //manejar el cambio de horario
    lcd = new LiquidCrystal_I2C(0x27, 16, 2);

void loop() {
int minutoActual = Time.minute();
    if( minutoUltimo != minutoActual ){
        minutoUltimo = minutoActual;
        if(minutoActual == 0){

void escrituraBD(){
    String cadenaRuta =   clave +"/"+ Time.format(, "%Y%m%d%H%M%S") + "/" + Volumen + "/" +  Volumen2 + "/" +  Velocidad + "/" +  String(Caudal);

    Serial.print("Cadena de ruta: ");

    lcd->print("Vol(m3) " + String(Volumen,2));
    lcd->print("Q(L/s) " + String(Caudal,2));

@rodrigo_santos, as per the SdCardLogHandlerRK library README file:

The library creates a directory (default: “logs”) at the top level of the SD card and stores the log files in that. Each log file is a .txt file 6-digit number beginning with 000001.txt.

The default log file is 1 MB (1000000 bytes), but you can reconfigure this. The actual size will be slightly larger than that, as the log is rotated when it exceeds the limit, and the file will always contain a whole log entry.

When rotated, the default is to keep 10 log files, but this is configurable. The oldest is deleted when the maximum number is reached.

So, I would say no, you cannot change the filename unless you modify the library. I also don’t see any way to verify that data was saved successfully to the mSD.

I’m not sure what you mean but the library won’t automatically create a log file unless you try and write a log entry (text) to the mSD.

1 Like

You’d have to modify the library to change the filename. The reason is that the library always uses sequentially numbered files because there is no way to efficiently delete the beginning of a file. Without the ability to delete from the file, it would grow without bounds until it filled the entire card.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.