ESP32 reset due to task watchdog every 20min

Hello All,

I have an issue with ESP 32 devkit v1, it is rebooting every 20 minutes with an almost bare bone sketch. Tested on 2 boards with the same results.
The board is not connected to anything and it is powered from usb charger. Before writing this to the board, I had a sketch from arduino and didn’t reboot.

esphome:
  name: bme680-esp32
  friendly_name: bme680_esp32
  compile_process_limit: 1

esp32:
  board: esp32doit-devkit-v1
  framework:
    type: arduino

# Enable logging
logger:
  level: DEBUG

debug:
  update_interval: 500ms

ota:
  - platform: esphome
    password: [redacted]

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

captive_portal:

mqtt:
  broker: "192.168.50.1"
  username: !secret mqtt_user
  password: !secret mqtt_password
  topic_prefix: "bme680_32-sensor"  
  discovery: true
  discovery_prefix: homeassistant
  port: 1883 
  keepalive: 120s

sensor:
  ###### DEBUG #######
  - platform: debug
    free:
      name: "Heap Free"
    block:
      name: "Heap Max Block"
    loop_time:
      name: "Loop Time"
 
  - platform: uptime
    name: "ESP Uptime"
    unit_of_measurement: min
    update_interval: 10s
    accuracy_decimals: 0
    filters: 
      - lambda: |-
          return x / 60.0;

text_sensor:
  ######## DEBUG ##########
  - platform: debug
    reset_reason:
      name: "Last Reset Reason"

Any idea why would reboot every 20 minutes constantly?

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  reboot_timeout: 0s

Try this
or just keep it much simpler

esphome:
  name: bme680-esp32
  friendly_name: bme680_esp32
 

esp32:
  board: esp32doit-devkit-v1
  framework:
    type: arduino

# Enable logging
logger:
  level: DEBUG


ota:
  - platform: esphome
    password: [redacted]

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  reboot_timeout: 0s
captive_portal:

mqtt:
  broker: "192.168.50.1"
  username: !secret mqtt_user
  password: !secret mqtt_password
  topic_prefix: "bme680_32-sensor"  
  discovery: true
  discovery_prefix: homeassistant
  port: 1883 
  

sensor:
 
  - platform: uptime
    name: "ESP Uptime"
    type: seconds
    update_interval: 10s


I will let it over night to see how it’s behaving

Your esphome logs don’t offer any hint?

I’ve had 2 boards with framework arduino and esp-idf for 8+ hours, the esp-idf din’t restarted but the arduino one restarted 3 times. The behavior for the arduino framework version is: it stays on for was 2h 24-38min after that the mqtt stops ~15min and board reboots.
I don’t have any logs because the board was not connected to the pc and on mqtt didn’t receive anything

MQTT client has default reboot_timeout of 15min for missing connection.
While IDF didn’t cause reboot, id you have any hiccups with MQTT?

I don’t think so but I don’t have history of the values for the IDF version as HA doesn’t recognize it as a device (even it’s receiving the mqtt messages from the esp with different topic).
I’ve changed the board to the generic one, as someone from a local group has an identical board and he doesn’t has any issues with it. Forgot to mention that the board is not original DOIT, it’s a clone.
I don’t have a final resolution but it seams that if the code gets more complex the reboots get more often. Now on an other board that was rebooting every 30min is now on for 87min.

You can put another reboot timeout under Mqtt. That’ll stop the reboot but not the underlying cause for it.

reboot_timeout: 0s

You could also set a static IP and a fast connect for the wifi

I do not think it is MQTT, but instead the WiFi module.
If I recall correctly, then it has a 5 minutes retry session for connecting, then the fallback AP and captive portal kicks in for 15 minutes and then it reboots.

