Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newer telestore code taking a long time to enumerate SD card with existing DATA directory with 900+ saved files #181

Open
sn3ak opened this issue Apr 12, 2023 · 1 comment

Comments

@sn3ak
Copy link

sn3ak commented Apr 12, 2023

I was using a binary built from the freematics builder from around March of 2022. I was forced to change providers and needed to rebuild for a new apn. I had nothing but problems trying to get a new binary rebuilt, so I switched to the Telelogger ESP-IDF Project Package. 12232022 version.

I've successfully built a working binary, however it sits at SD:61025 MB total, 132 MB used for four plus minutes before moving onto:
File: /DATA/947.CSV

Whereas the original binary processed it pretty much instantly. To confirm it is something with the new binary, I flashed the binary from March 2022 on the device and once again it started recording new data instantly.

If I flash the new binary, and eject the SD Card, or rename the DATA folder to DATA1, the logger starts reporting/recording almost instantly.

@sn3ak
Copy link
Author

sn3ak commented Aug 10, 2024

If you find yourself with this problem and don't wish to delete the files.. Try changing

int FileLogger::getFileID(File& root)
{
    if (root) {
        File file;
        int id = 0;
        while(file = root.openNextFile()) {
            char *p = strrchr(file.name(), '/');
            unsigned int n = atoi(p ? p + 1 : file.name());
            if (n > id) id = n;
        }
        return id + 1;
    } else {
        return 0;
    }
}

in telestore.cpp into this:

int FileLogger::getFileID(File& root)
{
    if (root) {
        int id = 0;
        String filename;
        //Serial.println("Starting to get file IDs");
		
        while (!(filename = root.getNextFileName()).isEmpty()) {
            // Serial.print("Found file: ");
            // Serial.println(filename);
            // Convert String to C-string
            const char* cfilename = filename.c_str();
            
            // Extract file name from path
            char *p = strrchr(const_cast<char*>(cfilename), '/');
            
            // Convert filename to integer, handle if `p` is null
            unsigned int n = atoi(p ? p + 1 : cfilename);
            if (n > id) id = n;
        }
        // Serial.print("Max ID found: ");
        // Serial.println(id); // Print the maximum ID found
		
        return id + 1;
    } else {
        // Serial.println("Root is not valid");
        return 0;
    }
}

In my case, I now have 2500 files in my DATA directory, and it loads it in seconds unlike four to five minutes it used to take for 900 files.

HTH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant