D1 mini in boot loop after OTA flash (and still after USB flash)

Hey, not sure where to search further around this one, so here I am I guess.

In short: I have a d1 mini 8266 running since August which has 2 infrared sensor connected to read power and gas usage. It ran without interuption until the 1st of January, there I had to do a hard reboot because it stopped providing data to HA, but again flawless since then. Today I changed the code for the first time since August and did an OTA update, which resulted in a boot loop without being able to connect to the Wifi. I reverted the code change, flashed the old version via USB, but the d1 mini still behaves the same.
The only change I made since August: I updated my esphome version to 2022.12.8.

I use my windows10 laptop to develop and flash, so esphome command line.

When I do the flashing via USB, the logs return this:

[09:46:54]--------------- CUT HERE FOR EXCEPTION DECODER ---------------
[09:46:54]
[09:46:54]Exception (28):
WARNING Exception type: Access to invalid address: LOAD (wild pointer?)
[09:46:54]epc1=0x4020d01b epc2=0x00000000 epc3=0x00000000 excvaddr=0x0c260000 depc=0x00000000
WARNING Decoded 0x4020d01b: esphome::wifi::WiFiComponent::wifi_sta_connect_status_()
[09:46:54]
[09:46:54]>>>stack>>>
WARNING Found stack trace! Trying to decode it
[09:46:54]
[09:46:54]ctx: cont
[09:46:54]sp: 3ffffc80 end: 3fffffc0 offset: 0190
[09:46:54]3ffffe10:  3fff1e44 4020d00c 4bc6a7f0 00000000
WARNING Decoded 0x4020d00c: esphome::wifi::WiFiComponent::wifi_sta_connect_status_()
[09:46:54]3ffffe20:  00000000 3ffef500 40100629 4020c74a
WARNING Decoded 0x40100629: millis
WARNING Decoded 0x4020c74a: esphome::wifi::WiFiComponent::check_connecting_finished()
[09:46:54]3ffffe30:  000017c2 3ffef590 3fff18b4 40210012
WARNING Decoded 0x40210012: esphome::Scheduler::call()
[09:46:54]3ffffe40:  007a1200 589b167b 3ffe8600 00000100
[09:46:54]3ffffe50:  3fff0bcc 00000013 3fff0bcc 00000100
[09:46:54]3ffffe60:  3fff0bcc 000017c2 3fff0bcc 4020c8dc
WARNING Decoded 0x4020c8dc: esphome::wifi::WiFiComponent::loop()
[09:46:54]3ffffe70:  000017c2 00000013 3ffef590 40222750
WARNING Decoded 0x40222750: esphome::Component::call_loop()
[09:46:54]3ffffe80:  3fff16a4 3ffffea0 3ffef590 4022281c
WARNING Decoded 0x4022281c: esphome::Component::call()
[09:46:54]3ffffe90:  3fff0bcc 00000013 3ffef590 4020ed09
WARNING Decoded 0x4020ed09: esphome::Application::setup()
[09:46:54]3ffffea0:  00000014 00000014 3fff1a5c 4022f21c
WARNING Decoded 0x4022f21c: operator delete(void*) at /workdir/repo/gcc-gnu/libstdc++-v3/libsupc++/del_op.cc:50
[09:46:54]3ffffeb0:  00000050 00000000 00000000 4020dc42
WARNING Decoded 0x4020dc42: esphome::Application::register_component_(esphome::Component*)
[09:46:54]3ffffec0:  3fff0edc 3ffef668 3fffff70 3ffef590
[09:46:54]3ffffed0:  3fffff70 3fff0b54 3ffef6a4 402113c4
WARNING Decoded 0x402113c4: setup
[09:46:54]3ffffee0:  3fff0e04 3fff0e08 3fff0e08 00000000
[09:46:54]3ffffef0:  74746177 00000000 00000000 00000000
[09:46:54]3fffff00:  3fffff08 0000000c 6b486a6a 6f65516f
[09:46:54]3fffff10:  52336259 00000000 00000000 00000000
[09:46:54]3fffff20:  00000000 00000000 00000000 00000000
[09:46:54]3fffff30:  00000000 00000000 3fffff70 00000001
[09:46:54]3fffff40:  6b486a6a 6f65516f 52336259 feefef00
[09:46:54]3fffff50:  3fffff38 00000001 3fffff38 00000001
[09:46:54]3fffff60:  3fffff38 00000001 3fffff38 00000002
[09:46:54]3fffff70:  3fff1724 feefeffe feefeffe feefeffe
[09:46:54]3fffff80:  3fff1244 00000084 3fff10f4 00000001
[09:46:54]3fffff90:  feefeffe feefeffe feefeffe 3ffef9ac
[09:46:54]3fffffa0:  3fffdad0 00000000 3ffef998 4021ed58
WARNING Decoded 0x4021ed58: loop_wrapper() at core_esp8266_main.cpp
[09:46:54]3fffffb0:  feefeffe feefeffe 3ffe8640 40100471
WARNING Decoded 0x40100471: cont_wrapper
[09:46:54]<<<stack<<<
[09:46:54]
[09:46:54]--------------- CUT HERE FOR EXCEPTION DECODER ---------------
[09:46:54]
[09:46:54] ets Jan  8 2013,rst cause:2, boot mode:(3,6)
[09:46:54]
[09:46:54]load 0x4010f000, len 3460, room 16
[09:46:54]tail 4
[09:46:54]chksum 0xcc
[09:46:54]load 0x3fff20b8, len 40, room 4
[09:46:54]tail 4
[09:46:54]chksum 0xc9
[09:46:54]csum 0xc9
[09:46:54]v00068360
[09:46:54]~ld

