Flashee-eeprom storage of long int


I wish to use the eeprom to store some long int may I ask for help with this everything I have found is for strings. I tried the documentation but could not find examples for anything but string.

Many thanks in advance.

Best regards,

I’m just giving an obvious answer based on [doumentation][1 related to eeprom, it is an emulated eeprom where you can write or rad in terms of bytes. You need to treat long as a sequence of 4 bytes and use the following function

write(address, value)

You need to extract the bytes from the long variable you want to store one by one and store in the required address using the call above, Since long is 4 bytes, you need to call the above function four times, each time incrementing the address.

It is not obvious to me from the documentation of eeprom write if there are better ways. I will be glad to know.

This week I will add functions that allow you to store arbitrary data types without first having to encode them as bytes, similar to how EEPROM.get/put work on the Photon.

While waiting on @mdma’s update (who I’m not sure sleeps between working on the general firmware and his other projects :wink:), you can always use something like this:

long value = 10;
flash->write(&value, 100, sizeof(value));
flash->read(&value, 100, sizeof(value));

or helper functions

void writeFlash(void* _data, flash_addr_t _address) {
    flash->write(&_data, _address, sizeof(_data));

void readFlash(void* _data, flash_addr_t _address) {
    flash->read(&_data, _address, sizeof(_data));

which then is called like:

double ourDouble;
readFlash(&ourDouble, 10);
writeFlash(&ourDouble, 10);
1 Like

Hi All

Thanks so much for the great input and to @mdma for your offer to update the library. @TheVelozGroup and @mumblepins great help from you two on teaching me how to do this independently.

Best regards