Skip to content

Instantly share code, notes, and snippets.

@zenmanenergy
Last active May 1, 2017 17:53
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 zenmanenergy/8dba0f792370f39316f72d559e366af6 to your computer and use it in GitHub Desktop.
Save zenmanenergy/8dba0f792370f39316f72d559e366af6 to your computer and use it in GitHub Desktop.
updated to simplified C structs.
#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:
}
@zenmanenergy
Copy link
Author

This now works when I remove the String datatypes. What I've learned is that this technique only works with simple data structures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment