I use FATFS to manage the on board files.
When the GSM unit is not connected it can read and write data without a problem
When the GSM unit is connected it reads but the write does not happen. There are no error codes returned but no data is written.
Here is a simple sketch to illustrate the problem.
- #include <FFat.h>
- void setup() {
- Serial.begin(115200);
- if (!FFat.begin(true)) { //if mount fails filesystem is reformatted (optional, default false)
- Serial.println("Mount failed");
- return;
- }
- Serial.println("File contents before write:");
- File file = FFat.open("/testfile.txt");
- if (!file) {
- Serial.println("read open fail");
- return;
- }
- while(file.available()){
- Serial.write(file.read());
- }
- file.close();
- Serial.println ("write data to file");
- file = FFat.open("/testfile.txt",FILE_APPEND);
- if (!file) {
- Serial.println("error creating file");
- return;
- }
- if (file.print("TEST\r\n")) {
- Serial.println("write ok");
- } else {
- Serial.println("write failed");
- }
- file.close();
- file = FFat.open("/testfile.txt");
- if (!file) {
- Serial.println("read open fail");
- return;
- }
- Serial.println("File contents after write:");
- while(file.available()){
- Serial.write(file.read());
- }
- file.close();
- }
- void loop() {}
10:41:57.651 -> File contents before write:
10:41:57.651 -> TEST
10:41:57.651 -> write data to file
10:41:57.651 -> write ok
10:41:57.745 -> File contents after write:
10:41:57.745 -> TEST
10:41:57.745 -> TEST
And with the GSM module connected I get this:-
10:45:28.210 -> File contents before write:
10:45:28.210 -> TEST
10:45:28.210 -> TEST
10:45:28.210 -> write data to file
10:45:28.210 -> write ok
10:45:28.210 -> File contents after write:
10:45:28.210 -> TEST
10:45:28.210 -> TEST
Note the extra line hasn't been added to the file.
It may be of interest that prior to using FATFS the solution was using LittleFS. The problem there was that when the GSM unit was connected and I attemoted to write to a file I got lots of BAD BLOCK messages. For this reason I switched to FATFS. I no longer get any messages and the app appears tp work ok but as you can see no data is written to the file system.