#include <SDMMCBlockDevice.h>
#include <FATFileSystem.h>
#include <ArduinoJson.h>
#include "WiFi.h"
#include "Arduino.h"
#include "FTPClient_Generic.h"
#include "SdFat.h"
SDMMCBlockDevice blockDevice;
mbed::FATFileSystem fs("fs");
void initializeSD() {
if (!initializedSD) {
int err = fs.mount(&blockDevice);
if (err) {
Serial.println("Not mounted successfully");
while(1);
}
Serial.println("Mounted successfully");
initializedSD = 1;
}
}
// function to open a file and it returns the address of the file that was opened
FILE* JiBandFileManager::openFile(FILE* file, const char* filePath, const char* mode) {
initializeSD();
//SdFile::dateTimeCallback(dateTime);
file = fopen(filePath, mode);
if (file == NULL) {
Serial.println("Error opening file...");
return NULL;
} else {
Serial.println("File opened!");
return file;
}
}
// function to close a file that was opened
void JiBandFileManager::closeFile(FILE* file) {
Serial.println("Closing SD card file...");
closeFile(file);
Serial.println("Closing SD file is complete!!!");
}
//Write data to SD
FILE* JiBandFileManager::writeDatatoSDCard(String strData, FILE* fileFile) {
//convert string data into a pointer to a character
const char* finalString = (char*)((strData).c_str());
//loop through all the characters until the end of file and write the character to SD
for (int i = 0; finalString[i] != '\0'; i++) {
fputc(finalString[i], fileFile);
}
return fileFile;
}
Above is the code I use to write data to the files and the libraries I have included in the program. Could the problem be the libraries I am using or is there something I have omitted or done wrong in my code?
Some of the libraries included above are not used in the code I have uploaded above but are part of the program I am working on.