I’ve added all the functionality that I need to the board (BME sensor still disconnected) and I was following mqtt debug logs for a reboot.
This is the reboot logs:
[17:57:06][I][waveshare_epaper:473]: Wake up the display
[17:57:06][I][waveshare_epaper:646]: Set the display back to deep sleep
[17:57:07][W][component:239]: Component display took a long time for an operation (724 ms).
[17:57:07][W][component:240]: Components should block for at most 30 ms.
[17:57:28][W][component:172]: Component mqtt cleared Warning flag
[17:57:28][I][mqtt:291]: MQTT Connected!
[17:57:28][I][app:062]: setup() finished successfully!
[17:57:28][I][app:100]: ESPHome version 2025.4.2 compiled on May 15 2025, 17:00:02
[17:57:28][C][wifi:600]: WiFi:
Followed by the rest of the initialization logs

Any idea on how to investigate this?

I have reboot_timeout: 0s for wifi and mqtt

esp32:
  board: esp32dev
  framework:
    type: arduino

Log provided does not match the YAML provided.

Start with the MOST minimal config provided and connect it to a computer that is set to stay on, so you have the serial log. That will probably not show the issue, so you can know that your board is okay or not. Then you can change ONE thing at a time until it fails and you will know what caused the issue.

I made another test with minimal config

esphome:
  name: bme680-esp32
  friendly_name: bme680_esp32
  compile_process_limit: 1

esp32:
  board: esp32dev
  framework:
    type: arduino

logger:
  level: DEBUG

ota:
  - platform: esphome
    password: "redacted"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  reboot_timeout: 0s


captive_portal:

mqtt:
  broker: "192.168.50.1"
  username: !secret mqtt_user
  password: !secret mqtt_password
  topic_prefix: "bme680_32-sensor"  
  discovery: true
  discovery_prefix: homeassistant
  port: 1883 
  reboot_timeout: 0s

sensor:
  - platform: uptime
    name: "ESP Uptime"
    unit_of_measurement: min
    update_interval: 10s
    accuracy_decimals: 0
    filters: 
      - lambda: |-
          return x / 60.0;

And after some time i got this in serial logs:

[18:56:03][D][sensor:094]: 'ESP Uptime': Sending state 89.85098 min with 0 decimals of accuracy
[18:56:13][D][sensor:094]: 'ESP Uptime': Sending state 90.01768 min with 0 decimals of accuracy
[18:56:21][D][esp-idf:000][mqtt_task]: E (5413607) MQTT_CLIENT: No PING_RESP, disconnected
[18:56:21]
[18:56:21][W][mqtt:340]: MQTT Disconnected: TCP disconnected.
[18:56:21][W][component:157]: Component mqtt set Warning flag: unspecified
[18:56:21][I][mqtt:250]: Connecting to MQTT...
[18:56:23][D][sensor:094]: 'ESP Uptime': Sending state 90.18435 min with 0 decimals of accuracy
[18:56:33][D][sensor:094]: 'ESP Uptime': Sending state 90.35102 min with 0 decimals of accuracy
[18:56:43][D][sensor:094]: 'ESP Uptime': Sending state 90.51768 min with 0 decimals of accuracy
[18:56:46][D][esp-idf:000][mqtt_task]: E (5438619) esp-tls: [sock=49] select() timeout
[18:56:46]
[18:56:46][D][esp-idf:000][mqtt_task]: E (5438621) TRANSPORT_BASE: Failed to open a new connection: 32774
[18:56:46]
[18:56:46][D][esp-idf:000][mqtt_task]: E (5438631) MQTT_CLIENT: Error transport connect
[18:56:46]
[18:56:46][E][mqtt.idf:162]: MQTT_EVENT_ERROR
[18:56:46][E][mqtt.idf:164]: Last error code reported from esp-tls: 0x8006
[18:56:46][E][mqtt.idf:165]: Last tls stack error number: 0x0
[18:56:46][E][mqtt.idf:167]: Last captured errno : 0 (Success)
[18:56:46][W][mqtt:340]: MQTT Disconnected: TCP disconnected.
[18:56:46][I][mqtt:250]: Connecting to MQTT...
[18:56:53][D][sensor:094]: 'ESP Uptime': Sending state 90.68435 min with 0 decimals of accuracy
[18:57:03][D][sensor:094]: 'ESP Uptime': Sending state 90.85102 min with 0 decimals of accuracy
[18:57:11][D][esp-idf:000][mqtt_task]: E (5463649) esp-tls: [sock=49] select() timeout
[18:57:11]
[18:57:11][D][esp-idf:000][mqtt_task]: E (5463651) TRANSPORT_BASE: Failed to open a new connection: 32774

