// ESPSSS 002 — what survives deep sleep: RTC_DATA_ATTR, RTC_NOINIT_ATTR and a plain global.
// The sketch goes into deep sleep for 0.5 s three times and prints the counters on every boot.
// RTC_DATA_ATTR vs RTC_NOINIT_ATTR vs ordinary global across deep sleep and reset
#include <esp_sleep.h>
RTC_DATA_ATTR uint32_t rtc_data = 0;
RTC_NOINIT_ATTR uint32_t rtc_noinit;
uint32_t plain = 0;
void setup() {
  Serial.begin(115200);
  delay(1500);
  rtc_data++; rtc_noinit++; plain++;
  Serial.printf("BOOT reset_reason=%d wake_cause=%d  RTC_DATA=%u RTC_NOINIT=%u plain=%u\n",
                esp_reset_reason(), esp_sleep_get_wakeup_cause(), (unsigned)rtc_data, (unsigned)rtc_noinit, (unsigned)plain);
  if (rtc_data >= 4) { Serial.println("=== END ==="); delay(100); while (1) delay(1000); }
  Serial.flush();
  esp_sleep_enable_timer_wakeup(500000);
  esp_deep_sleep_start();
}
void loop() {}