In case it helps, this is the YAML (with the original code that ran since August):

esphome:
  name: power8266

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: ""

ota:
  password: ""

wifi:
  ssid: "xxxxxx"
  password: "xxxxxxxx"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Power8266 Fallback Hotspot"
    password: "xxxxxxxxx"

captive_portal:

time:
  - platform: homeassistant
    id: homeassistant_time
    on_time_sync:
      then:
        - lambda: |-
            id(lastpulse) = millis();


globals:
  - id: total_e_pulses
    type: int
    restore_value: false
    initial_value: '0'
  - id: total_g_pulses
    type: int
    restore_value: false
    initial_value: '0'
  - id: lastpulse
    type: float
    restore_value: false
    initial_value: '0'
  - id: rotationtime
    type: float
    restore_value: false
    initial_value: '0'

binary_sensor:
  - platform: gpio
    id: electro_pulse_counter
    pin: GPIO12
    filters:
      - invert: 
      - delayed_on: 200ms
    on_press:
      then:
        - lambda: |- 
            id(total_e_pulses) += 1;
            id(rotationtime) = (millis() - id(lastpulse)) / 1000;
            id(lastpulse) = millis();
  - platform: gpio
    id: gas_pulse_counter
    pin: GPIO5
    filters:
      - delayed_on: 500ms
    on_press:
      then:
        - lambda: id(total_g_pulses) += 1;
        
sensor:
  - platform: template
    name: "Gas usage"
    device_class: gas
    unit_of_measurement: "m³"
    state_class: "total_increasing"
    icon: "mdi:fire"
    accuracy_decimals: 2
    lambda: |-
        return id(total_g_pulses) * 0.01;
  - platform: template
    name: "Power usage"
    device_class: energy
    unit_of_measurement: "kWh"
    state_class: "total_increasing"
    icon: "mdi:flash"
    accuracy_decimals: 2
    lambda: |-
        return id(total_e_pulses) * 0.0026666666666667;
  - platform: template
    name: "rotation time"
    unit_of_measurement: "s"
    update_interval: 30s
    lambda: |-
      return id(rotationtime);
  - platform: template
    name: "current watt"
    device_class: "power"
    unit_of_measurement: "W"
    update_interval: 30s
    accuracy_decimals: 0
    lambda: |-
      return 9600 / id(rotationtime);

Not sure what to do with this one, any ideas would be highly appreciated. I could flash the code onto another d1 mini board under a different device name (to narrow things down further), but I’m a bit afraid of messing up my energy statistics.

