Hi,
Why the else option is never choosen?
/*
ESP32 eeprom_class example with EEPROM library
This simple example demonstrates using EEPROM library to store different data in
ESP32 Flash memory in a multiple user-defined EEPROM class objects. Created for arduino-esp32 on 25 Dec, 2017
by Elochukwu Ifediora (fedy0)
converted to nvs by lbernstone - 06/22/2019
*/
#include "EEPROM.h"
#include "Preferences.h"
#define uS_TO_S_FACTOR 1000000ULL
// Instantiate eeprom objects with parameter/argument names and sizes
EEPROMClass NAMES("eeprom0", 0x500);
EEPROMClass HEIGHT("eeprom1", 0x200);
EEPROMClass AGE("eeprom2", 0x100);
RTC_DATA_ATTR uint32_t check2 = 0;
uint32_t age = 0; void setup() {
Serial.begin(115200);
Serial.println("Testing EEPROMClass\n");
if (!NAMES.begin(NAMES.length())) {
Serial.println("Failed to initialise NAMES");
Serial.println("Restarting...");
//ESP.restart();
}
if (!HEIGHT.begin(HEIGHT.length())) {
Serial.println("Failed to initialise HEIGHT");
Serial.println("Restarting...");
delay(1000);
ESP.restart();
}
if (!AGE.begin(AGE.length())) {
Serial.println("Failed to initialise AGE");
Serial.println("Restarting...");
delay(1000);
ESP.restart();
}
Serial.println(age);
Serial.println(check2);
AGE.get(0, age);
if (age != 47) {
const char* name = "Teo Swee Ann";
double height = 5.8;
uint32_t age = 47;
check2 += 1;
Serial.print("In check: "); Serial.println(check);
Serial.println("----------------- WRITE -------------------\n");
NAMES.put(0, name);
HEIGHT.put(0, height);
AGE.put(0, 47); // Write: Variables ---> EEPROM stores
Serial.print("name: "); Serial.println(name);
Serial.print("height: "); Serial.println(height);
Serial.print("age: "); Serial.println(age); Serial.println("----------------- CLEAR -------------------\n");
// Clear variables
Serial.printf("name: %s", name);
name = '\0';
Serial.println(name);
height = 0;
age = 0;
Serial.print("name: "); Serial.println(name);
Serial.print("height: "); Serial.println(height);
Serial.print("age: "); Serial.println(age); Serial.println("----------------- READ -------------------\n");
// Read: Variables <--- EEPROM stores NAMES.get(0, name);
HEIGHT.get(0, height);
AGE.get(0, age);
Serial.print("name: "); Serial.println( name);
Serial.print("height: "); Serial.println(height);
Serial.print("age: "); Serial.println(age);
uint32_t age3 = 47;
AGE.put(0, age3);
Serial.println("----------------- Going to sleep.");
delay(1000);
esp_sleep_enable_timer_wakeup(30 * uS_TO_S_FACTOR);
esp_deep_sleep_start();
//ESP.restart();
} else {
Serial.println("In else");
const char rname[24] = {};
NAMES.put(0, rname[0]);
double height2;
HEIGHT.put(0, height2);
uint32_t age2;
AGE.put(0, age2);
Serial.print("name: "); Serial.println( rname);
Serial.print("height: "); Serial.println(height2);
Serial.print("age2: "); Serial.println(age2);
} Serial.println("\n----------------- Done!");
}
void loop() {
delay(0xFFFFFFFF);
}
REgard
JPDaviau
One thing I see is you declaring the age variable twice. Once before setup. Then again inside if(age != 47).
AGE.get(0, age); // 42837455
if(age != 47) // first time age = 0;
age = 47
// AGE.put(0, age2); //AGE = 47
sleep
//second turn
AGE.get(0, age); // should be 47 even after deep sleep.
Age is just a standard variable so after deep sleep will not be what you think it is. Either save it to EEPROM or RTC variable.
Hi,
Does the value in :
EEPROMClass AGE(“eeprom2”, 0x100); will survive a deep sleep? Will it survive a power cut ? This is the answer I am after.
RTC_DATA_ATTR uint32_t age = 0; EEPROMClass NAMES("eeprom0", 0x500); EEPROMClass HEIGHT("eeprom1", 0x200); EEPROMClass AGE("eeprom2", 0x100); void setup() { ...................... AGE.get(0, age); // get the value from eeprom and put it in the variable age if (age != 47) { ........
Where did you get EEPROMClass from? I see EEPROM from Arduino. The only reference I can find is for a Sony Spresence board. What does the documentation say?