Log when ESP is being reset

I want to log when the ESP is being reset. Initially I was thinking about using a counter or something.
Can someone give some ideas about how to do this or what would be a better approach for this ?

To what purpose ? What information do you want have ? When i had some issues with stability i added a page that would show me how long the ESP had been running using millis(). You could add a counter that increments every time the ESP has been started and save/load this counter to EEPROM, but eventually the cell will stop working.
Ideally you would want to have the reset cause as it is put on the UART, that is really useful information,

if the reset is happening you are unable to retrieve any information except the reset-reason which is send out to the serial port. The reset reason is sendet prior to the very first line of setup. So you can't write code for it.

Writing to EEPROM very often is wearing out the EEPROM after 100.000 writings it is worn out.

You could use a FRAM-module which has 1.000.000.000.000 10^12 writecycles guaranteed.
or keep your ESP (which one ESP32 or ESP8266 ? )connected to a PC always listening on the serial port and logging what is comming in

or printing and logging serial output in a regular manner while the ESP is running and then see what was the last entry because a reset occurred.

best regards Stefan

Simply increment a counter on startup and immediately save that counter to EEPROM.
This will record at least 100.000 resets without issue, as @StefanL38 shows us (and in practice it may be more).

I've a circuit which will reset the esp if the battery (connected to an ADC) is below certain voltage. So I want to log/see when the ESP is being reset.

Count the number of boots and store the count using LittleFileSystem

Hummm. Battery low, reboot, battery low, reboot, battery low, reboot... See an issue there?

Very valid point.

https://www.st.com/en/reset-and-supervisor-ics.html

One of the ESP32's in my weather station does the deep sleep thingie when the battery is too low. The ESP32 detects low bat volts, less then 9 volts and puts itself to deep sleep upon detecting 9 volts or less. Before the ESP32 goes to sleep the ULP is started up, that's the 2nd processor on a ESP32. The ULP will now start up and does the volts detect things. The ULP keeps the main CPU and all the peripherals shut down till volts rise above 10.

Gentlemen, this is about an ESP, they make use of 'flash-EEPROM' which wears out considerably quicker.

How about it logging 'before' it is being reset. Anyway a counter seems appropriate.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.