Thanks a lot in advance! Cheers :slight_smile:

In one of recent esphome versions file structure of bin fileschanged (or something in this direction…), so it was advisable to re-flash our devices via UART to recreate file structure. Once it’s done latesr updates are fine via OTA again.

So, try flashing your ESP via uart and see…

Wow, was that for all devices? I guess I better not touch any of my other running ones for now then…
Thanks for the hint in which direction to look!

Flashing via USB equals UART and this is what @Lakini did already.

Don’t think so. What @Protoncek probably is referring to is using a esp32 with ble proxy which was flashed prior 2012.12.x(?)

As you flashed already via usb/serial the next step would be to erase the flash of your d1 mini and then flash esphome again on it to see if it comes back to life :raised_hands:

https://docs.espressif.com/projects/esptool/en/latest/esp8266/esptool/basic-commands.html#erase-flash-erase-flash-erase-region

Ok, in this case perhaps flashing via esphome’s web flasher may help? I know that first flashing of my ESP32-C3 series modules doesn’t work via USB and esp32flasher windows program, but if i flash it via esphome’s web flasher it’s ok.

thanks! i tried that now, then flashed the code again, and run into the same issue as before. Always at the part were the esp has identified the right wifi and tries to connect…

output from the esptool looked “unsuspicious”:

esptool erase_flash
esptool.py v4.4
Found 1 serial ports
Serial port COM6
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 48:3f:da:53:85:00
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 8.8s
Hard resetting via RTS pin...

I think as a next step I’ll dig a bit in my hardware box and see if I have another d1 mini laying around and flash it with the same code and see if that works…

Arg! Different board (which was running different code before succesfully, so not broken) with the same code runs into the same issue:

