ESP32-C3 with ble_tracker - I'm sharing how it worked

Introduction:
I have this: Wemos C3 Mini - Lolin ESP32-C3 ( C3 mini — WEMOS documentation )
I wanted to use it as a Bluetooth proxy and to use also the onboard RGB Led so I wanted an arduino platform, not esp_idf.

Problem
I was having a strange behaviour: very loooong time t oconnect to WiFi (1 … 2 or even 3 minutes) or sometimes it was even not connecting (I was restarting it until it was connecting in some minutes).
I tried and tried, various variants and … nothing.

Solution
Until … I found this answer:

Thanks chose007 :slight_smile:

The final code I have:

esphome:
  name: my-c3-mini-bt
  on_boot: #this is to avoid slow startup time because of BT and WiFi "interactions?" , check https://github.com/esphome/issues/issues/2941#issuecomment-1331851692
    priority: 250
    then:
      - delay: 15s
      - lambda: |-
          id(ble_tracker).set_scan_continuous(true); 
          id(ble_tracker).start_scan();

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: ":) :) :)"

ota:
  password: ":) :) :)"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  output_power: "8.5"  # sometimes results in a bootloop without it

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "My-C3-Mini-Bt Fallback Hotspot"
    password: ":) :) :)"

captive_portal:

esp32_ble_tracker:
  id: ble_tracker
  scan_parameters:
    continuous: false

bluetooth_proxy:
  active: true

light:
  - platform: neopixelbus
    id: myC3MiniBt_led
    type: GRB
    variant: WS2812
    method: ESP32_RMT_1
    num_leds: 1
    pin: GPIO7
    name: "My C3 Mini BT Led"
    effects:
      - addressable_rainbow:
          name: Rainbow Effect With Custom Values
          speed: 10
          width: 50
9 Likes

Thanks for sharing!
Finally got the RGB LED working on a M5stamp-C3U, for that specific board the pin is GPIO2.

Thanks for sharing this. Fixed my ESP32-C3’s WiFi connection issues. My garage door remote is now totally reliable (M5Stamp C3 + M5 3A Relay Unit).

Great find!

Thanks for sharing. My Seeed Xiao now works as my bluetooth proxy that enables my switchbot again (which failed since I installed USB3.0 SSD on HA).

However I have one observation. If i connect to my Seeed Xiao with ESPHome web through USB, it boots just fine. If I don’t do it and just plug in USB power, it doesn’t seem to boot and I can’t reach it wirelessly through esphome. That’s one weird thing. I’ll do more tests in the coming days.

I’m having the same issue. :frowning: Did you have any luck getting that sorted?

[edit] looks like there’s an issue with logger: ESPHome device does not restart without serial port active (apparently!) - #10 by tom_l

1 Like

Yeah I found that out too. However I still can’t get that resolved so I just disconnect the power and let my Seeed xiao collect dust now. I have another esp32 board serving as my bluetooth proxy now but ironically it stopped working suddenly two days ago, without me doing any software updates. Hence why I am back to this forum again.

I am still trying to turn on the RGB LED using NeoPixel, without success.
At the moment, the only way I have found to turn on the led is to ground pins 3,4 and 5. Which are Red, Green and Blue respectively.
So i’ve made this and it works:

light:
  - platform: rgb
    name: "RGB Led"
    red: output_component1
    green: output_component2
    blue: output_component3

output:
  - platform: ledc
    pin: GPIO3
    inverted: true
    id: output_component1
  - platform: ledc
    pin: GPIO4
    inverted: true
    id: output_component2
  - platform: ledc
    pin: GPIO5
    inverted: true
    id: output_component3

My board is a generic ESP32-C3-MINI-1

I found this thread, as I am trying to sort out if it actually is possible to get the BLE proxy to run on an ESP32-C3 (I have an ESP32-C3 Super Mini).

The config is like:

esphome:
  name: c3-ble-proxy
  friendly_name: c3-ble-proxy
  platformio_options:
    board_build.mcu: esp32c3
    board_build.variant: esp32c3  
  on_boot: #this is to avoid slow startup time because of BT and WiFi "interactions?" , check https://github.com/esphome/issues/issues/2941#issuecomment-1331851692
    priority: 250
    then:
      - delay: 15s
      - lambda: |-
          id(ble_tracker).set_scan_continuous(true); 
          id(ble_tracker).start_scan();

esp32:
  variant: ESP32C3
  board: esp32-c3-devkitm-1
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y
      CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y
      CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10"    


# Enable logging
logger:
  level: verbose

# Enable Home Assistant API
api:
  encryption:
    key: ":-) :-) :-)"

ota:
  password: ":-) .-) :-)"

button:
  - platform: safe_mode
    name: ${friendly_name} (Safe Mode)


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  output_power: "8.5"  # sometimes results in a bootloop without it

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "C3-Ble-Proxy Fallback Hotspot"
    password: "secret"

captive_portal:

esp32_ble_tracker:
  id: ble_tracker
  scan_parameters:
    continuous: false
    active: True

bluetooth_proxy:
  active: true

But the log after boot gives me:

[18:29:34][D][esp32_ble_tracker:266]: Starting scan...
[18:29:34][V][esp32_ble:314]: (BLE) gap_event_handler - 2
[18:29:34][V][esp32_ble:314]: (BLE) gap_event_handler - 7
[18:29:34][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[18:29:34][V][esp32_ble:314]: (BLE) gap_event_handler - 3

Any hints ?

1 Like

What about using wait_until / wifi_connected as shown at https://github.com/damex/esphome/blob/116e5836fd4fb501bb72aad9fa970cd7fb4ce512/bluetooth-proxies/weactstudio-esp32c3-core-bt-proxy.yaml#L15-L22 ? A hardcoded sleep value is bound to be flaky. Pasting here for posterity:

esphome:
  # Rest of config (...)
  on_boot:
    then:
      - wait_until:
          condition:
            wifi.connected:
      - lambda: >
          id(ble_tracker).set_scan_continuous(true);
          id(ble_tracker).start_scan();
1 Like