It kept the loop to try connecting until here:

[20:36:28][I][mqtt:250]: Connecting to MQTT...
[20:36:33][D][sensor:094]: 'ESP Uptime': Sending state 190.35596 min with 0 decimals of accuracy
[20:36:43][D][sensor:094]: 'ESP Uptime': Sending state 190.52263 min with 0 decimals of accuracy
[20:36:53][D][esp-idf:000][mqtt_task]: E (11445611) esp-tls: [sock=49] select() timeout
[20:36:53]
[20:36:53][D][esp-idf:000][mqtt_task]: E (11445613) TRANSPORT_BASE: Failed to open a new connection: 32774
[20:36:53]
[20:36:53][D][esp-idf:000][mqtt_task]: E (11445623) MQTT_CLIENT: Error transport connect
[20:36:53]
[20:36:53][E][mqtt.idf:162]: MQTT_EVENT_ERROR
[20:36:53][E][mqtt.idf:164]: Last error code reported from esp-tls: 0x8006
[20:36:53][E][mqtt.idf:165]: Last tls stack error number: 0x0
[20:36:53][E][mqtt.idf:167]: Last captured errno : 0 (Success)
[20:36:53][W][mqtt:340]: MQTT Disconnected: TCP disconnected.
[20:36:53][I][mqtt:250]: Connecting to MQTT...
[20:36:53][D][sensor:094]: 'ESP Uptime': Sending state 190.68929 min with 0 decimals of accuracy
[20:37:03][D][sensor:094]: 'ESP Uptime': Sending state 190.85596 min with 0 decimals of accuracy
[20:37:13][D][sensor:094]: 'ESP Uptime': Sending state 191.02263 min with 0 decimals of accuracy
[20:37:17][W][component:172]: Component mqtt cleared Warning flag
[20:37:17][I][mqtt:291]: MQTT Connected!
[20:37:17][W][component:239]: Component mqtt took a long time for an operation (114 ms).
[20:37:17][W][component:240]: Components should block for at most 30 ms.
[20:37:23][D][sensor:094]: 'ESP Uptime': Sending state 191.18929 min with 0 decimals of accuracy
[20:37:33][D][sensor:094]: 'ESP Uptime': Sending state 191.35597 min with 0 decimals of accuracy
[20:37:43][D][sensor:094]: 'ESP Uptime': Sending state 191.52264 min with 0 decimals of accuracy

After first boot it worked for ~93min then it was in error for ~101 min, it recovered and worked for 89 min, after was in error for ~104min. The error was always the same.

Your log and YAML don’t appear to match up correctly. YAML says you are using Arduino framework. Log has things that imply it is using IDF framework.

Log does indicate you have a flakey connection to MQTT. This could be caused by either side or anything in-between.

This is a classic case of failure to communicate. You will need to do basic communication troubleshooting to resolve this.

Sorry for that I had the impression that I’ve flashed the file and yes I’ve used the same structure with IDF framework before.
I will try it again with arduino framework.
Thank you for the support so far.
So my setup is like this, HA is running on a PI 4 and is also creating the wifi network,on wlan0, that the esp connects to. Both devices are on my desk so poor connection is excluded.
Do this E (5413607) MQTT_CLIENT: No PING_RESP, disconnected means that the ESP is not receiving a response form HA? I’m trying to narrow the debug to one device ESP or HA.

That is not necessarily true. Poor connection does not equal ONLY low signal strength. That frequently is the cause of a poor connection, but not the only cause of one.

The error message is saying “I can’t communicate”. That can be for a variety of reasons. You have a more complicated network setup than “normal”. Is there a reason for it? Don’t you have a reliable wireless network you can use. Your current setup looks like it needs routing to work, which can be complicated to get set up correctly.

Since things are not working reliably, I would go for an even more basic configuration (of network and everything) and once that is working add the complexity you need back one step at a time.