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
14 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

You code is using the eps-idf framework, the original example is using arduino.

  • Update: Tried with only 2 binary_sensors enabled and was briefly seeing more stable tracking… but now my watch is “on”, but the phone is “off” again…

Does anyone find the ble tracking feature to be unreliable or very slow (compared to regular sized ESP32-S)? I am sitting right next to the ESP32-C3 and both my phone and watch are showing presence as off (or they flip between on/off frequently despite not moving out of the room). Thinking these little devices may only be useful to me as additional BT Proxies. Code snipped below with an example binary_sensor (I have 6 configured in total):

bluetooth_proxy:
  active: true
  
esp32_ble_tracker:
  id: ble_tracker
#  scan_parameters:       # adding/removing these 2 lines did not help
#    continuous: false

binary_sensor:
  - platform: ble_presence
    irk: xxxx
    name: "Apple Watch 10 Tracker"
    timeout: 30s
  - platform: ble_presence
    irk: xxxx
    name: "Apple iPhone 15 Tracker"
    timeout: 30s

I too am having issues (I think) with the C3 SuperMinis. Did you get this resolved or simply resort to the normal sized ESP32-S?

Trying to decide which to buy next - mode SuperMini or normal.

I gave up on using the C3 for presence or BT Proxy and currently using the full size ESP32… eg. S3.

I do still use the C3 purely for checking the battery levels of my BT Beacons. For whatever reason, when I added steps to check on the battery levels with the S3, either the battery levels would not update reliably, or other issues turned up.

This is more or less what I have for the battery level tracking on the C3 in ESPHome (I have a Home Assistant Automation that runs the script every morning):

esphome:
  name: esp32-c3
  friendly_name: EESP32-C3

  on_boot:
    priority: 250
    then:
      - delay: 15s
      - lambda: |-
          id(ble_tracker_id).set_scan_continuous(true); 
          id(ble_tracker_id).start_scan();

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

logger:

api:
  encryption:
    key: “KEY”

ota:
  - platform: esphome
    password: “PASSWORD”

