Fighting esp32_ble_tracker

Hi,

I’m trying to get a ESP32 D1 Mini (which has a ESP32-WROOM chip) reliably working with esp32_ble_tracker. No ethernet, just WLAN available. I’m trying to report a bunch of Mijia sensors.

Can’t really get a good uptime, haven’t seen times over 400-500sec.
Mijia’s seem to report data okay most of the time, but sometimes reporting just “stalls”. Then esphome run log output occasionally disconnects and reconnects:

WARNING atc_001: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for atc_001
WARNING Disconnected from API
WARNING Can't connect to ESPHome API for atc_001: Error connecting to ('10.1.0.103', 6053): [Errno 111] Connect call failed ('10.1.0.103', 6053) (SocketAPIError)

GPIO2 LED occasionally starts to blink, without any esphome run log output. I might need to connect via USB…

Any help would be appreciated.

Config follows:

esphome:
  name: atc_001

esp32:
  board: wemos_d1_mini32
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: ""
  reboot_timeout: 0s

ota:
  password: ""

wifi:
  ssid: "***"
  password: "***"

web_server:
  port: 80    

light:
  - platform: status_led
    name: "Switch state"
    pin: GPIO2

dallas:
  - pin: 19

i2c:
  sda: 21
  scl: 22
  scan: true
  id: bus_a

pcf8574:
  - id: 'pcf8574_hub'
    address: 0x20
    pcf8575: false

# Individual outputs
#switch:
#  - platform: gpio
#    name: "PCF8574 Pin #0"
#    pin:
#      pcf8574: pcf8574_hub
#      # Use pin number 0
#      number: 0
#      # One of INPUT or OUTPUT
#      mode:
#        output: true
#      inverted: false

esp32_ble_tracker:
  
  on_ble_advertise:
    - mac_address:
        - "A4:C1:38:F1:88:B5"
        - "A4:C1:38:44:BB:75"
        - "A4:C1:38:06:FB:DE"
      then:
        - lambda: |-
            ESP_LOGD("ble_adv", "New BLE device");
            ESP_LOGD("ble_adv", "  address: %s", x.address_str().c_str());
            ESP_LOGD("ble_adv", "  name: %s", x.get_name().c_str());

  scan_parameters:
    interval: 300ms # try with 300ms if you don't have LAN module
    window: 250ms # try with 300ms if you don't have LAN module
    active: false

sensor:
  - platform: uptime
    name: Uptime Sensor

  - platform: dallas
    address: 0x5365446f0e64ff28
    name: "box"

  - platform: pvvx_mithermometer
    mac_address: "A4:C1:38:F1:88:B5"
    temperature:
      name: "88:B5 Temperature"
    humidity:
      name: "88:B5 Humidity"
    battery_level:
      name: "88:B5 Battery-Level"
    battery_voltage:
      name: "88:B5 Battery-Voltage"
    signal_strength:
      name: "88:B5 Signal"

  - platform: pvvx_mithermometer
    mac_address: "A4:C1:38:44:BB:75"
    temperature:
      name: "BB:75 Temperature"
    humidity:
      name: "BB:75 Humidity"
    battery_level:
      name: "BB:75 Battery-Level"
    battery_voltage:
      name: "BB:75 Battery-Voltage"
    signal_strength:
      name: "BB:75 Signal"

  - platform: pvvx_mithermometer
    mac_address: "A4:C1:38:06:FB:DE"
    temperature:
      name: "FB:DE Temperature"
    humidity:
      name: "FB:DE Humidity"
    battery_level:
      name: "FB:DE Battery-Level"
    battery_voltage:
      name: "FB:DE Battery-Voltage"
    signal_strength:
      name: "FB:DE Signal"

Looks like having the web UI open and listening OR esphome logs <config> breaks it.
Leaving it all alone makes it happy, uptime now ~21hrs and counting.