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

logData() not working after initial call #2

Open
KravitzLab opened this issue Dec 12, 2024 · 3 comments
Open

logData() not working after initial call #2

KravitzLab opened this issue Dec 12, 2024 · 3 comments

Comments

@KravitzLab
Copy link
Member

logData() works in the begin function, creating a new file with Event=Startup.
Subsequent calls to logData() in the script cause it to time out and not write to the file. Added debugging code to the logData() function, confirming that it fails to open the file after the first call.

Also confirmed on the Serial Output that the SD card successfully reinitializes after wakeup:
image

@mattgaidica
Copy link
Collaborator

mattgaidica commented Dec 13, 2024

Do you get any of these print statements at logData? @KravitzLab

void FED4::logData()
{
    greenPix();
    
    Serial.println ("Getting time");
    DateTime now = rtc.now();
    
    Serial.print ("Attempting to open file: ");
    Serial.print (filename);
    File dataFile = SD.open(filename, FILE_WRITE);

    if (dataFile)
    {
    Serial.println (" ... opened");
        // DateTime, Event
        dataFile.printf("%04d-%02d-%02d %02d:%02d:%02d,%s,",
                        now.year(), now.month(), now.day(),
                        now.hour(), now.minute(), now.second(),
                        event.c_str());

        // Counters
        dataFile.printf("%d,%d,%d,%d,%d,",
                        pelletCount, leftCount, rightCount, centerCount, wakeCount);

        // Battery and Environmental
        dataFile.printf("%.2f,%.1f,",
                        getBatteryVoltage(),
                        getTemperature());

        // Memory stats
        dataFile.printf("%d,%d,%d\n",
                        ESP.getFreeHeap(),
                        ESP.getHeapSize(),
                        ESP.getMinFreeHeap());

        dataFile.close();
    }
    
    else {
    Serial.println(" ... Warning: SD file not opened.");
    }
    noPix();
}

@mattgaidica
Copy link
Collaborator

filenames need to be prepended by '/' in ESP32, pushed update

@KravitzLab
Copy link
Member Author

Reopening this as we're still getting "Warning: SD file not opened." We've tried the following two approaches but neither works. I can try more on this over the weekend, it's annoying!

Approach 1:
File dataFile = SD.open(String("/") + filename, FILE_WRITE);

Approach 2:
char fullPath[22];
snprintf(fullPath, sizeof(fullPath), "/%s", filename);
File dataFile = SD.open(fullPath, FILE_WRITE);

Also not sure why this works in the createLogFile function?
image

@KravitzLab KravitzLab reopened this Dec 13, 2024
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

2 participants