ESPHome BLE Gateway and other BLE components

@micturkey @mundschenk-at @pplucky As @Ernst mention here I think we have a good chance to have this working in next releases.

1 Like

The devs are currently looking into this, on discord. I told them about ESPhome gateway and will probably take this as an example. @myhomeiot if you want to join the discussion on discord, let me know your username (including the number)

3 Likes

I have a USB Bluetooth dongle in my HA server and pick up BLE sensors via the passive BLE monitor in HACS.

Now this doesn’t pick up all the sensors in the house and I want to use the ESPHome BLE Gateway to forward BLE data to the passive BLE monitor which reading the above should be possible.

However when updating the code to the following

esp32_ble_tracker:

ble_gateway:
  devices:
    - mac_address: 01:23:45:67:89:AB
  on_ble_advertise:
    then:
      homeassistant.event:
        event: esphome.on_ble_advertise
        data:
          packet: !lambda return packet;

I get an error in the editor that the component ble_gateway is not found. Just using esp32_ble_tracker: I can see on the console that the ESP32 sees the sensors I’m interested in.

What’s missing to enable the component ble_gateway?

Hello, you missing this from README:

To use this repository you should confugure it inside your yaml-configuration:

external_components:
  - source: github://myhomeiot/esphome-components

Oops, totally overseen this. The ESPHome build completed and firmware flashed. txs!

However nothing seems to appear on the Home Assistant end. If I understand this correctly I should see the newly discovered MAC addresses at the bottom of the passive BLE monitor configuration pop-up. However I don’t see any new ones.
image

What I do have in the ESPHome log are these api errors. Not sure this stops the BLE data from being sent to Home Assistant.

[23:04:51][D][api:102]: Accepted ::FFFF:C0A8:262
[23:04:52][W][api.connection:068]: ::FFFF:C0A8:262: Socket operation failed: CONNECTION_CLOSED errno=128
[23:03:23][C][ota:085]: Over-The-Air Updates:
[23:03:23][C][ota:086]:   Address: fsh-ble-gw01.local:3232
[23:03:23][C][ota:089]:   Using Password.
[23:03:23][C][api:138]: API Server:
[23:03:23][C][api:139]:   Address: fsh-ble-gw01.local:6053
[23:03:23][C][api:141]:   Using noise encryption: YES
[23:03:30][D][esp32_ble_tracker:726]: Found device XX:XX:XX:BF:8D:12 RSSI=-91
[23:03:30][D][esp32_ble_tracker:747]:   Address Type: RANDOM
[23:03:30][D][esp32_ble_tracker:749]:   Name: 'paula's g-home mini'
[23:03:51][D][api:102]: Accepted ::FFFF:C0A8:262
[23:03:51][W][api.connection:068]: ::FFFF:C0A8:262: Socket operation failed: CONNECTION_CLOSED errno=128
[23:03:53][D][esp32_ble_tracker:726]: Found device XX:XX:XX:09:FC:E9 RSSI=-94
[23:03:53][D][esp32_ble_tracker:747]:   Address Type: RANDOM
[23:03:53][D][esp32_ble_tracker:749]:   Name: 'paula's g-home mini'
[23:04:32][D][esp32_ble_tracker:726]: Found device XX:XX:XX:07:6E:28 RSSI=-86
[23:04:32][D][esp32_ble_tracker:747]:   Address Type: RANDOM
[23:04:32][D][esp32_ble_tracker:751]:   TX Power: 2
[23:04:37][D][esp32_ble_tracker:726]: Found device XX:XX:XX:34:EF:40 RSSI=-89
[23:04:37][D][esp32_ble_tracker:747]:   Address Type: PUBLIC
[23:04:37][D][esp32_ble_tracker:749]:   Name: 'ATC_34EF40'
[23:04:45][D][esp32_ble_tracker:726]: Found device XX:XX:XX:70:52:DE RSSI=-80
[23:04:45][D][esp32_ble_tracker:747]:   Address Type: PUBLIC
[23:04:45][D][esp32_ble_tracker:749]:   Name: 'ATC_7052DE'
[23:04:51][D][api:102]: Accepted ::FFFF:C0A8:262
[23:04:52][W][api.connection:068]: ::FFFF:C0A8:262: Socket operation failed: CONNECTION_CLOSED errno=128
[23:05:52][D][api:102]: Accepted ::FFFF:C0A8:262
[23:05:52][W][api.connection:068]: ::FFFF:C0A8:262: Socket operation failed: CONNECTION_CLOSED errno=128
[23:06:06][D][esp32_ble_tracker:726]: Found device XX:XX:XX:37:5E:90 RSSI=-92
[23:06:06][D][esp32_ble_tracker:747]:   Address Type: RANDOM
[23:06:52][D][api:102]: Accepted ::FFFF:C0A8:262
[23:06:52][W][api.connection:068]: ::FFFF:C0A8:262: Socket operation failed: CONNECTION_CLOSED errno=128
[23:07:52][D][api:102]: Accepted ::FFFF:C0A8:262
[23:07:52][W][api.connection:068]: ::FFFF:C0A8:262: Socket operation failed: CONNECTION_CLOSED errno=128
[23:07:52][I][ota:105]: Boot seems successful, resetting boot loop counter.
1 Like

