I am following instructions in part using an SD Card as described here https://randomnerdtutorials.com/esp32-microsd-card-arduino/ on an esp32. Sensor data is written to the card, then it is later opened and the data is sent. Once it is sent, I want to clear the contents. However, if I use SD.remove(“/data.txt”) the data is cleared, but the following error occurs :
[ 27102][E][vfs_api.cpp:104] open(): /sd/data.txt does not exist, no permits for creation
[ 29103][E][vfs_api.cpp:175] remove(): /data.txt does not exists or is directory
How to avoid this from occurring?
I guess I could delete the file altogether and create it again each time the program runs. Seems like there should be a simple way to clear the contents.
Can you try the following snippet? It opens the file, moves the cursor to the beginning of the file, removes all contents, and closes the file. I didn’t test it.
File file = SD.open("data.txt", FILE_WRITE);
Tell me if it works.
The following error occurs :
on_120822TEST.ino:389:30: error: 'class fs::File' has no member named 'truncate'
*** [.pio\build\esp32dev\src\SoilStation_120822TEST.ino.cpp.o] Error 1
As per my initial thoughts, I ended up using SD.remove() [https://arduinogetstarted.com/reference/library/arduino-sd.remove], then creating a new file for each loop.
I’m so sorry for taking so long to get back to you.
For some reason, I didn’t receive a notification from your previous response.
Thanks for sharing that solution.