esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
291 stars 34 forks source link

Random panic (ld2410 + bh1750) #5380

Open fornellas opened 5 months ago

fornellas commented 5 months ago

The problem

The device seems to "randomly" panic, every ~1h or so.

Which version of ESPHome has the issue?

2023.12.5

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

2023.12.2

What platform are you using?

ESP32

Board

ESP32-C3-MINI-1

Component causing the issue

ld2410

Example YAML snippet

esphome:
  name: "presence"
  friendly_name: "Presence"
  name_add_mac_suffix: true
  on_boot:
    - priority: 600.0
      then:
        - lambda: |-
            // Default: Connecting
            id(wifi_led_pwm).set_level(0.5);
            id(wifi_led_pwm).set_period(1000);
            id(wifi_led_pwm).turn_on();
        - script.execute: fast_reboot_factory_reset
        - switch.turn_off: ld2410_bluetooth
        - button.press: ld2410_query_params
  on_loop:
    then:
      - lambda: |-
          // Captive portal
          if(id(wifi_component).has_ap() && !id(wifi_component).has_sta()) {
            id(wifi_led_pwm).set_level(0.5);
            id(wifi_led_pwm).set_period(200);
          } else {
            id(wifi_led_pwm).set_period(1000);
            // Connected
            if(id(wifi_component).is_connected())
              id(wifi_led_pwm).set_level(1);
            // Connecting
            else
              id(wifi_led_pwm).set_level(0.5);
          }

esp32:
  board: esp32-c3-devkitm-1

globals:
  - id: fast_reboot
    type: int
    restore_value: yes
    initial_value: '0'

  - id: factory_reset_reboot_counter
    type: int
    initial_value: '2'

logger:
  baud_rate: 0
  level: info

script:
  - id: fast_reboot_factory_reset
    then:
      - if:
          condition:
            lambda: return ( id(fast_reboot) >= id(factory_reset_reboot_counter) );
          then:
            - lambda: |-
                ESP_LOGI("Fast Boot Factory Reset", "Performing factotry reset");
                id(fast_reboot) = 0;
                fast_reboot->loop();
                global_preferences->sync();
            - button.press: factory_reset_button
      - lambda: |-
          if(id(fast_reboot) > 0)
            ESP_LOGI("Fast Boot Factory Reset", "Quick reboot %d/%d, do it %d more times to factory reset", id(fast_reboot), id(factory_reset_reboot_counter), id(factory_reset_reboot_counter) - id(fast_reboot));
          id(fast_reboot) += 1;
          fast_reboot->loop();
          global_preferences->sync();
      - delay: 10s
      - lambda: |-
          id(fast_reboot) = 0;
          fast_reboot->loop();
          global_preferences->sync();

wifi:
  id: wifi_component
  ap:
    ap_timeout: 0s
  reboot_timeout: 0s

captive_portal:

web_server:

api:
  reboot_timeout: 0s

ota:
  safe_mode: false

prometheus:

debug:
  update_interval: 5s

uart:
  baud_rate: 256000
  tx_pin: 2
  rx_pin: 1
  parity: NONE
  stop_bits: 1

i2c:
  sda: 7
  scl: 6
  scan: false

ld2410:
  id: ld2410_sensor

binary_sensor:
  - platform: status
    name: "Status"

  - platform: ld2410
    has_target:
      name: 'Hi-Link HLK-LD2410: Presence (UART)'
    has_moving_target:
      name: 'Hi-Link HLK-LD2410: Presence moving'
    has_still_target:
      name: 'Hi-Link HLK-LD2410: Presence still'
    out_pin_presence_status:
      name: 'Hi-Link HLK-LD2410: Presence GPIO indicates'

  - platform: gpio
    pin: 3
    id: presence_gpio
    name: 'Hi-Link HLK-LD2410: Presence (GPIO)'
    on_press:
      then:
        - output.turn_on: presence_led
    on_release:
      then:
        - output.turn_off: presence_led

sensor:
  - platform: uptime
    name: "Uptime"
    update_interval: 1s

  - platform: wifi_signal
    name: "WiFi Signal"
    unit_of_measurement: "dB"
    icon: 'mdi:signal'
    update_interval: 5s

  - platform: debug
    free:
      name: "Debug: Heap Free"
    block:
      name: "Debug: Heap Largest Contiguous Free Block"
    loop_time:
      name: "Debug: Loop Time"

  - platform: ld2410
    # Engineering Mode
    light:
      name: 'Hi-Link HLK-LD2410: Light'
    moving_distance:
      name: 'Hi-Link HLK-LD2410: Presence moving distance'
    still_distance:
      name: 'Hi-Link HLK-LD2410: Presence still distance'
    moving_energy:
      name: 'Hi-Link HLK-LD2410: Presence moving energy'
    still_energy:
      name: 'Hi-Link HLK-LD2410: Presence still energy'
    detection_distance:
      name: 'Hi-Link HLK-LD2410: Presence distance'
    g0:
      # Engineering Mode
      move_energy:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 0 energy'
      # Engineering Mode
      still_energy:
        name: 'Hi-Link HLK-LD2410: Presence still gate 0 energy'
    g1:
      # Engineering Mode
      move_energy:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 1 energy'
      # Engineering Mode
      still_energy:
        name: 'Hi-Link HLK-LD2410: Presence still gate 1 energy'
    g2:
      # Engineering Mode
      move_energy:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 2 energy'
      # Engineering Mode
      still_energy:
        name: 'Hi-Link HLK-LD2410: Presence still gate 2 energy'
    g3:
      # Engineering Mode
      move_energy:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 3 energy'
      # Engineering Mode
      still_energy:
        name: 'Hi-Link HLK-LD2410: Presence still gate 3 energy'
    g4:
      # Engineering Mode
      move_energy:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 4 energy'
      # Engineering Mode
      still_energy:
        name: 'Hi-Link HLK-LD2410: Presence still gate 4 energy'
    g5:
      # Engineering Mode
      move_energy:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 5 energy'
      # Engineering Mode
      still_energy:
        name: 'Hi-Link HLK-LD2410: Presence still gate 5 energy'
    g6:
      # Engineering Mode
      move_energy:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 6 energy'
      # Engineering Mode
      still_energy:
        name: 'Hi-Link HLK-LD2410: Presence still gate 6 energy'
    g7:
      # Engineering Mode
      move_energy:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 7 energy'
      # Engineering Mode
      still_energy:
        name: 'Hi-Link HLK-LD2410: Presence still gate 7 energy'
    g8:
      # Engineering Mode
      move_energy:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 8 energy'
      # Engineering Mode
      still_energy:
        name: 'Hi-Link HLK-LD2410: Presence still gate 8 energy'

  - platform: bh1750
    name: "Rohms BH1750"
    address: 0x23
    update_interval: 1s
    unit_of_measurement: "lx"

output:
  - platform: slow_pwm
    id: wifi_led_pwm
    period: 1s
    pin: 5

  - platform: gpio
    pin: 4
    id: presence_led

switch:
  - platform: ld2410
    engineering_mode:
      id: ld2410_engineering_mode
      name: "Hi-Link HLK-LD2410: Engineering mode"
    bluetooth:
      id: ld2410_bluetooth
      name: "Hi-Link HLK-LD2410: Bluetooth"

number:
  - platform: ld2410
    timeout:
      name: 'Hi-Link HLK-LD2410: Presence timeout'
      # unit_of_measurement: "s"
    light_threshold:
      name: 'Hi-Link HLK-LD2410: Light threshold'
    max_move_distance_gate:
      name: 'Hi-Link HLK-LD2410: Presence moving max distance gate'
    max_still_distance_gate:
      name: 'Hi-Link HLK-LD2410: Presence still max distance gate'
    g0:
      move_threshold:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 0 threshold'
      still_threshold:
        name: 'Hi-Link HLK-LD2410: Presence still gate 0 threshold'
    g1:
      move_threshold:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 1 threshold'
      still_threshold:
        name: 'Hi-Link HLK-LD2410: Presence still gate 1 threshold'
    g2:
      move_threshold:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 2 threshold'
      still_threshold:
        name: 'Hi-Link HLK-LD2410: Presence still gate 2 threshold'
    g3:
      move_threshold:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 3 threshold'
      still_threshold:
        name: 'Hi-Link HLK-LD2410: Presence still gate 3 threshold'
    g4:
      move_threshold:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 4 threshold'
      still_threshold:
        name: 'Hi-Link HLK-LD2410: Presence still gate 4 threshold'
    g5:
      move_threshold:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 5 threshold'
      still_threshold:
        name: 'Hi-Link HLK-LD2410: Presence still gate 5 threshold'
    g6:
      move_threshold:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 6 threshold'
      still_threshold:
        name: 'Hi-Link HLK-LD2410: Presence still gate 6 threshold'
    g7:
      move_threshold:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 7 threshold'
      still_threshold:
        name: 'Hi-Link HLK-LD2410: Presence still gate 7 threshold'
    g8:
      move_threshold:
        name: 'Hi-Link HLK-LD2410: Presence moving gate 8 threshold'
      still_threshold:
        name: 'Hi-Link HLK-LD2410: Presence still gate 8 threshold'

button:
  - platform: restart
    name: "Restart"

  - platform: safe_mode
    name: "Safe Mode"

  - platform: factory_reset
    id: factory_reset_button
    name: "Factory Reset"

  - platform: ld2410
    factory_reset:
      name: "Hi-Link HLK-LD2410: Factory reset"
    restart:
      id: ld2410_restart
      name: "Hi-Link HLK-LD2410: Restart"
    query_params:
      id: ld2410_query_params
      name: 'Hi-Link HLK-LD2410: Query params'

text_sensor:
  - platform: wifi_info
    ip_address:
      name: "Wifi Info: IP Address"
    ssid:
      name: "Wifi Info: SSID"
    bssid:
      name: "Wifi Info: BSSID"
    mac_address:
      name: "Wifi Info: MAC Address"
    dns_address:
      name: "Wifi Info: DNS Address"

  - platform: debug
    device:
      name: "Debug: Device Info"
    reset_reason:
      name: "Debug: Reset Reason"

  - platform: ld2410
    version:
      name: "Hi-Link HLK-LD2410: Firmware version"
    mac_address:
      name: "Hi-Link HLK-LD2410: Bluetooth MAC address"

select:
  - platform: ld2410
    distance_resolution:
      name: "Hi-Link HLK-LD2410: Presence distance resolution"
    baud_rate:
      name: "Hi-Link HLK-LD2410: Baud rate"
    light_function:
      name: 'Hi-Link HLK-LD2410: Light function'
    out_pin_level:
      name: 'Hi-Link HLK-LD2410: Presence GPIO pin level'

text:
  - platform: template
    name: "Hi-Link HLK-LD2410: Bluetooth password"
    optimistic: true
    min_length: 6
    max_length: 6
    mode: text
    on_value:
      then:
        - bluetooth_password.set:
            id: ld2410_sensor
            password: !lambda 'return x;'

Anything in the logs that might be useful for us?

[D][sensor:094]: 'Uptime': Sending state 472.12701 s with 0 decimals of accuracy
[D][sensor:094]: 'Hi-Link HLK-LD2410: Presence moving distance': Sending state 150.00000 cm with 0 decimals of accuracy
[D][sensor:094]: 'Hi-Link HLK-LD2410: Presence moving energy': Sending state 12.00000 % with 0 decimals of accuracy
[D][sensor:094]: 'Hi-Link HLK-LD2410: Presence still distance': Sending state 317.00000 cm with 0 decimals of accuracy
[D][sensor:094]: 'Hi-Link HLK-LD2410: Presence still energy': Sending state 100.00000 % with 0 decimals of accuracy
[D][sensor:094]: 'Hi-Link HLK-LD2410: Presence distance': Sending state 131.00000 cm with 0 decimals of accuracy
[W][component:214]: Component ld2410 took a long time for an operation (0.05 s).
[W][component:215]: Components should block for at most 20-30ms.
[D][bh1750.sensor:159]: 'Rohms BH1750': Got illuminance=314.1lx
[D][sensor:094]: 'Rohms BH1750': Sending state 314.09940 lx with 1 decimals of accuracy
[D][sensor:094]: 'Uptime': Sending state 473.12701 s with 0 decimals of accuracy
[D][bh1750.sensor:159]: 'Rohms BH1750': Got illuminance=314.4lx
[D][sensor:094]: 'Rohms BH1750': Sending state 314.43896 lx with 1 decimals of accuracy
[D][sensor:094]: 'Hi-Link HLK-LD2410: Presence moving distance': Sending state 217.00000 cm with 0 decimals of accuracy
[D][sensor:094]: 'Hi-Link HLK-LD2410: Presence moving energy': Sending state 21.00000 % with 0 decimals of accuracy
[D][sensor:094]: 'Hi-Link HLK-LD2410: Presence still distance': Sending state 63.00000 cm with 0 decimals of accuracy
[D][sensor:094]: 'Hi-Link HLK-LD2410: Presence distance': Sending state 90.00000 cm with 0 decimals of accuracy
[D][sensor:094]: 'Uptime': Sending state 474.12701 s with 0 decimals of accuracy
[D][bh1750.sensor:159]: 'Rohms BH1750': Got illuminance=314.4lx
[D][sensor:094]: 'Rohms BH1750': Sending state 314.43896 lx with 1 decimals of accuracy
[D][binary_sensor:036]: 'Hi-Link HLK-LD2410: Presence moving': Sending state ON
[D][sensor:094]: 'Hi-Link HLK-LD2410: Presence moving distance': Sending state 69.00000 cm with 0 decimals of accuracy
[D][sensor:094]: 'Hi-Link HLK-LD2410: Presence moving energy': Sending state 39.00000 % with 0 decimals of accuracy
[D][sensor:094]: 'Hi-Link HLK-LD2410: Presence still distance': Sending state 45.00000 cm with 0 decimals of accuracy
[D][sensor:094]: 'Hi-Link HLK-LD2410: Presence distance': Sending state 56.00000 cm with 0 decimals of accuracy
Guru Meditation Error: Core  0 panic'ed (Load access fault). Exception was unhandled.

Core  0 register dump:
MEPC    : 0x4202be40  RA      : 0x4202be22  SP      : 0x3fca3470  GP      : 0x3fc8f400
TP      : 0x3fc85db0  T0      : 0x6c685f6b  T1      : 0x645f6563  T2      : 0x6e696c2d
S0/FP   : 0x3fcb9894  S1      : 0x3fcb8ebc  A0      : 0x00000001  A1      : 0x3fcb8ebc
A2      : 0x0a0d0a0d  A3      : 0x3fcbab54  A4      : 0x00000001  A5      : 0x00000002
A6      : 0x2265636e  A7      : 0x61747369  S2      : 0x42600000  S3      : 0x3fcb2020
S4      : 0x42b40000  S5      : 0x00000000  S6      : 0x00000000  S7      : 0x00000000
S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000
T3      : 0x6e657365  T4      : 0x72705f5f  T5      : 0x30313432  T6      : 0x646c2d6b
MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000005  MTVAL   : 0x00000005
MHARTID : 0x00000000

Stack memory:
3fca3470: 0x42600000 0x3fcb9894 0x3fc98000 0x4202bf28 0x00000000 0x00000001 0x42600000 0x3fcb9c3c
3fca3490: 0x42340000 0x3fcb74c8 0x00000000 0x3fcb9c3c 0x0000006f 0x00000068 0x0e000a0d 0x9201d021
3fca34b0: 0x43590000 0x3fca454c 0x3fc98000 0x4201824e 0x00000000 0x3fcb9b40 0x00000050 0x00000078
3fca34d0: 0x42600000 0x3fc98000 0x3fca5558 0x9201d021 0x42340000 0x3fc98000 0x3fcb2000 0x42007dd8
3fca34f0: 0x42600000 0x3fc98000 0x3fca3534 0x42600000 0x3c0d75ac 0x00000000 0x00000000 0x42015606
3fca3510: 0x3fca353c 0x00000000 0x00000054 0x00000078 0x00000000 0x404c0000 0x3fcb9844 0x3c0d75ac
3fca3530: 0x00000001 0x3fca353c 0x00000002 0x42006d63 0x00000000 0x3caf6dc0 0x3fc9f008 0x9201d021
3fca3550: 0xfa000000 0x00000001 0x00000000 0x00000002 0x42600000 0x3fc9221c 0x3fca4c54 0x4200d10a
3fca3570: 0x3fca4bc8 0x3fca35af 0x3fcb9844 0x3fca4c54 0x3fcb9828 0x3fc92000 0x3fc978c0 0x4200f58a
3fca3590: 0x3fcb9828 0x3fc92000 0x3fca4c54 0x4200f604 0x00000000 0x00000001 0x3fca4fa4 0xf5ca4c54
3fca35b0: 0x3fcb9824 0x00000002 0x3fc927ac 0x4201f45e 0x00000000 0x00000000 0x00073e24 0x3fca4c54
3fca35d0: 0x73222c37 0x3fc98000 0x00000000 0x00000000 0x00000000 0x3fc98000 0x42032192 0x42035d1e
3fca35f0: 0x00000000 0x00000000 0x00000000 0x4038a958 0x00000000 0x00000000 0x00000000 0x00000000
3fca3610: 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fca3630: 0xbaad5678 0x00000160 0xabba1234 0x00000154 0x3fca33f0 0x00074143 0x3fc941cc 0x3fc941cc
3fca3650: 0x3fca3640 0x3fc941c4 0x00000018 0x3fca40bc 0x3fca40bc 0x3fca3640 0x00000000 0x00000001
3fca3670: 0x3fca1630 0x706f6f6c 0x6b736154 0xa6b7ce00 0x00c728a2 0x00000000 0x3fca3620 0x00000001
3fca3690: 0x00000000 0x3fcabb90 0x4204228e 0x0000000b 0x3fc99024 0x3fc9908c 0x3fc990f4 0x00000000
3fca36b0: 0x00000000 0x00000001 0x00000000 0x00000000 0x3fcb0d8c 0x420b1ee6 0x00000000 0x00000000
3fca36d0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca36f0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca3710: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca3730: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca3750: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca3770: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000001
3fca3790: 0x84000000 0xbaad5678 0x00000018 0xabba1234 0x0000000c 0x3fca3640 0x00000000 0x00000000
3fca37b0: 0xbaad5678 0x00000050 0xabba1234 0x00000044 0x3c0d42a8 0x00000002 0x7fc00000 0x3c0d42e0
3fca37d0: 0x0001c200 0x3fca3814 0x0000007a 0x00000200 0x00000000 0x3fc92aec 0x00000000 0x00000000
3fca37f0: 0x00000000 0x3fcb2720 0x3fcb2740 0x3fcb2740 0x766dd200 0xbaad5678 0x00000210 0xabba1234
3fca3810: 0x00000201 0x3b305b1b 0x5b6d3633 0x735b5d44 0x6f736e65 0x39303a72 0x203a5d34 0x2d694827
3fca3830: 0x6b6e694c 0x4b4c4820 0x32444c2d 0x3a303134 0x65725020 0x636e6573 0x69642065 0x6e617473
3fca3850: 0x3a276563 0x6e655320 0x676e6964 0x61747320 0x35206574 0x30302e36 0x20303030 0x77206d63

ELF file SHA256: 0000000000000000

Rebooting...
ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0xf (SPI_FAST_FLASH_BOOT)
Saved PC:0x4038252a
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x438
load:0x403ce000,len:0x918
load:0x403d0000,len:0x24e4
entry 0x403ce000
[I][logger:355]: Log initialized

Additional information

No response

fornellas commented 5 months ago

Bug seems to be here:

0x4200d10a: esphome::ld2410::LD2410Component::handle_periodic_data_(unsigned char*, int) at toolchain-riscv32-esp/riscv32-esp-elf/include/c++/8.4.0/bits/stl_tree.h:2476
 (inlined by) esphome::ld2410::LD2410Component::handle_periodic_data_(unsigned char*, int) at presence/src/esphome/components/ld2410/ld2410.cpp:146

0x4200f58a: esphome::ld2410::LD2410Component::readline_(int, unsigned char*, int) at toolchain-riscv32-esp/riscv32-esp-elf/include/c++/8.4.0/bits/stl_tree.h:2476
 (inlined by) esphome::ld2410::LD2410Component::readline_(int, unsigned char*, int) at presence/src/esphome/components/ld2410/ld2410.cpp:478

0x4200f604: esphome::ld2410::LD2410Component::loop() at toolchain-riscv32-esp/riscv32-esp-elf/include/c++/8.4.0/bits/stl_tree.h:2476

CC @regevbr, @sebcaps

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.