-->
Page 2 of 3

Re: can't find preferences.H building against ESP8266/ARDUIN

PostPosted: Sat Feb 13, 2021 2:23 pm
by RaspBerry-Picker
flisterfive wrote:opening "%appdata%\local\arduino15\staging\packages\" and for each error downloading given in the arduino IDE, i downloaded the ZIP file manually, and copy to the above directory, after the fifth zip was copied. all was fine.


Hi flisterfive,

download wich zip from where? From the ESP32-repository?

Found the local folder (linux) but did found the .zip for preferences.h regarding to esp8266 via google...

Code: Select all~/.arduino15/staging/packages# ls
esp32-1.0.4.zip             mkspiffs-0.2.3-arduino-esp32-linux64.tar.gz            x86_64-linux-gnu.mkspiffs-7fefeac.1563313032.tar.gz
esp8266-2.7.4.zip           python3-via-env.tar.gz                                 x86_64-linux-gnu.xtensa-lx106-elf-b40a506.1563313032.tar.gz
esptool-2.6.1-linux.tar.gz  x86_64-linux-gnu.mklittlefs-fe5bb56.1578453304.tar.gz  xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz

Re: can't find preferences.H building against ESP8266/ARDUIN

PostPosted: Tue Mar 09, 2021 3:38 pm
by RIN67630
It is not difficult to perform the same magic with the classical EEPROM library.

You will be using a quick and dirty method called 'type punning' copying the memory block of a structure into an array of chars, saving this array to EEPROM, reading later the array back and copying back the memory block of the array into the same structure to restore the data:

First define your data in a structure:
Code: Select allstruct persistance {      // you may include as many data of any type in that structure
  long  Runtime;
  float Whout ;
  float Ahout ; 
} persistance;

char persistance_punning[sizeof(persistance)];   // char array as a copy of the structure


Code: Select all    // write Persistance to  EEPROM (Adress = 100...)
    memcpy(persistance_punning, &persistance, sizeof(persistance));
    for ( int i = 0; i < sizeof(persistance); ++i ) EEPROM.write ( i + 100,  persistance_punning[i] );


Code: Select all    // read Persistance from EEPROM (Adress = 100...)
    for ( int i = 0; i < sizeof(persistance); ++i ) persistance_punning[i] = EEPROM.read ( i + 100 );
    memcpy(&persistance, persistance_punning, sizeof(persistance));   


enjoy!

Re: can't find preferences.H building against ESP8266/ARDUIN

PostPosted: Wed Mar 10, 2021 12:31 am
by Pablo2048
Hi,
this is very ineffective - just use EEPROM.put and EEPROM.get templates for reading and storing the whole structure. Or (even better) use the memory address with this https://github.com/esp8266/Arduino/blob ... PROM.h#L66 and reinterpret the cast as structure pointer (because we all know, that the EEPROM in the ESP8266 is mirrored in RAM...). Don't forget to EEPROM.commit() changes...

Re: can't find preferences.H building against ESP8266/ARDUIN

PostPosted: Fri Sep 24, 2021 3:56 am
by gmag11
I normally use filesystem (SPIFFS or better LittleFS). I create a structure with all data I need to save and dump to a file.

Code: Select allFile configFile = SPIFFS.open (CONFIG_FILE, "w");
configFile.write ((uint8_t*)&persistent_data, sizeof (persistent_data));
configFile.flush();
configFile.close();


Loading data is similar:
Code: Select allFile configFile = SPIFFS.open (CONFIG_FILE, "r");
configFile.readBytes((uint8_t*)&persistent_data, sizeof (persistent_data));
configFile.close();


This may be run on both ESP32 and ESP8266. Preferences library is cleaner anyway. Would be nice that it was included in ESP8266 core