B4R Question ESP32 RTC data storage: store max measurements

peacemaker

Expert
Licensed User
Longtime User
HI, All

Who used RTC for ESP32 ?
Usual task for sensors: measure, store to RTC that it is to be saved if even reboot or re-power up, and next send out all collected from RTC.
It was OK before for ESP8266, but now for ESP32 cannot find well the solution, to store an array or records, i mean, use max area of RTC memory.
EEPROM is bad idea to fastly kill the FLASH cells in a month or year (EEPROM only for settings)...

Any help ?
 

peacemaker

Expert
Licensed User
Longtime User
Some codes to think about:

Base RTC test:
#include <Arduino.h>

static RTC_DATA_ATTR int counter1 = 0;
static RTC_NOINIT_ATTR int counter2 = 0;

void setup() {
Serial.begin(115200);
esp_reset_reason_t reason = esp_reset_reason();
if ((reason != ESP_RST_DEEPSLEEP) && (reason != ESP_RST_SW))
{
  counter2 = 0;
}
Serial.printf("RTC programme running, counter1 = %d; counter2 = %d\n",counter1,counter2);
delay(3000);
counter1++;
counter2++;
esp_restart();
}

void loop() {
  // nothing needed here
}

RTC programme running, counter1 = 0; counter2 = 4 incrementing after each restart automatically, because of ...
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) ....of this king of auto software restart
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
RTC programme running, counter1 = 0; counter2 = 5
ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) AND FOGOT IT at power reset :-(
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
RTC programme running, counter1 = 0; counter2 = 0
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
RTC programme running, counter1 = 0; counter2 = 1
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
RTC programme running, counter1 = 0; counter2 = 2
But how to save forever (power independent)?
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
So, RTC at ESP32 works only if it's constantly powered and not rebooted hardwarely.
This code works, preserves the variable (until power_reboot), but ... no idea how to use without persistent storage:

Module name 'esprtc':
Private Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public LiveCounter As ULong
End Sub


Sub Init
    RunNative("rtccount", Null)
    Log("LiveCounter = " , LiveCounter)
    'testing
    Delay(2000)
    RunNative("esprestart", Null)
End Sub




#if C
static RTC_NOINIT_ATTR ulong counter = 0;

void rtccount(B4R::Object* u) {
esp_reset_reason_t reason = esp_reset_reason();
if ((reason != ESP_RST_DEEPSLEEP) && (reason != ESP_RST_SW))
{
  counter = 0;
}
counter++;
b4r_esprtc::_livecounter = counter;
}

void esprestart(B4R::Object* u) {
esp_restart();
}

#end if

It seems, for the task the NVS partition of ESP32 is interesting...

upd: ooops ! ESP32 does not have ... EEPROM memory, just FLASH one, so i guess, EEPROM lib here can works with NVS and any other partitions :) depending on address
 
Last edited:
Upvote 0
Top