[07:32:54]--------------- CUT HERE FOR EXCEPTION DECODER ---------------
[07:32:54]
[07:32:54]Exception (28):
WARNING Exception type: Access to invalid address: LOAD (wild pointer?)
[07:32:54]epc1=0x4020d01b epc2=0x00000000 epc3=0x00000000 excvaddr=0x0c260000 depc=0x00000000
WARNING Decoded 0x4020d01b: esphome::wifi::WiFiComponent::wifi_sta_connect_status_()
[07:32:54]
[07:32:54]>>>stack>>>
WARNING Found stack trace! Trying to decode it
[07:32:54]
[07:32:54]ctx: cont
[07:32:54]sp: 3ffffc80 end: 3fffffc0 offset: 0190
[07:32:54]3ffffe10:  3fff1de4 4020d00c 4bc6a7f0 00000000
WARNING Decoded 0x4020d00c: esphome::wifi::WiFiComponent::wifi_sta_connect_status_()
[07:32:54]3ffffe20:  00000000 3ffef500 40100629 4020c74a
WARNING Decoded 0x40100629: millis
WARNING Decoded 0x4020c74a: esphome::wifi::WiFiComponent::check_connecting_finished()
[07:32:54]3ffffe30:  000017c3 3ffef590 3fff1894 40210012
WARNING Decoded 0x40210012: esphome::Scheduler::call()
[07:32:54]3ffffe40:  007a1200 768be3a0 3ffe8600 00000100
[07:32:54]3ffffe50:  3fff0bc4 00000012 3fff0bc4 00000100
[07:32:54]3ffffe60:  3fff0bc4 000017c3 3fff0bc4 4020c8dc
WARNING Decoded 0x4020c8dc: esphome::wifi::WiFiComponent::loop()
[07:32:54]3ffffe70:  000017c3 00000012 3ffef590 40222748
WARNING Decoded 0x40222748: esphome::Component::call_loop()
[07:32:54]3ffffe80:  00000000 3ffffea0 3ffef590 40222814
WARNING Decoded 0x40222814: esphome::Component::call()
[07:32:54]3ffffe90:  3fff0bc4 00000012 3ffef590 4020ed09
WARNING Decoded 0x4020ed09: esphome::Application::setup()
[07:32:55]3ffffea0:  00000013 00000013 3fff19fc 00000000
[07:32:55]3ffffeb0:  0000004c 00000000 00000000 00000000
[07:32:55]3ffffec0:  00000000 3ffef590 00000008 3fff123c
[07:32:55]3ffffed0:  00000084 3ffef590 00000000 402113bc
WARNING Decoded 0x402113bc: setup
[07:32:55]3ffffee0:  3fff0dfc 3fff0e00 402229a0 40210128
WARNING Decoded 0x402229a0: std::_Function_handler<esphome::optional<float> (), setup::{lambda()#7}>::_M_manager(std::_Any_data&, std::_Function_handler<esphome::optional<float> (), setup::{lambda()#7}> const&, std::_Manager_operation) at main.cpp
WARNING Decoded 0x40210128: std::_Function_handler<esphome::optional<float> (), setup::{lambda()#7}>::_M_invoke(std::_Any_data const&) at main.cpp
[07:32:55]3ffffef0:  74746177 00000000 00000000 00000000
[07:32:55]3fffff00:  3fffff08 0000000c 6b486a6a 6f65516f
[07:32:55]3fffff10:  52336259 00000000 00000000 00000000
[07:32:55]3fffff20:  00000000 00000000 00000000 00000000
[07:32:55]3fffff30:  00000000 00000000 3fffff70 00000001
[07:32:55]3fffff40:  6b486a6a 6f65516f 52336259 feefef00
[07:32:55]3fffff50:  3fffff38 00000001 3fffff38 00000001
[07:32:55]3fffff60:  3fffff38 00000001 3fffff38 00000002
[07:32:55]3fffff70:  3fff170c feefeffe feefeffe feefeffe
[07:32:55]3fffff80:  3ffef644 3fffff70 00000001 feefeffe
[07:32:55]3fffff90:  feefeffe feefeffe feefeffe 3ffef9a8
[07:32:55]3fffffa0:  3fffdad0 00000000 3ffef994 4021ed50
WARNING Decoded 0x4021ed50: loop_wrapper() at core_esp8266_main.cpp
[07:32:55]3fffffb0:  feefeffe feefeffe 3ffe8640 40100471
WARNING Decoded 0x40100471: cont_wrapper
[07:32:55]<<<stack<<<
[07:32:55]
[07:32:55]--------------- CUT HERE FOR EXCEPTION DECODER ---------------
[07:32:55]
[07:32:55] ets Jan  8 2013,rst cause:2, boot mode:(3,6)
[07:32:55]
[07:32:55]load 0x4010f000, len 3460, room 16
[07:32:55]tail 4
[07:32:55]chksum 0xcc
[07:32:55]load 0x3fff20b8, len 40, room 4
[07:32:55]tail 4
[07:32:55]chksum 0xc9
[07:32:55]csum 0xc9
[07:32:55]v00068360
[07:32:55]~ld

Okay, got it to work. On the original board, with the original code. The solution was kind of easy and annoying at the same time: in order to try out a minimal config I saved the yaml file under a different name (…_2.yaml), which resulted in esphome doing the whole compilation really from scratch, with a longer output during compiling/building. I guess before it took cached versions of some libraries, and now it didnt have those because different filename. I flashed the original code now, from a different file, with the same device name though, and everything works.
Might post some log output for documentation purposes later

Ahhhh… sorry, i totally forgot … indeed, if something goes wrong, one thing i do pretty soon is “clean build files”(hamburger icon on esphome’s basic site). Many times it solves the problem, especially when esphome is updated with some newer libraries.

Okay, so here is the part of the compilation output where it detects the difference:

esphome run power8266_2.yaml
INFO Reading configuration power8266_2.yaml...
INFO Detected timezone 'Europe/Berlin'
INFO Generating C++ source...
INFO Core config or version changed, cleaning build files...
INFO Deleting .esphome/build/power8266\.pioenvs
INFO Deleting .esphome/build/power8266\.piolibdeps
INFO Compiling app...

Command Line Interface — ESPHome would have probably done the same thing from what I understand. Well, now I know :slight_smile:

1 Like