api.connection errors can stop BLE data because BLE gateway use HA API events/service to send BLE packet data into HA. You should see the BLE packets in the ESPHome log. You can try do disable ESPHome encryption it’s can cause the connection problem.

Also be sure that you have all necessary parts in place in HA and ESPHome according instruction. You can also check advanced configuration examples here esphome.yaml ESPHome part, homeassistant.yaml - Home Assistant part.

Hope this helps.

@myhomeiot I tried your mi band config but I cant get it to work.
In logs there are error: OPEN_EVT failed, status (133), app_id (1)
Battery entites are unknown:
band

I really love your work, many thanks for that.

I think the Home Assistant side BLE Gateway binary sensor device attribute can be simplified with the following code

my version, just disabling the extra audodiscovery step:

{{ expand(integration_entities('ble_monitor')) | map(attribute='attributes.mac_address')
| unique | sort | join('') | replace(':', '') | trim }}

OR with the autodiscovery added:

{{ 
(expand(integration_entities('ble_monitor')) | map(attribute='attributes.mac_address') | unique | sort | join('') ~ states('input_text.settings_ble_gateway_add_device')) 
| replace(':', '') | trim 
if is_state('binary_sensor.ble_gateway', 'on')
}}

Yes, looks like it’s works worse (I still get data from MiBand after 10-12 hours), in latest releases of ESPHome, they made lot of changes in BLE for Bluetooth proxy and Active Bluetooth. I will check what can be done, but probably next right step will be to create integration in HA for MiBand using Active Bluetooth.

ESPHome - bluetooth_proxy
 on 2022.9.1 bluetooth_proxy works and the code compiles and installs, when I upgraded to 2022.9.2 and .3 it doesn’t it errors at the below.
I have restored from backup, upgraded HA Core to the latest but cannot find any reason for it. The code is simple

esp32_ble_tracker:
bluetooth_proxy:
  active: true

and omit active: true on 2022.9.1
This is part of the error


Error.log

INFO Reading configuration /config/esphome/blehub1.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing blehub1 (board: esp32dev; framework: arduino; platform: platformio/espressif32 @ 3.5.0)
--------------------------------------------------------------------------------
Library Manager: Installing Hash
INFO Installing Hash
Library Manager: Installing ESP8266WiFi
INFO Installing ESP8266WiFi
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- AsyncTCP-esphome @ 1.2.2
|-- WiFi @ 1.0
|-- FS @ 1.0
|-- Update @ 1.0
|-- ESPAsyncWebServer-esphome @ 2.1.0
|   |-- AsyncTCP-esphome @ 1.2.2
|-- DNSServer @ 1.1.0
|-- ESPmDNS @ 1.0
Compiling /data/blehub1/.pioenvs/blehub1/src/esphome/components/api/api_connection.cpp.o
Compiling /data/blehub1/.pioenvs/blehub1/src/esphome/components/api/subscribe_state.cpp.o
Compiling /data/blehub1/.pioenvs/blehub1/src/esphome/components/api/user_services.cpp.o
Compiling /data/blehub1/.pioenvs/blehub1/src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp.o
In file included from src/esphome/components/bluetooth_proxy/bluetooth_proxy.h:7:0,
                 from src/esphome/components/api/api_connection.cpp:16:
src/esphome/components/esp32_ble_client/ble_client_base.h:33:8: error: 'void esphome::esp32_ble_client::BLEClientBase::gap_event_handler(esp_gap_ble_cb_event_t, esp_ble_gap_cb_param_t*)' marked 'override', but does not override
   void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override;
        ^
