59: Particle Photon "Persistent Data"
Up till now I have handled the problem of getting data to persist between reboots by sending it daily to-and-from a Linux (Raspberry Pi) system. And I will continue to handle Daylight Savings that way. But now I'm going to try Particle's EEPROM memory storage scheme. The Photon provides 4096 bytes of flash RAM that presumably/seems-to persist between power outages. The hitch is that you have to manage storage space allocation on your own. So if you want to store a C++ int you have to know to offset the next variable by at least 4 bytes (higher number). Reminds me of my first assembly language compiler from 1961.
Here's a sample program.
#define VAR1 0 // first address in eeprom -- 32-bit int
#define VAR2 4 // leaving room for the previous value
int Var1;
int InitialValue = 123; // whatever...
void setup() {
EEPROM.get(VAR1, Var1); // copy from eeprom to RAM data
if(Var1 == -1) { // hex "FF"s first time, not initialized
EEPROM.put(VAR1, InitialValue); // load starting value
...
}
// might also want to check for reasonable "get" value!
}
void loop() {
// use or change eeprom values as needed
}
More/better info at--
https://docs.particle.io/guide/getting-started/intro/photon/
Search for "EEPROM".
No comments:
Post a Comment