Hi,
I have managed to save the boot count (two of them) after a deep sleep on the ESP 32, but I can not save a string and add to the string on each boot.
How can I save a string? My final aim is to read an analog pin on each wakeup, then after 20 wakeups get the max, min, average and median of the 20 readings.
If there is an way to store an array, then please teach me, however out of curiosity I still like to store a string. I am a beginner.
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ #define TIME_TO_SLEEP 3 /* Time ESP32 will go to sleep (in seconds) */ #define LED 2 RTC_DATA_ATTR int bootCount = 0; RTC_DATA_ATTR int bootCount2 = 0; //int bootCount = 0; //int bootCount2 = 0; RTC_DATA_ATTR String RTCvariable = "H"; void setup(){ Serial.begin(115200); delay(500); Serial.println("ESP32 boot RTC test"); if(bootCount == 0) //Run this only the first time { //digitalWrite(YELLOW_LED_PIN,HIGH); delay(500); //Increment boot number and print it every reboot Serial.println("Boot count = 0 , first time boot "); Serial.println("Boot count2 = 0 , first time boot "); }else // not first boot { Serial.println("2nd + boot. Boot number: " + String(bootCount)); Serial.println("2nd + boot2. Boot number: " + String(bootCount2)); } Serial.println("RTCvariable: " + String(RTCvariable)); ++bootCount; ++bootCount2; //RTCvariable.concat("A"); //RTCvariable += "A"; RTCvariable += 'A'; Serial.println("Enter deep sleep for 3 seconds"); esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); esp_deep_sleep_start(); } void loop(){ }
Hi Steven.
Unfortunately, I don’t have a clear answer for you. I don’t know how to store arrays or strings in the RTC memory.
There is a library that does exactly what you want, but it was built for the ESP8266. https://github.com/highno/rtcvars
I think they will add support ESP32 in the future.
At the moment, I think the best option would be storing the temperature values in a position of the flash memory and then compare the temperatures in each position.
You should also need to keep track of the boot count so that you know where yo save each temperature.
You can see our tutorial about storing data on the flash memory here: https://randomnerdtutorials.com/esp32-flash-memory/
I hope this helps.
Regards,
Sara