esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 36 forks source link

Large gaps in on_loop calls #5597

Open pzich opened 7 months ago

pzich commented 7 months ago

The problem

Apologies if this is known / answered somewhere, but I couldn't find anything searching around online, the esphome site, or issues here.

I have some displays I'm controlling from an ESP-01S using I2C or SPI (I've been testing both configurations). I was hoping to have some booting/connecting animations and I've noticed that there seems to always be at least one sort of hiccup/gap in on_loop calls during the boot process, with the biggest one usually being about 900ms.

https://github.com/esphome/issues/assets/706138/5a935e06-8fab-41f0-a536-b3cf2a12f993

I suspect this has to do with some time-critical portion of connecting to the wifi, as it seems to happen shortly before ap's on_connected callback gets called.

Is there any way to squeeze at least a few on_loop calls in during that process, assuming whatever on_loop is doing is not too intensive? It's definitely a minor issue, but would make for a much nicer start up experience.

Which version of ESPHome has the issue?

2023.12.5

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2024.2.5

What platform are you using?

ESP8266

Board

ESP-01S

Component causing the issue

ap, i2c

Example YAML snippet

#min.h
unsigned long long last, lastLog, maxGap;

# min.yaml

esphome:
  name: max-gap
  includes:
    - min.h
  on_loop:
      then:
        - lambda: |-
            unsigned long long now = millis();
            if (last == 0) last = now;
            maxGap = max(now - last, maxGap);
            if (now - lastLog > 5000) {
              lastLog = now;
              ESP_LOGI("gap", "max gap: %dms", maxGap);
            }
            last = now;

esp8266:
  board: esp01_1m

logger:

api:
  encryption:
    key: "<your key here>"

ota:
  password: "<ota password>"

wifi:
  ssid: "<ssid>"
  password: "<wifi password>"

Anything in the logs that might be useful for us?

No response

Additional information

No response

ssieb commented 4 months ago

If it was possible, on_loop would be getting called. Something is blocking, quite possibly wifi. If you watch the serial logs, do you see any messages about a component taking too long?