Compiling /data/blehub1/.pioenvs/blehub1/src/esphome/components/captive_portal/captive_portal.cpp.o
*** [/data/blehub1/.pioenvs/blehub1/src/esphome/components/api/api_connection.cpp.o] Error 1
In file included from src/esphome/components/bluetooth_proxy/bluetooth_proxy.h:7:0,
                 from src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:1:
src/esphome/components/esp32_ble_client/ble_client_base.h:33:8: error: 'void esphome::esp32_ble_client::BLEClientBase::gap_event_handler(esp_gap_ble_cb_event_t, esp_ble_gap_cb_param_t*)' marked 'override', but does not override
   void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override;
        ^
src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp: In member function 'virtual void esphome::bluetooth_proxy::BluetoothProxy::loop()':
src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:161:40: error: 'class esphome::esp32_ble_tracker::ESPBTUUID' has no member named 'get_128bit_high'
     service_resp.uuid = {service->uuid.get_128bit_high(), service->uuid.get_128bit_low()};
                                        ^
src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:161:73: error: 'class esphome::esp32_ble_tracker::ESPBTUUID' has no member named 'get_128bit_low'
     service_resp.uuid = {service->uuid.get_128bit_high(), service->uuid.get_128bit_low()};
                                                                         ^
src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:161:23: error: no match for 'operator=' (operand types are 'std::vector<long long unsigned int>' and '<brace-enclosed initializer list>')
     service_resp.uuid = {service->uuid.get_128bit_high(), service->uuid.get_128bit_low()};
                       ^
In file included from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/vector:69:0,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/random.h:34,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/random:49,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_algo.h:66,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/algorithm:62,
                 from src/esphome/core/optional.h:19,
                 from src/esphome/core/component.h:7,
                 from src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.h:3,
                 from src/esphome/components/esp32_ble_client/ble_client_base.h:5,
                 from src/esphome/components/bluetooth_proxy/bluetooth_proxy.h:7,
                 from src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:1:
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/vector.tcc:167:5: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long unsigned int; _Alloc = std::allocator<long long unsigned int>]
     vector<_Tp, _Alloc>::
     ^
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/vector.tcc:167:5: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<long long unsigned int>&'
In file included from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/vector:64:0,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/random.h:34,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/random:49,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_algo.h:66,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/algorithm:62,
                 from src/esphome/core/optional.h:19,
                 from src/esphome/core/component.h:7,
                 from src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.h:3,
                 from src/esphome/components/esp32_ble_client/ble_client_base.h:5,
                 from src/esphome/components/bluetooth_proxy/bluetooth_proxy.h:7,
                 from src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:1:
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:448:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long unsigned int; _Alloc = std::allocator<long long unsigned int>]
       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
       ^
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:448:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<long long unsigned int>&&'
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:470:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long unsigned int; _Alloc = std::allocator<long long unsigned int>]
       operator=(initializer_list<value_type> __l)
       ^
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:470:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<long long unsigned int>'
src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:165:56: error: 'class esphome::esp32_ble_tracker::ESPBTUUID' has no member named 'get_128bit_high'
       characteristic_resp.uuid = {characteristic->uuid.get_128bit_high(), characteristic->uuid.get_128bit_low()};
                                                        ^
src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:165:96: error: 'class esphome::esp32_ble_tracker::ESPBTUUID' has no member named 'get_128bit_low'
       characteristic_resp.uuid = {characteristic->uuid.get_128bit_high(), characteristic->uuid.get_128bit_low()};
                                                                                                ^
src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:165:32: error: no match for 'operator=' (operand types are 'std::vector<long long unsigned int>' and '<brace-enclosed initializer list>')
       characteristic_resp.uuid = {characteristic->uuid.get_128bit_high(), characteristic->uuid.get_128bit_low()};
                                ^
