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) || defined(USE_ESP32_VARIANT_ESP32S3) 40 case RTC_SW_SYS_RESET:
42 reset_reason =
"Software Reset Digital Core";
44 #if defined(USE_ESP32_VARIANT_ESP32) 46 reset_reason =
"Watch Dog Reset Digital Core";
50 reset_reason =
"Deep Sleep Reset Digital Core";
52 #if defined(USE_ESP32_VARIANT_ESP32) 54 reset_reason =
"SLC Module Reset Digital Core";
57 case TG0WDT_SYS_RESET:
58 reset_reason =
"Timer Group 0 Watch Dog Reset Digital Core";
60 case TG1WDT_SYS_RESET:
61 reset_reason =
"Timer Group 1 Watch Dog Reset Digital Core";
63 case RTCWDT_SYS_RESET:
64 reset_reason =
"RTC Watch Dog Reset Digital Core";
66 #if !defined(USE_ESP32_VARIANT_ESP32C6) && !defined(USE_ESP32_VARIANT_ESP32H2) 68 reset_reason =
"Intrusion Reset CPU";
71 #if defined(USE_ESP32_VARIANT_ESP32) 73 reset_reason =
"Timer Group Reset CPU";
75 #elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 76 case TG0WDT_CPU_RESET:
77 reset_reason =
"Timer Group 0 Reset CPU";
80 #if defined(USE_ESP32_VARIANT_ESP32) 82 #elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 83 case RTC_SW_CPU_RESET:
85 reset_reason =
"Software Reset CPU";
87 case RTCWDT_CPU_RESET:
88 reset_reason =
"RTC Watch Dog Reset CPU";
90 #if defined(USE_ESP32_VARIANT_ESP32) 92 reset_reason =
"External CPU Reset";
95 case RTCWDT_BROWN_OUT_RESET:
96 reset_reason =
"Voltage Unstable Reset";
98 case RTCWDT_RTC_RESET:
99 reset_reason =
"RTC Watch Dog Reset Digital Core And RTC Module";
101 #if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 102 case TG1WDT_CPU_RESET:
103 reset_reason =
"Timer Group 1 Reset CPU";
105 case SUPER_WDT_RESET:
106 reset_reason =
"Super Watchdog Reset Digital Core And RTC Module";
108 case GLITCH_RTC_RESET:
109 reset_reason =
"Glitch Reset Digital Core And RTC Module";
112 reset_reason =
"eFuse Reset Digital Core";
115 #if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S3) 116 case USB_UART_CHIP_RESET:
117 reset_reason =
"USB UART Reset Digital Core";
119 case USB_JTAG_CHIP_RESET:
120 reset_reason =
"USB JTAG Reset Digital Core";
122 case POWER_GLITCH_RESET:
123 reset_reason =
"Power Glitch Reset Digital Core And RTC Module";
127 reset_reason =
"Unknown Reset Reason";
129 ESP_LOGD(TAG,
"Reset Reason: %s", reset_reason.c_str());
136 #if defined(USE_ARDUINO) 137 const char *flash_mode;
138 switch (ESP.getFlashChipMode()) {
152 flash_mode =
"FAST_READ";
155 flash_mode =
"SLOW_READ";
158 flash_mode =
"UNKNOWN";
160 ESP_LOGD(TAG,
"Flash Chip: Size=%ukB Speed=%uMHz Mode=%s",
161 ESP.getFlashChipSize() / 1024,
162 ESP.getFlashChipSpeed() / 1000000, flash_mode);
163 device_info +=
"|Flash: " +
to_string(ESP.getFlashChipSize() / 1024) +
164 "kB Speed:" +
to_string(ESP.getFlashChipSpeed() / 1000000) +
"MHz Mode:";
165 device_info += flash_mode;
168 esp_chip_info_t info;
169 esp_chip_info(&info);
171 #if defined(USE_ESP32_VARIANT_ESP32) 173 #elif defined(USE_ESP32_VARIANT_ESP32C3) 175 #elif defined(USE_ESP32_VARIANT_ESP32C6) 177 #elif defined(USE_ESP32_VARIANT_ESP32S2) 179 #elif defined(USE_ESP32_VARIANT_ESP32S3) 181 #elif defined(USE_ESP32_VARIANT_ESP32H2) 186 std::string features;
187 if (info.features & CHIP_FEATURE_EMB_FLASH) {
188 features +=
"EMB_FLASH,";
189 info.features &= ~CHIP_FEATURE_EMB_FLASH;
191 if (info.features & CHIP_FEATURE_WIFI_BGN) {
192 features +=
"WIFI_BGN,";
193 info.features &= ~CHIP_FEATURE_WIFI_BGN;
195 if (info.features & CHIP_FEATURE_BLE) {
197 info.features &= ~CHIP_FEATURE_BLE;
199 if (info.features & CHIP_FEATURE_BT) {
201 info.features &= ~CHIP_FEATURE_BT;
203 if (info.features & CHIP_FEATURE_EMB_PSRAM) {
204 features +=
"EMB_PSRAM,";
205 info.features &= ~CHIP_FEATURE_EMB_PSRAM;
208 features +=
"Other:" +
format_hex(info.features);
209 ESP_LOGD(TAG,
"Chip: Model=%s, Features=%s Cores=%u, Revision=%u", model, features.c_str(), info.cores,
211 device_info +=
"|Chip: ";
212 device_info += model;
213 device_info +=
" Features:";
214 device_info += features;
215 device_info +=
" Cores:" +
to_string(info.cores);
216 device_info +=
" Revision:" +
to_string(info.revision);
218 ESP_LOGD(TAG,
"ESP-IDF Version: %s", esp_get_idf_version());
219 device_info +=
"|ESP-IDF: ";
220 device_info += esp_get_idf_version();
223 ESP_LOGD(TAG,
"EFuse MAC: %s", mac.c_str());
224 device_info +=
"|EFuse MAC: ";
227 device_info +=
"|Reset: ";
230 const char *wakeup_reason;
231 switch (rtc_get_wakeup_cause()) {
233 wakeup_reason =
"No Sleep";
235 case EXT_EVENT0_TRIG:
236 wakeup_reason =
"External Event 0";
238 case EXT_EVENT1_TRIG:
239 wakeup_reason =
"External Event 1";
242 wakeup_reason =
"GPIO";
245 wakeup_reason =
"Wakeup Timer";
248 wakeup_reason =
"SDIO";
251 wakeup_reason =
"MAC";
254 wakeup_reason =
"UART0";
257 wakeup_reason =
"UART1";
260 wakeup_reason =
"Touch";
263 wakeup_reason =
"SAR";
266 wakeup_reason =
"BT";
269 wakeup_reason =
"Unknown";
271 ESP_LOGD(TAG,
"Wakeup Reason: %s", wakeup_reason);
272 device_info +=
"|Wakeup: ";
273 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_