esp32_ble_tracker:
  id: ble_tracker_id
  scan_parameters:
    interval: 10s
    window: 1100ms
    active: true

  on_ble_service_data_advertise:
    - mac_address: MAC1
      service_uuid: "5242"
      then:
        - lambda: |-
            ESP_LOGD("BLE", "Service Data Received: %s", format_hex_pretty(x).c_str());
            if (x.size() > 1) {
              id(henry_holyiot_beacon_tracker_battery).publish_state(x[1]);
            }
    - mac_address: MAC2
      service_uuid: "5242"
      then:
        - lambda: |-
            ESP_LOGD("BLE", "Service Data Received: %s", format_hex_pretty(x).c_str());
            if (x.size() > 1) {
              id(louie_holyiot_beacon_tracker_battery).publish_state(x[1]);

sensor:
  - platform: template
    id: henry_holyiot_beacon_tracker_battery
    name: "Henry HolyIOT Beacon Tracker Battery"
    device_class: "battery"
    unit_of_measurement: "%"
    entity_category: "diagnostic"
    accuracy_decimals: 0
  - platform: template
    id: louie_holyiot_beacon_tracker_battery
    name: "Louie HolyIOT Beacon Tracker Battery"
    device_class: "battery"
    unit_of_measurement: "%"
    entity_category: "diagnostic"
    accuracy_decimals: 0

script:
  - id: ble_active_scan
    mode: single
    then:
    - lambda: |-
        id(ble_tracker_id).stop_scan();
    - delay: 2s
    - lambda: |-
        id(ble_tracker_id).set_scan_active(true);
        id(ble_tracker_id).start_scan();
    - logger.log: 
        format: Active scan started
        level: INFO
    - delay: 30s
    - logger.log: 
        format: Active scan stopped
        level: INFO
    - lambda: |-
        id(ble_tracker_id).stop_scan();
    - delay: 2s
    - lambda: |-
        id(ble_tracker_id).set_scan_active(false);
        id(ble_tracker_id).start_scan();

button:
  - platform: template
    name: "BLE Active Scan"
    id: run_active_scan
    icon: "mdi:home-automation"
    on_press:
    - script.execute: ble_active_scan
1 Like

So far having one BLE proxy on ESP32-C3 SuperMini.
Tried on Arduion & IDF frameworks - both works fine.
To solve issue with WiFi/BLE simultenious working using following:

binary_sensor:
  - platform: template
    id: ble_scan_torun
    internal: true
    entity_category: diagnostic
    device_class: connectivity
    lambda: !lambda |-
      return global_api_server->is_connected();
    on_press:
    - esp32_ble_tracker.start_scan:
        continuous: true
    on_release:
    - esp32_ble_tracker.stop_scan:

It ensure BLE scanning starts and continues while connection from HA is established.
See no idea to run BLE scan when not possible to send data to HA.

Another option is to start BLE scan as soon WiFi is connected:

wifi:
  on_connect:
    - esp32_ble_tracker.start_scan:
        continuous: true
  on_disconnect:
    - esp32_ble_tracker.stop_scan:

@Masterzz oh, mine is a mess compared to that. Here is what is on my C3 superminis that I copied from somewhere here or on the wiki:

substitutions:
  name: esp32-bluetooth-proxy-1c9da0
  friendly_name: Bluetooth Proxy Bathroom
packages:
  esphome.bluetooth-proxy: github://esphome/bluetooth-proxies/esp32-generic/esp32-generic-c3.yaml@main
esphome:
  name: ${name}
  name_add_mac_suffix: false
  friendly_name: ${friendly_name}

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

esp32:
  board: esp32-c3-devkitm-1  # Feel free to use a more specific board if that's what you have
  framework:
    type: esp-idf  # This is important: the default "arduino" framework does not perform well.
    sdkconfig_options:
      # @grigi found in testing that these options resulted in better responsiveness.
      # BLE 4.2 is supported by ALL ESP32 boards that have bluetooth, the original and derivatives.
      CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y
      # Also enable this on any derivative boards (S2, C3 etc) but not the original ESP32.
      CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y
      # Extend the watchdog timeout, so the device reboots if the device appears locked up for over 10 seconds.
      CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10"

logger:
  baud_rate: 0  # 0 Enables logging, but disables serial-port logging to free CPU and memory

ota:
  platform: esphome

api:
  encryption:
    key: redacted
  # Only enable BLE tracking when wifi is up and api is connected
  # Gives single-core ESP32-C3 devices time to manage wifi and authenticate with api
  on_client_connected:
     - esp32_ble_tracker.start_scan:
        continuous: true
  # Disable BLE tracking when there are no api connections live
  on_client_disconnected:
    if:
      condition:
        not:
          api.connected:
      then:
        - esp32_ble_tracker.stop_scan:

esp32_ble_tracker:
  scan_parameters:
    # Don't auto start BLE scanning, we control it in the `api` block's automation.
    continuous: False
    
    active: True  # send scan-request packets to gather more info, like device name for some devices.

    interval: 320ms  # default 320ms - how long to spend on each advert channel
    window:   300ms  # default 30ms - how long to actually "listen" in each interval. Reduce this if device is unstable.
    # If the device cannot keep up or becomes unstable, reduce the "window" setting. This may be
    # required if your device is controlling other sensors or doing PWM for lights etc.

bluetooth_proxy:
  active: true  # allows outbound connections from HA to devices.

sensor:
  - platform: uptime
    # The uptime sensor is extremely helpful to know if your device is rebooting
    # when it shouldn't be. This might indicate your interval-to-window timing is
    # too tight, and the window needs to be reduced.
    name: "Uptime Sensor"
    update_interval: 60s

Hey guys, late to the party of BT tracking.
Want to use the BT devices as a replacement for my ESP8266+DFRobot SEN0395 presence sensors.

This C3: https://de.aliexpress.com/item/1005004740051202.html

My main goal is to create an dynamic HA dashboard for my phones which changes depending in which room you are.

So my question, is the C3-mini reliable for BT/BLE tracking/communication stuff?

Does