Hi there,
Ah’ I see that now, I stopped comprehending after “does not store variable” Snap!
low hanging fruit first
I have sleep code w/ wake button included in the Grove Expansion Flash Upgrade Demo on here. One is for Nrf52840 and the other is for Xiao ESP32C3 with that boot count code working, I don’t recall same issues, it’s battery and USB, works both ways.
May be off your mark slightly but good info just the same.
HTH
GL PJ
swing and a miss,
I found this one , It’s the preferences LIB, Works and saved across resets.