Skip to content

Instantly share code, notes, and snippets.

@DaleGia
Last active June 10, 2020 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaleGia/4703dcc222683f67c3aa604b5f331fa9 to your computer and use it in GitHub Desktop.
Save DaleGia/4703dcc222683f67c3aa604b5f331fa9 to your computer and use it in GitHub Desktop.
ESPFlash: Creating a file with a filename of “/intExample” and storing a single integer in the file with error checking.
/* Creating a file with a filename of “/intExample” and storing a
single integer in the file with error checking. */
int testData = 10;
ESPFlash<int> intExample("/intExample")
bool success = intExample.set(10);
/* The above code replaces the following SPIFFS implementation */
int testData = 10;
bool success = false;
uint32_t bytesWritten = 0;
File file;
SPIFFS.begin();
file = SPIFFS.open("/intExample", "w");
if(file)
{
int* testPointer = &testData;
bytesWritten = file.write((uint8_t*)testPointer, sizeof(testData));
if(bytesWritten == sizeof(int))
{
success = true;
}
}
file.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment