paveldn / haier-esphome

Haier ac integration for ESPHome
91 stars 13 forks source link

Configuring a `platform: haier` beeper switch causes esp8266 to crash #62

Open roobre opened 2 days ago

roobre commented 2 days ago

Hey,

I recently updated esphome which brought the new version of the library with the native haier switches/buttons, which I think are great!

I'm however facing some trouble getting the new beeper swtich to work after the deprecation of beeper: false. When I try to call climate.haier.beeper_off, or just create a beeper switch as in the example:

switch:
  - platform: haier
    haier_id: hvac # This is the id in my config
    beeper:
      name: Haier hOn Climate beeper

My esp8266 (d1_mini) crashes:

[11:30:26][I][app:062]: setup() finished successfully!
[11:30:26][W][component:170]: Component wifi cleared Warning flag
[11:30:26][W][component:157]: Component api set Warning flag: unspecified
[11:30:26][I][app:100]: ESPHome version 2024.10.2 compiled on Nov  3 2024, 11:30:03
[11:30:26][C][wifi:600]: WiFi:
# Redacted
[11:30:26][C][logger:185]: Logger:
[11:30:26][C][logger:186]:   Level: DEBUG
[11:30:26][C][logger:188]:   Log Baud Rate: 115200
[11:30:26][C][logger:189]:   Hardware UART: UART0
[11:30:26][C][uart.arduino_esp8266:118]: UART Bus:
[11:30:26][C][uart.arduino_esp8266:119]:   TX Pin: GPIO4
[11:30:26][C][uart.arduino_esp8266:120]:   RX Pin: GPIO5
[11:30:26][C][uart.arduino_esp8266:122]:   RX Buffer Size: 256
[11:30:26][C][uart.arduino_esp8266:124]:   Baud Rate: 9600 baud
[11:30:26][C][uart.arduino_esp8266:125]:   Data Bits: 8
[11:30:26][C][uart.arduino_esp8266:126]:   Parity: NONE
[11:30:26][C][uart.arduino_esp8266:127]:   Stop bits: 1
[11:30:26][C][uart.arduino_esp8266:131]:   Using software serial
[11:30:26][C][haier.climate:256]: Haier Climate 'HVAC'
[11:30:26][C][haier.climate:257]:   Device communication status: none
[11:30:26][C][haier.climate:333]:   Protocol version: hOn
[11:30:26][C][haier.climate:334]:   Control method: 1
[11:30:26][C][template.select:065]: Template Select 'Vertical airflow'
[11:30:26][C][template.select:065]:   Icon: 'mdi:arrow-expand-vertical'
[11:30:26][C][template.select:066]:   Update Interval: 60.0s
[11:30:26][C][mdns:116]: mDNS:
[11:30:26][C][mdns:117]:   Hostname: living-room-ac
[11:30:26][C][esphome.ota:073]: Over-The-Air updates:
[11:30:26][C][esphome.ota:074]:   Address: 10.0.3.41:8266
[11:30:26][C][esphome.ota:075]:   Version: 2
[11:30:26][C][esphome.ota:078]:   Password configured
[11:30:26][C][safe_mode:018]: Safe Mode:
[11:30:26][C][safe_mode:019]:   Boot considered successful after 60 seconds
[11:30:26][C][safe_mode:021]:   Invoke after 10 boot attempts
[11:30:26][C][safe_mode:022]:   Remain in safe mode for 300 seconds
[11:30:26][W][safe_mode:028]: Last reset occurred too quickly; safe mode will be invoked in 7 restarts
[11:30:26][C][api:140]: API Server:
[11:30:26][C][api:141]:   Address: 10.0.3.41:6053
[11:30:26][C][api:143]:   Using noise encryption: YES
[11:30:27][D][haier.protocol:019]: Sending frame: type 61, data: 00 07
[11:30:27][W][haier.climate:234]: Answer timeout for command 61, phase SENDING_INIT_1
[11:30:37][D][haier.protocol:019]: Sending frame: type 61, data: 00 07
[11:30:37][W][haier.climate:234]: Answer timeout for command 61, phase SENDING_INIT_1
[11:30:41][D][api:103]: Accepted 10.0.0.31
[11:30:41][W][api.connection:092]: : Socket operation failed: HANDSHAKESTATE_SETUP_FAILED errno=11
[11:30:41][W][component:170]: Component api cleared Warning flag
[11:30:41][W][component:157]: Component api set Warning flag: unspecified
[11:30:47][D][haier.protocol:019]: Sending frame: type 61, data: 00 07
[11:30:47][W][haier.climate:234]: Answer timeout for command 61, phase SENDING_INIT_1
[11:30:56][D][select:015]: 'Vertical airflow': Sending state Center (index 3)
[11:30:57][D][haier.protocol:019]: Sending frame: type 61, data: 00 07
[11:30:57][W][haier.climate:234]: Answer timeout for command 61, phase SENDING_INIT_1
[11:31:00][D][api:103]: Accepted 10.0.0.31
[11:31:00]
[11:31:00]--------------- CUT HERE FOR EXCEPTION DECODER ---------------
[11:31:00]
[11:31:00]Exception (3):
WARNING Exception type: LoadStoreError: Processor internal physical address or data error during load or store
[11:31:00]epc1=0x40100f99 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4002ee71 depc=0x00000000
WARNING Decoded 0x40100f99: umm_malloc_core at umm_malloc.cpp
[11:31:00]
[11:31:00]>>>stack>>>
WARNING Found stack trace! Trying to decode it
[11:31:00]
[11:31:00]ctx: cont
[11:31:00]sp: 3ffffbb0 end: 3fffffd0 offset: 0150
[11:31:00]3ffffd00:  00000013 4020f8a9 00000020 3fffbf84
WARNING Decoded 0x4020f8a9: _ZNSt6vectorIhSaIhEE12emplace_backIJhEEERhDpOT_$isra$0 at api_frame_helper.cpp
[11:31:00]3ffffd10:  00000000 0000000e 00000020 40101220
WARNING Decoded 0x40101220: malloc
[11:31:00]3ffffd20:  3fffbb74 3fff9b0c 3fffbea4 4020152b
WARNING Decoded 0x4020152b: noise_handshakestate_set_prologue
[11:31:00]3ffffd30:  00005202 00000003 3fff9afc 3fff229c
[11:31:00]3ffffd40:  3fff9b0c 00000000 3fffb474 4020fae3
WARNING Decoded 0x4020fae3: esphome::api::APINoiseFrameHelper::init_handshake_()
[11:31:00]3ffffd50:  00000000 3fff9b0c 3fffb474 402101b3
WARNING Decoded 0x402101b3: esphome::api::APINoiseFrameHelper::state_action_()
[11:31:00]3ffffd60:  3fff9afc 3fff9b0c 3fff9b0c 4023b135
WARNING Decoded 0x4023b135: vsnprintf at /workdir/repo/newlib/newlib/libc/stdio/vsnprintf.c:41
[11:31:00]3ffffd70:  3ffffde0 3ffffdd0 00000008 40232e3c
WARNING Decoded 0x40232e3c: uart_write
[11:31:00]3ffffd80:  3ffea87e fffffffc 00000010 ffffffff
[11:31:00]3ffffd90:  00000000 3ffe3331 3fff39b4 3ffe8b79
[11:31:00]3ffffda0:  00000003 00000001 00000000 00000000
[11:31:00]3ffffdb0:  402683ae 3fff7a84 3fffad50 00000001
WARNING Decoded 0x402683ae: wifi_get_opmode
[11:31:00]3ffffdc0:  3fff22ab 00000010 00000005 3fff7d5c
[11:31:00]3ffffdd0:  3fff9f3c 4022318c 3ffffe50 3fff7d5c
WARNING Decoded 0x4022318c: esphome::wifi::WiFiComponent::wifi_sta_connect_status_()
[11:31:00]3ffffde0:  3fffad50 3fffad50 3fffb474 40210518
WARNING Decoded 0x40210518: esphome::api::APINoiseFrameHelper::loop()
[11:31:00]3ffffdf0:  00000000 00000000 3fffb3bc 4020d804
WARNING Decoded 0x4020d804: esphome::api::APIConnection::loop()
[11:31:00]3ffffe00:  00000000 00000000 00000000 00000000
[11:31:00]3ffffe10:  3ffe0000 3ffe8b6c 0000000c 00c40771
[11:31:00]3ffffe20:  00000009 3fffb3d8 3ffffe50 3fff7d5c
[11:31:00]3ffffe30:  4020f484 3fffb3d8 3fffb474 4020d330
WARNING Decoded 0x4020f484: esphome::api::APINoiseFrameHelper::set_log_info(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
WARNING Decoded 0x4020d330: esphome::api::APIConnection::start()
[11:31:00]3ffffe40:  00000000 3ffffe50 00000010 3fff7d5c
[11:31:00]3ffffe50:  3ffffee4 00000000 302e3000 332e302e
[11:31:00]3ffffe60:  3fff0031 332e302e 000000b0 3fff7d5c
[11:31:00]3ffffe70:  3fffad50 3fffad50 3fff7d5c 402145a0
WARNING Decoded 0x402145a0: esphome::api::APIServer::loop()
[11:31:00]3ffffe80:  17a50210 2903000a 0000000a 3fff7e74
[11:31:00]3ffffe90:  0000002b 00000000 00058818 00000000
[11:31:00]3ffffea0:  00000009 302e3031 332e302e 40230031
WARNING Decoded 0x40230031: EspClass::flashWrite(unsigned int, unsigned int const*, unsigned int)
[11:31:00]3ffffeb0:  0000000a 3fffb3bc 3fff7f54 4022e88b
WARNING Decoded 0x4022e88b: haier_protocol::ProtocolHandler::loop()
[11:31:00]3ffffec0:  00000000 3fff1388 40232919 00000000
WARNING Decoded 0x40232919: _gettimeofday_r
[11:31:00]3ffffed0:  00000000 3fffff20 00016211 4023292c
WARNING Decoded 0x4023292c: _gettimeofday_r
[11:31:00]3ffffee0:  00000000 0000001c 3fffff20 3fff7e74
[11:31:00]3ffffef0:  00000000 0000a988 f1eb851e 00c40657
[11:31:00]3fffff00:  189b8bc0 0000000a 3fff2200 3fff9bc4
[11:31:00]3fffff10:  3fff2910 00000001 3fff9bf8 4022a4e0
WARNING Decoded 0x4022a4e0: esp8266::polledTimeout::timeoutTemplate<false, esp8266::polledTimeout::YieldPolicy::DoNothing, esp8266::polledTimeout::TimePolicy::TimeUnit<esp8266::polledTimeout::TimePolicy::TimeSourceMillis, 1000ull> >::expiredOneShot() const
[11:31:00]3fffff20:  0000002b 00000000 00000001 4022a9e8
WARNING Decoded 0x4022a9e8: esp8266::MDNSImplementation::MDNSResponder::_updateProbeStatus()
[11:31:00]3fffff30:  40269593 0000000c 0000001c 00000000
WARNING Decoded 0x40269593: wifi_station_get_connect_status
[11:31:00]3fffff40:  00000000 0000a989 16041893 00c40681
[11:31:00]3fffff50:  0000a988 3fff986c 3fff2200 3fff7d5c
[11:31:00]3fffff60:  3fffad68 3fff7d5c 3fffff80 3fff7d5c
[11:31:00]3fffff70:  3fffad68 00000002 3fff2200 4022378e
WARNING Decoded 0x4022378e: esphome::Application::loop()
[11:31:00]3fffff80:  0000a989 3fff7d5c 3fff9b54 3fff3b7c
[11:31:00]3fffff90:  3fffad6c 3fff8c34 3fff2234 3fff3b7c
[11:31:00]3fffffa0:  3fffdad0 00000000 3fff3b50 3fff3b7c
[11:31:00]3fffffb0:  3fffdad0 00000000 3fff3b50 40231cf8
WARNING Decoded 0x40231cf8: loop_wrapper() at core_esp8266_main.cpp
[11:31:00]3fffffc0:  feefeffe feefeffe 3fffdab0 40100669
WARNING Decoded 0x40100669: cont_wrapper
[11:31:00]<<<stack<<<
[11:31:00]
[11:31:00]--------------- CUT HERE FOR EXCEPTION DECODER ---------------
[11:31:00]
[11:31:00] ets Jan  8 2013,rst cause:2, boot mode:(3,6)
[11:31:00]
[11:31:00]load 0x4010f000, len 3424, room 16
[11:31:00]tail 0
[11:31:00]chksum 0x2e
[11:31:00]load 0x3fff20b8, len 40, room 8
[11:31:00]tail 0
[11:31:00]chksum 0x2b
[11:31:00]csum 0x2b
[11:31:00]v000813c0

Feel free to ignore the timeout messages, this happened as I had to pull the esp out of the AC unit to reflash it via serial.

This is an hOn unit:

climate:
  - name: HVAC
    id: hvac
    platform: haier
    protocol: hon
    uart_id: hw0

In this case the error occurred after a few seconds. Is something wrong with my config?

Here's the full config attached:

haier-works.yaml.txt haier-crashes.yaml.txt

13:16:08 /tmp/nadia $> diff haier-*
168,173c168,172
<
< switch:
<   - platform: haier
<     haier_id: hvac
<     beeper:
<       name: Beeper
---
> # switch:
> #   - platform: haier
> #     haier_id: hvac
> #     beeper:
> #       name: Beeper
roobre commented 2 days ago

I'm not a CPP expert or anything close, but I can't help but notice that there is nothing related to haier in the trace. However I have verified that adding the haier switch snippet definitely caused this to happen, and vice versa. As the error seems to be in malloc, perhaps somewhere the haier code is looping and exhausting all available memory? Or perhaps overflowing a buffer somewhere and corrupting the heap? Just a wild guess.

paveldn commented 1 day ago

Hi @roobre,

That is strange. Technically those switches not doing anything it is just mark that every time when command will be sent in future bit that suppress sound feedback should be set to 1. I can't reproduce problem with my AC. But I am using ESP32. Can you try with ESP32? Through last releases I see that ESPHome uses more and more resources (providing more and more features of course) but for old ESP8266 it gets more and more difficult to keep up. When you adding switch it includes a lot of switch related code which push your device "over the edge".

Also one of the thing you can try is to remove everything related to Haier except plain AC itself and beeper switch. It should be something like this:

climate:
  - name: HVAC
    id: hvac
    platform: haier
    protocol: hon
    uart_id: hw0

switch:
  - platform: haier
    haier_id: hvac
    beeper:
      name: Beeper

Remove all other buttons sensors and selects. Try to reproduce same problem. THanks.