This is almost too simple to post, but hey, someone may be stumped. I am only including a short code snippet, and it WILL matter where this function appears. At least it does in this case as I am using it to store a Preference value in esp32 flash memory. As it is in “setup()” it is only going to run once, so there is no second chance, as there often is in parsing variables in a function that runs in a loop. Without further ado, the code.
void setup() {
Serial.begin(115200);
prefString.begin("macAssignment", false);//for nonvolitile memory process
prefInteger.begin("allMacsSaved", false);
//(another note. if you forget the preference.begin statement you will not always get a compile error , but the mememory function will NOT WORK )
pinMode(26, INPUT_PULLUP); //internal pull-up for calibration pushbutton
factoryReset();
//HERE IS THE FUNCTION CALL >> AFTER << THE preference.begin
// AND IT IS IS >> AFTER << THE SETTING OF THE pinMode the button uses
pinMode(32, INPUT_PULLUP); // for chooseTank switch
pinMode(33, INPUT_PULLUP); // for chooseTank switch
///////////////////////// END OF SETUP() STIPPET
THE FACTORY RESET () FUNCTION (MOST OF THIS IS UNNECESSARY AND IS FOR TESTING AND WILL NOT APPLY TO YOUR NEED. But it allows me to reuse the button that is already wired in for a double use. Once in the code and aother time in setup(). The button needs to be pushed when the board/card is powered up. that's the trick. so the setup() function will read the button ONE TIME ONLY for this purpose.
void factoryReset() {
if (digitalRead(26) == 0) {
blinkLED1();
gotMacs = 0;
prefInteger.putUInt("GetStatus", gotMacs);
Serial.print(" inside factory reset gotMacs = >>>> ");
Serial.println(gotMacs);
delay(5000); // to be able to read the message
Serial.print(" the get saved value > value >>>> ");
Serial.println(prefInteger.getUInt("GetStatus", gotMacs));
delay(5000); // to be able to read the message
}