5 #include <esp_heap_caps.h> 6 #include <esp_system.h> 7 #include <esp_chip_info.h> 9 #if defined(USE_ESP32_VARIANT_ESP32) 10 #include <esp32/rom/rtc.h> 11 #elif defined(USE_ESP32_VARIANT_ESP32C3) 12 #include <esp32c3/rom/rtc.h> 13 #elif defined(USE_ESP32_VARIANT_ESP32C6) 14 #include <esp32c6/rom/rtc.h> 15 #elif defined(USE_ESP32_VARIANT_ESP32S2) 16 #include <esp32s2/rom/rtc.h> 17 #elif defined(USE_ESP32_VARIANT_ESP32S3) 18 #include <esp32s3/rom/rtc.h> 19 #elif defined(USE_ESP32_VARIANT_ESP32H2) 20 #include <esp32h2/rom/rtc.h> 29 static const char *
const TAG =
"debug";
32 std::string reset_reason;
33 switch (rtc_get_reset_reason(0)) {
35 reset_reason =
"Power On Reset";
37 #if defined(USE_ESP32_VARIANT_ESP32) 39 #elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || \ 40 defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32C6) 41 case RTC_SW_SYS_RESET:
43 reset_reason =
"Software Reset Digital Core";
45 #if defined(USE_ESP32_VARIANT_ESP32) 47 reset_reason =
"Watch Dog Reset Digital Core";
51 reset_reason =
"Deep Sleep Reset Digital Core";
53 #if defined(USE_ESP32_VARIANT_ESP32) 55 reset_reason =
"SLC Module Reset Digital Core";
58 case TG0WDT_SYS_RESET:
59 reset_reason =
"Timer Group 0 Watch Dog Reset Digital Core";
61 case TG1WDT_SYS_RESET:
62 reset_reason =
"Timer Group 1 Watch Dog Reset Digital Core";
64 case RTCWDT_SYS_RESET:
65 reset_reason =
"RTC Watch Dog Reset Digital Core";
67 #if !defined(USE_ESP32_VARIANT_ESP32C6) && !defined(USE_ESP32_VARIANT_ESP32H2) 69 reset_reason =
"Intrusion Reset CPU";
72 #if defined(USE_ESP32_VARIANT_ESP32) 74 reset_reason =
"Timer Group Reset CPU";
76 #elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || \ 77 defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32C6) 78 case TG0WDT_CPU_RESET:
79 reset_reason =
"Timer Group 0 Reset CPU";
82 #if defined(USE_ESP32_VARIANT_ESP32) 84 #elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || \ 85 defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32C6) 86 case RTC_SW_CPU_RESET:
88 reset_reason =
"Software Reset CPU";
90 case RTCWDT_CPU_RESET:
91 reset_reason =
"RTC Watch Dog Reset CPU";
93 #if defined(USE_ESP32_VARIANT_ESP32) 95 reset_reason =
"External CPU Reset";
98 case RTCWDT_BROWN_OUT_RESET:
99 reset_reason =
"Voltage Unstable Reset";
101 case RTCWDT_RTC_RESET:
102 reset_reason =
"RTC Watch Dog Reset Digital Core And RTC Module";
104 #if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) || \ 105 defined(USE_ESP32_VARIANT_ESP32C6) 106 case TG1WDT_CPU_RESET:
107 reset_reason =
"Timer Group 1 Reset CPU";
109 case SUPER_WDT_RESET:
110 reset_reason =
"Super Watchdog Reset Digital Core And RTC Module";
113 reset_reason =
"eFuse Reset Digital Core";
116 #if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 117 case GLITCH_RTC_RESET:
118 reset_reason =
"Glitch Reset Digital Core And RTC Module";
121 #if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32C6) 122 case USB_UART_CHIP_RESET:
123 reset_reason =
"USB UART Reset Digital Core";
125 case USB_JTAG_CHIP_RESET:
126 reset_reason =
"USB JTAG Reset Digital Core";
129 #if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S3) 130 case POWER_GLITCH_RESET:
131 reset_reason =
"Power Glitch Reset Digital Core And RTC Module";
135 reset_reason =
"Unknown Reset Reason";
137 ESP_LOGD(TAG,
"Reset Reason: %s", reset_reason.c_str());
144 #if defined(USE_ARDUINO) 145 const char *flash_mode;
146 switch (ESP.getFlashChipMode()) {
160 flash_mode =
"FAST_READ";
163 flash_mode =
"SLOW_READ";
166 flash_mode =
"UNKNOWN";
168 ESP_LOGD(TAG,
"Flash Chip: Size=%ukB Speed=%uMHz Mode=%s",
169 ESP.getFlashChipSize() / 1024,
170 ESP.getFlashChipSpeed() / 1000000, flash_mode);
171 device_info +=
"|Flash: " +
to_string(ESP.getFlashChipSize() / 1024) +
172 "kB Speed:" +
to_string(ESP.getFlashChipSpeed() / 1000000) +
"MHz Mode:";
173 device_info += flash_mode;
176 esp_chip_info_t info;
177 esp_chip_info(&info);
179 #if defined(USE_ESP32_VARIANT_ESP32) 181 #elif defined(USE_ESP32_VARIANT_ESP32C3) 183 #elif defined(USE_ESP32_VARIANT_ESP32C6) 185 #elif defined(USE_ESP32_VARIANT_ESP32S2) 187 #elif defined(USE_ESP32_VARIANT_ESP32S3) 189 #elif defined(USE_ESP32_VARIANT_ESP32H2) 194 std::string features;
195 if (info.features & CHIP_FEATURE_EMB_FLASH) {
196 features +=
"EMB_FLASH,";
197 info.features &= ~CHIP_FEATURE_EMB_FLASH;
199 if (info.features & CHIP_FEATURE_WIFI_BGN) {
200 features +=
"WIFI_BGN,";
201 info.features &= ~CHIP_FEATURE_WIFI_BGN;
203 if (info.features & CHIP_FEATURE_BLE) {
205 info.features &= ~CHIP_FEATURE_BLE;
207 if (info.features & CHIP_FEATURE_BT) {
209 info.features &= ~CHIP_FEATURE_BT;
211 if (info.features & CHIP_FEATURE_EMB_PSRAM) {
212 features +=
"EMB_PSRAM,";
213 info.features &= ~CHIP_FEATURE_EMB_PSRAM;
216 features +=
"Other:" +
format_hex(info.features);
217 ESP_LOGD(TAG,
"Chip: Model=%s, Features=%s Cores=%u, Revision=%u", model, features.c_str(), info.cores,
219 device_info +=
"|Chip: ";
220 device_info += model;
221 device_info +=
" Features:";
222 device_info += features;
223 device_info +=
" Cores:" +
to_string(info.cores);
224 device_info +=
" Revision:" +
to_string(info.revision);
226 ESP_LOGD(TAG,
"ESP-IDF Version: %s", esp_get_idf_version());
227 device_info +=
"|ESP-IDF: ";
228 device_info += esp_get_idf_version();
231 ESP_LOGD(TAG,
"EFuse MAC: %s", mac.c_str());
232 device_info +=
"|EFuse MAC: ";
235 device_info +=
"|Reset: ";
238 const char *wakeup_reason;
239 switch (rtc_get_wakeup_cause()) {
241 wakeup_reason =
"No Sleep";
243 case EXT_EVENT0_TRIG:
244 wakeup_reason =
"External Event 0";
246 case EXT_EVENT1_TRIG:
247 wakeup_reason =
"External Event 1";
250 wakeup_reason =
"GPIO";
253 wakeup_reason =
"Wakeup Timer";
256 wakeup_reason =
"SDIO";
259 wakeup_reason =
"MAC";
262 wakeup_reason =
"UART0";
265 wakeup_reason =
"UART1";
268 wakeup_reason =
"Touch";
271 wakeup_reason =
"SAR";
274 wakeup_reason =
"BT";
277 wakeup_reason =
"Unknown";
279 ESP_LOGD(TAG,
"Wakeup Reason: %s", wakeup_reason);
280 device_info +=
"|Wakeup: ";
281 device_info += wakeup_reason;
std::string format_hex(const uint8_t *data, size_t length)
Format the byte array data of length len in lowercased hex.
void get_device_info_(std::string &device_info)
sensor::Sensor * psram_sensor_
void publish_state(float state)
Publish a new state to the front-end.
uint32_t get_free_heap_()
std::string to_string(int value)
std::string get_reset_reason_()
Implementation of SPI Controller mode.
std::string get_mac_address_pretty()
Get the device MAC address as a string, in colon-separated uppercase hex notation.
sensor::Sensor * block_sensor_