In file included from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/vector:69:0,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/random.h:34,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/random:49,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_algo.h:66,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/algorithm:62,
                 from src/esphome/core/optional.h:19,
                 from src/esphome/core/component.h:7,
                 from src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.h:3,
                 from src/esphome/components/esp32_ble_client/ble_client_base.h:5,
                 from src/esphome/components/bluetooth_proxy/bluetooth_proxy.h:7,
                 from src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:1:
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/vector.tcc:167:5: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long unsigned int; _Alloc = std::allocator<long long unsigned int>]
     vector<_Tp, _Alloc>::
     ^
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/vector.tcc:167:5: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<long long unsigned int>&'
In file included from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/vector:64:0,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/random.h:34,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/random:49,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_algo.h:66,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/algorithm:62,
                 from src/esphome/core/optional.h:19,
                 from src/esphome/core/component.h:7,
                 from src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.h:3,
                 from src/esphome/components/esp32_ble_client/ble_client_base.h:5,
                 from src/esphome/components/bluetooth_proxy/bluetooth_proxy.h:7,
                 from src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:1:
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:448:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long unsigned int; _Alloc = std::allocator<long long unsigned int>]
       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
       ^
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:448:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<long long unsigned int>&&'
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:470:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long unsigned int; _Alloc = std::allocator<long long unsigned int>]
       operator=(initializer_list<value_type> __l)
       ^
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:470:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<long long unsigned int>'
src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:170:50: error: 'class esphome::esp32_ble_tracker::ESPBTUUID' has no member named 'get_128bit_high'
         descriptor_resp.uuid = {descriptor->uuid.get_128bit_high(), descriptor->uuid.get_128bit_low()};
                                                  ^
src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:170:86: error: 'class esphome::esp32_ble_tracker::ESPBTUUID' has no member named 'get_128bit_low'
         descriptor_resp.uuid = {descriptor->uuid.get_128bit_high(), descriptor->uuid.get_128bit_low()};
                                                                                      ^
src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:170:30: error: no match for 'operator=' (operand types are 'std::vector<long long unsigned int>' and '<brace-enclosed initializer list>')
         descriptor_resp.uuid = {descriptor->uuid.get_128bit_high(), descriptor->uuid.get_128bit_low()};
                              ^
In file included from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/vector:69:0,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/random.h:34,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/random:49,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_algo.h:66,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/algorithm:62,
                 from src/esphome/core/optional.h:19,
                 from src/esphome/core/component.h:7,
                 from src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.h:3,
                 from src/esphome/components/esp32_ble_client/ble_client_base.h:5,
                 from src/esphome/components/bluetooth_proxy/bluetooth_proxy.h:7,
                 from src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:1:
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/vector.tcc:167:5: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long unsigned int; _Alloc = std::allocator<long long unsigned int>]
     vector<_Tp, _Alloc>::
     ^
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/vector.tcc:167:5: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<long long unsigned int>&'
In file included from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/vector:64:0,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/random.h:34,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/random:49,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_algo.h:66,
                 from /data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/algorithm:62,
                 from src/esphome/core/optional.h:19,
                 from src/esphome/core/component.h:7,
                 from src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.h:3,
                 from src/esphome/components/esp32_ble_client/ble_client_base.h:5,
                 from src/esphome/components/bluetooth_proxy/bluetooth_proxy.h:7,
                 from src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp:1:
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:448:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long unsigned int; _Alloc = std::allocator<long long unsigned int>]
       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
       ^
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:448:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<long long unsigned int>&&'
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:470:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long unsigned int; _Alloc = std::allocator<long long unsigned int>]
       operator=(initializer_list<value_type> __l)
       ^
/data/cache/platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:470:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<long long unsigned int>'
*** [/data/blehub1/.pioenvs/blehub1/src/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp.o] Error 1
========================== [FAILED] Took 6.31 seconds ==========================
1 Like

BLE Gateway it’s a not bluetooth_proxy even bluetooth_proxy based on same idea as BLE Gateway and from version 2022.9 code from BLE Monitor integrated into HA.

Looks like previously compiled files make your problem, try to delete pre-compiled folder inside ESPHome container /data/blehub1/.pioenvs/blehub1 or completely uninstall ESPHome addon and install it again. Hope this helps.

Thanks for your code, I will add it into README of the project! My code much more complicated because integration_entities wan’t available in HA 2022.1.

Hey, I have removed and installed ESPHome but didn’t make sure all the files were removed before reinstalling it, i’ll give that ago and thanks for your help, I should know better :slight_smile:

Thank you for your help!!
So I did this and it works now


external_components:
  - source: github://myhomeiot/esphome-components
#  - source: github://pr#2854
#    components: [esp32_ble_tracker]

esp32_ble_tracker:
bluetooth_proxy:
  active: true
1 Like

If you use bluetooth_proxy you don’t need the lines above, you can remove them.

1 Like

Yup, I tried that, well also started from scratch which was easy and now it all works
really well :slight_smile: thanks for your help, epic as always

OK, going out on a limb and hoping this is the correct place to ask. Im an experience HA user that has just started to play with ESPHome. I have two ESP32 boards that I have successfully flashed and would like to use to extend the range of the iBeaconTrascker. I have two BlueCharm BC021 beacons that work moderately well with just iBeaconTracker. I would like to configure the ESP32 boards to extend that range and it looks like the BLE Gateway would be the tool for the job. Problem is, as a newbie at ESPHome, I’m ALOT unsure what code goes where and if Im on the right track. In addition, it seems like changes are in the works and some things are a little confusing in terms of what’s required. So two questions:

  1. Am I on the right track with this approach? If not, what is a better approach?
  2. Is someone willing to help me with which pieces of code go where and what/how do I install the necessary components. Yes, I’ve read a lot about the ESP Home components on GitHub but there’s a lot Im still unfamiliar with. A little guidance would help me avoid the trial and error approach.
    As always I appreciate any advice or guidance from users who are more comfortable with ESPHome and the add on components.

Thanks!!

If you already track your iBeacon’s using Home Assistant and build in Bluetooth or Bluetooth dongle I suggest you start from ESPHome Bluetooth Proxy it’s has installer site which allow you install and try it without any additional knowledge.

This BLE Gateway and the idea on which it is based was the predecessor of ESPHome Bluetooth Proxy which is now a part of ESPHome. So if you are new for it and don’t use BLE Passive Monitor integration, I suggest you to start from ESPHome Bluetooth Proxy.

Hope this helps.

:nerd_face: My first post
I have read post after post, and cannot get it. I have modified this code to use a DHT11,
:point_right:Here is the code for the esp32 server:

/*********
  Rui Santos
  Complete instructions at https://RandomNerdTutorials.com/esp32-ble-server-client/
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*********/

#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>

#include "DHT.h"
#define DHTTYPE DHT11  // DHT 11
#define dht_PIN 4      // Saras Room
DHT dht(dht_PIN, DHTTYPE);


//BLE server name
#define bleServerName "Temperature_ESP32"

float temp;
float tempF;
float hum;

// Timer variables
unsigned long lastTime = 0;
unsigned long timerDelay = 30000;

bool deviceConnected = false;

// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
#define SERVICE_UUID "91bad492-b950-4226-aa2b-4ede9fa42f59"

// Temperature Characteristic and Descriptor
#ifdef temperatureCelsius
BLECharacteristic dhtTemperatureCelsiusCharacteristics("cba1d466-344c-4be3-ab3f-189f80dd7518", BLECharacteristic::PROPERTY_NOTIFY);
BLEDescriptor dhtTemperatureCelsiusDescriptor(BLEUUID((uint16_t)0x2902));
#else
BLECharacteristic dhtTemperatureFahrenheitCharacteristics("f78ebbff-c8b7-4107-93de-889a6a06d408", BLECharacteristic::PROPERTY_NOTIFY);
BLEDescriptor dhtTemperatureFahrenheitDescriptor(BLEUUID((uint16_t)0x2901));
#endif

// Humidity Characteristic and Descriptor
BLECharacteristic dhtHumidityCharacteristics("ca73b3ba-39f6-4ab3-91ae-186dc9577d99", BLECharacteristic::PROPERTY_NOTIFY);
BLEDescriptor dhtHumidityDescriptor(BLEUUID((uint16_t)0x2903));

//Setup callbacks onConnect and onDisconnect
class MyServerCallbacks : public BLEServerCallbacks {
  void onConnect(BLEServer *pServer) {
    deviceConnected = true;
  };
  void onDisconnect(BLEServer *pServer) {
    deviceConnected = false;
  }
};


void setup() {
  // Start serial communication
  Serial.begin(115200);

  // Init dht Sensor
  //initdht();
  dht.begin();
  // Create the BLE Device
  BLEDevice::init(bleServerName);

  // Create the BLE Server
  BLEServer *pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());

  // Create the BLE Service
  BLEService *dhtService = pServer->createService(SERVICE_UUID);

// Create BLE Characteristics and Create a BLE Descriptor
// Temperature
#ifdef temperatureCelsius
  dhtService->addCharacteristic(&dhtTemperatureCelsiusCharacteristics);
  dhtTemperatureCelsiusDescriptor.setValue("dht temperature Celsius");
  dhtTemperatureCelsiusCharacteristics.addDescriptor(&dhtTemperatureCelsiusDescriptor);
#else
  dhtService->addCharacteristic(&dhtTemperatureFahrenheitCharacteristics);
  dhtTemperatureFahrenheitDescriptor.setValue("dht temperature Fahrenheit");
  dhtTemperatureFahrenheitCharacteristics.addDescriptor(&dhtTemperatureFahrenheitDescriptor);
#endif

  // Humidity
  dhtService->addCharacteristic(&dhtHumidityCharacteristics);
  dhtHumidityDescriptor.setValue("dht humidity");
  dhtHumidityCharacteristics.addDescriptor(new BLE2902());

  // Start the service
  dhtService->start();

  // Start advertising
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pServer->getAdvertising()->start();
  Serial.println("Waiting a client connection to notify...");
}

void loop() {
  if (deviceConnected) {
    if ((millis() - lastTime) > timerDelay) {
      // Read temperature as Celsius (the default)
      temp = dht.readTemperature();
      // Fahrenheit
      tempF = 1.8 * temp + 32;
      // Read humidity
      hum = dht.readHumidity();

//Notify temperature reading from DHT sensor
#ifdef temperatureCelsius
      static char temperatureCTemp[6];
      dtostrf(temp, 6, 2, temperatureCTemp);
      //Set temperature Characteristic value and notify connected client
      dhtTemperatureCelsiusCharacteristics.setValue(temperatureCTemp);
      dhtTemperatureCelsiusCharacteristics.notify();
      Serial.print("Temperature Celsius: ");
      Serial.print(temp);
      Serial.print(" ÂșC");
#else
      static char temperatureFTemp[6];
      dtostrf(tempF, 6, 2, temperatureFTemp);
      //Set temperature Characteristic value and notify connected client
      dhtTemperatureFahrenheitCharacteristics.setValue(temperatureFTemp);
      dhtTemperatureFahrenheitCharacteristics.notify();
      Serial.print("Temperature Fahrenheit: ");
      Serial.print(tempF);
      Serial.print(" ÂșF");
#endif

      //Notify humidity reading from dht
      static char humidityTemp[6];
      dtostrf(hum, 6, 2, humidityTemp);
      //Set humidity Characteristic value and notify connected client
      dhtHumidityCharacteristics.setValue(humidityTemp);
      dhtHumidityCharacteristics.notify();
      Serial.print(" - Humidity: ");
      Serial.print(hum);
      Serial.println(" %");

      lastTime = millis();
    }
  }
}

:point_right: Here is my ESPhome Yaml:

esphome:
  name: myble-client

esp32:
  board: wemos_d1_mini32
  framework:
    type: arduino

# Enable Home Assistant API
api:
  encryption:
    key: "gdOpgYZcDBnLlk9GJ46i4iOtmh3pS3hcC9dHjwI/0EI="

wifi:
  ssid: "DD_***"
  password: "****"
  manual_ip:
    static_ip: 192.168.3.160
    gateway: 192.168.3.1
    subnet: 255.255.255.0
    #dns1: 192.168.3.1
    #dns2: 8.8.8.8

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

captive_portal:

# Enable logging
logger:

ota:
  password: "***"

web_server:
  port: 80
  ota: true

esp32_ble_tracker:

ble_client:
  - mac_address: 78:E3:6D:10:6D:BA
    id: my_ble_client  
    on_connect:
      then:
        - lambda: |-
            ESP_LOGD("ble_client_lambda", "Connected to BLE device");

text_sensor:
  - platform: template
    name: "My_Esp_Tmp_Atmpt"
    
  - platform: ble_client
    ble_client_id: 
    id: my_ble_client1
    name: "Humidity"
    service_uuid: "91bad492-b950-4226-aa2b-4ede9fa42f59"  # Humidity
    characteristic_uuid: "ca73b3ba-39f6-4ab3-91ae-186dc9577d99"  
    notify: true

  - platform: ble_client
    ble_client_id: 
    id: my_ble_client2
    name: "Temperature"
    service_uuid: "91bad492-b950-4226-aa2b-4ede9fa42f59"  # Temperarure
    characteristic_uuid: "f78ebbff-c8b7-4107-93de-889a6a06d408"  
    notify: true

This is the web page from the esp32-server:

How do I turn the Temp. and Humid. results into a home-assistant sensor or (entity) such as:
ESPHOME_TMP_SENSOR

I want to thank all who contribute to these forums, IT IS A HUGE ADVANTAGE TO US WANA-BEE PROGRAMMERS!

Please have mercy on me. The post complaines about unformatted text, I posted anyway because it looks fine to me. Let me know if I did somthing wrong please.

1 Like

Try ESPHome 2022.10.1, without any changes it’s start works much better.