Last active
May 1, 2017 17:53
-
-
Save zenmanenergy/8dba0f792370f39316f72d559e366af6 to your computer and use it in GitHub Desktop.
updated to simplified C structs.
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
#include <FS.h> | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(115200); | |
Serial.println(); | |
Serial.println(); | |
struct Person{ | |
char personId[10]="1234abc"; | |
char firstName[10]="Steve"; | |
char lastName[10]="Nelson"; | |
}; | |
Person me; | |
Serial.println(me.personId); | |
Serial.println(me.firstName); | |
Serial.println(me.lastName); | |
SPIFFS.begin(); | |
File writefile = SPIFFS.open("test","w"); | |
writefile.write((uint8_t *)&me, sizeof(me)); | |
writefile.close(); | |
Serial.println("file written!"); | |
Person oldMe; | |
File readfile = SPIFFS.open("test","w"); | |
readfile.read((uint8_t *)&oldMe, readfile.size()); | |
readfile.close(); | |
Serial.println("file read"); | |
Serial.println(oldMe.personId); | |
Serial.println(oldMe.firstName); | |
Serial.println(oldMe.lastName); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This now works when I remove the String datatypes. What I've learned is that this technique only works with simple data structures.