11 #include <esp_heap_caps.h> 12 #include <esp_system.h> 14 #if ESP_IDF_VERSION_MAJOR >= 4 15 #include <esp32/rom/rtc.h> 29 static const char *
const TAG =
"debug";
31 static uint32_t get_free_heap() {
32 #if defined(USE_ESP8266) 33 return ESP.getFreeHeap();
34 #elif defined(USE_ESP32) 35 return heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
40 #ifndef ESPHOME_LOG_HAS_DEBUG 44 std::string device_info;
45 std::string reset_reason;
46 device_info.reserve(256);
48 ESP_LOGCONFIG(TAG,
"Debug component:");
49 #ifdef USE_TEXT_SENSOR 51 #endif // USE_TEXT_SENSOR 53 LOG_SENSOR(
" ",
"Free space on heap", this->
free_sensor_);
54 LOG_SENSOR(
" ",
"Largest free heap block", this->
block_sensor_);
55 #if defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(2, 5, 2) 57 #endif // defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(2, 5, 2) 60 ESP_LOGD(TAG,
"ESPHome version %s", ESPHOME_VERSION);
61 device_info += ESPHOME_VERSION;
64 ESP_LOGD(TAG,
"Free Heap Size: %u bytes", this->
free_heap_);
67 const char *flash_mode;
68 switch (ESP.getFlashChipMode()) {
83 flash_mode =
"FAST_READ";
86 flash_mode =
"SLOW_READ";
90 flash_mode =
"UNKNOWN";
92 ESP_LOGD(TAG,
"Flash Chip: Size=%ukB Speed=%uMHz Mode=%s",
93 ESP.getFlashChipSize() / 1024,
94 ESP.getFlashChipSpeed() / 1000000, flash_mode);
95 device_info +=
"|Flash: " +
to_string(ESP.getFlashChipSize() / 1024) +
96 "kB Speed:" +
to_string(ESP.getFlashChipSpeed() / 1000000) +
"MHz Mode:";
97 device_info += flash_mode;
101 esp_chip_info_t info;
102 esp_chip_info(&info);
104 switch (info.model) {
111 std::string features;
112 if (info.features & CHIP_FEATURE_EMB_FLASH) {
113 features +=
"EMB_FLASH,";
114 info.features &= ~CHIP_FEATURE_EMB_FLASH;
116 if (info.features & CHIP_FEATURE_WIFI_BGN) {
117 features +=
"WIFI_BGN,";
118 info.features &= ~CHIP_FEATURE_WIFI_BGN;
120 if (info.features & CHIP_FEATURE_BLE) {
122 info.features &= ~CHIP_FEATURE_BLE;
124 if (info.features & CHIP_FEATURE_BT) {
126 info.features &= ~CHIP_FEATURE_BT;
129 features +=
"Other:" +
format_hex(info.features);
130 ESP_LOGD(TAG,
"Chip: Model=%s, Features=%s Cores=%u, Revision=%u", model, features.c_str(), info.cores,
132 device_info +=
"|Chip: ";
133 device_info += model;
134 device_info +=
" Features:";
135 device_info += features;
136 device_info +=
" Cores:" +
to_string(info.cores);
137 device_info +=
" Revision:" +
to_string(info.revision);
139 ESP_LOGD(TAG,
"ESP-IDF Version: %s", esp_get_idf_version());
140 device_info +=
"|ESP-IDF: ";
141 device_info += esp_get_idf_version();
144 ESP_LOGD(TAG,
"EFuse MAC: %s", mac.c_str());
145 device_info +=
"|EFuse MAC: ";
148 switch (rtc_get_reset_reason(0)) {
150 reset_reason =
"Power On Reset";
153 reset_reason =
"Software Reset Digital Core";
156 reset_reason =
"Watch Dog Reset Digital Core";
158 case DEEPSLEEP_RESET:
159 reset_reason =
"Deep Sleep Reset Digital Core";
162 reset_reason =
"SLC Module Reset Digital Core";
164 case TG0WDT_SYS_RESET:
165 reset_reason =
"Timer Group 0 Watch Dog Reset Digital Core";
167 case TG1WDT_SYS_RESET:
168 reset_reason =
"Timer Group 1 Watch Dog Reset Digital Core";
170 case RTCWDT_SYS_RESET:
171 reset_reason =
"RTC Watch Dog Reset Digital Core";
173 case INTRUSION_RESET:
174 reset_reason =
"Intrusion Reset CPU";
176 case TGWDT_CPU_RESET:
177 reset_reason =
"Timer Group Reset CPU";
180 reset_reason =
"Software Reset CPU";
182 case RTCWDT_CPU_RESET:
183 reset_reason =
"RTC Watch Dog Reset CPU";
186 reset_reason =
"External CPU Reset";
188 case RTCWDT_BROWN_OUT_RESET:
189 reset_reason =
"Voltage Unstable Reset";
191 case RTCWDT_RTC_RESET:
192 reset_reason =
"RTC Watch Dog Reset Digital Core And RTC Module";
195 reset_reason =
"Unknown Reset Reason";
197 ESP_LOGD(TAG,
"Reset Reason: %s", reset_reason.c_str());
198 device_info +=
"|Reset: ";
199 device_info += reset_reason;
201 const char *wakeup_reason;
202 switch (rtc_get_wakeup_cause()) {
204 wakeup_reason =
"No Sleep";
206 case EXT_EVENT0_TRIG:
207 wakeup_reason =
"External Event 0";
209 case EXT_EVENT1_TRIG:
210 wakeup_reason =
"External Event 1";
213 wakeup_reason =
"GPIO";
216 wakeup_reason =
"Wakeup Timer";
219 wakeup_reason =
"SDIO";
222 wakeup_reason =
"MAC";
225 wakeup_reason =
"UART0";
228 wakeup_reason =
"UART1";
231 wakeup_reason =
"Touch";
234 wakeup_reason =
"SAR";
237 wakeup_reason =
"BT";
240 wakeup_reason =
"Unknown";
242 ESP_LOGD(TAG,
"Wakeup Reason: %s", wakeup_reason);
243 device_info +=
"|Wakeup: ";
244 device_info += wakeup_reason;
247 #if defined(USE_ESP8266) && !defined(CLANG_TIDY) 248 ESP_LOGD(TAG,
"Chip ID: 0x%08X", ESP.getChipId());
249 ESP_LOGD(TAG,
"SDK Version: %s", ESP.getSdkVersion());
250 ESP_LOGD(TAG,
"Core Version: %s", ESP.getCoreVersion().c_str());
251 ESP_LOGD(TAG,
"Boot Version=%u Mode=%u", ESP.getBootVersion(), ESP.getBootMode());
252 ESP_LOGD(TAG,
"CPU Frequency: %u", ESP.getCpuFreqMHz());
253 ESP_LOGD(TAG,
"Flash Chip ID=0x%08X", ESP.getFlashChipId());
254 ESP_LOGD(TAG,
"Reset Reason: %s", ESP.getResetReason().c_str());
255 ESP_LOGD(TAG,
"Reset Info: %s", ESP.getResetInfo().c_str());
257 device_info +=
"|Chip: 0x" +
format_hex(ESP.getChipId());
258 device_info +=
"|SDK: ";
259 device_info += ESP.getSdkVersion();
260 device_info +=
"|Core: ";
261 device_info += ESP.getCoreVersion().c_str();
262 device_info +=
"|Boot: ";
263 device_info +=
to_string(ESP.getBootVersion());
264 device_info +=
"|Mode: " +
to_string(ESP.getBootMode());
265 device_info +=
"|CPU: " +
to_string(ESP.getCpuFreqMHz());
266 device_info +=
"|Flash: 0x" +
format_hex(ESP.getFlashChipId());
267 device_info +=
"|Reset: ";
268 device_info += ESP.getResetReason().c_str();
270 device_info += ESP.getResetInfo().c_str();
272 reset_reason = ESP.getResetReason().c_str();
275 #ifdef USE_TEXT_SENSOR 277 if (device_info.length() > 255)
278 device_info.resize(255);
284 #endif // USE_TEXT_SENSOR 289 uint32_t new_free_heap = get_free_heap();
292 ESP_LOGD(TAG,
"Free Heap Size: %u bytes", this->
free_heap_);
302 this->last_loop_timetag_ = now;
314 #if defined(USE_ESP8266) 317 #elif defined(USE_ESP32) 322 #if defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(2, 5, 2) std::string format_hex(const uint8_t *data, size_t length)
Format the byte array data of length len in lowercased hex.
void status_momentary_warning(const std::string &name, uint32_t length=5000)
text_sensor::TextSensor * device_info_
const float LATE
For components that should be initialized at the very end of the setup process.
void publish_state(const std::string &state)
sensor::Sensor * loop_time_sensor_
float get_setup_priority() const override
uint32_t IRAM_ATTR HOT millis()
sensor::Sensor * fragmentation_sensor_
void dump_config() override
void publish_state(float state)
Publish a new state to the front-end.
text_sensor::TextSensor * reset_reason_
uint32_t last_loop_timetag_
std::string to_string(int value)
sensor::Sensor * free_sensor_
std::string get_mac_address_pretty()
Get the device MAC address as a string, in colon-separated uppercase hex notation.
sensor::Sensor * block_sensor_