// the setup function runs once when you press reset or power the board
void setup() {
my_flash_store.write(network);
networkRead = my_flash_store.read();
}
// the loop function runs over and over again until power down or reset
void loop() {
}
Using the debugger in Visual Studio the value of networkRead becomes bcdef rather than abcdef. The IDE underlines FlashStorage in the third line. The accompanying comment is "Function definition for FlashStorage not found." Yet the program runs. When I run the examples that are part of the FlashStorage.h package the IDE does not flag FlashStorage as being a problem.
Does FlashStorage actually supports classes ? I'm not sure (seen it with basic types or struct, something a sizeof() would fairly capture the number of bytes needed to represent the data and not just a pointer to memory. An object would need to be serialized to be saved properly)
Try using a char array of fixed width (the String class is not of great use anyway)
// the setup function runs once when you press reset or power the board
void setup() {
my_flash_store.write(network);
networkRead = my_flash_store.read();
}
// the loop function runs over and over again until power down or reset
void loop() {
}
The program will not compile in this form. It flags an error at the "networkRead = my_flash_store.read();" statement. It says that networkRead must be modifiable l value.
I will try setting something up with a structure. One of the examples for FlashStorage does use a structure.
I am able to write and read single integers to flash memory but I am unable to write and read to flash strings or structures with strings in them. The only way I see to go is to store the string that I want to save one character at a time.
There are EEPROM.write and EEPROM.read functions that are available if FlashAsEEPROM.h is used. These functions allow one character to be written or read at a time with the location of the write or read determined with an index integer that starts at zero. This will make what I want to do very easy so I have a good path going forward.
#include <FlashStorage.h>
// Create a structure that is big enough to contain a name
// and a surname. The "valid" variable is set to "true" once
// the structure is filled with actual data for the first time.
typedef struct {
boolean valid;
char name[100];
char surname[100];
} Person;
// Reserve a portion of flash memory to store a "Person" and
// call it "person_flash_store".
FlashStorage(person_flash_store, Person);
You are right about networkRead = my_flash_store.read();
not working. I did take a look at the example you sighted. That is definitely a way to go but I settled on the FlashAsEEPROM approach. I did not have to get involved with setting up a structure with that approach. Thanks for the help!