Last active
June 10, 2020 10:02
-
-
Save DaleGia/8aa39b929cf1537f7281c6649a3b4cb2 to your computer and use it in GitHub Desktop.
ESPFlash: Creating a file with a filename of “/charArrayExample” and store 10 chars in the file with error checking.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Creating a file with a filename of “/charArrayExample” and store | |
10 chars in the file with error checking. | |
*/ | |
char testData[10] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}; | |
ESPFlash<char> charExample("/charArrayExample"); | |
bool success = charExample.setElements(testData, sizeof(testData)); | |
/* The above code replaces the following SPIFFS implementation */ | |
char testData[10] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}; | |
bool success = false; | |
uint32_t bytesWritten = 0; | |
File file; | |
uint32_t elementsSizeInBytes = 0; | |
SPIFFS.begin(); | |
file = SPIFFS.open("/charArrayExample", "w"); | |
if(file) | |
{ | |
elementsSizeInBytes = sizeof(char)*sizeof(testData); | |
bytesWritten = file.write((uint8_t*)testData, elementsSizeInBytes); | |
if(bytesWritten == elementsSizeInBytes) | |
{ | |
success = true; | |
} | |
} | |
file.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment