wifwucite / esphome-ble-controller Goto Github PK
View Code? Open in Web Editor NEWBluetooth Low Energy (BLE) controller for ESPHome
License: MIT License
Bluetooth Low Energy (BLE) controller for ESPHome
License: MIT License
I think I have tried really hard to find an example of how to send commands over the command channel. I don't think I understand BLE enough to even ask a sensible question. Can you please provide an example of sending commands over the command channel?
I see this communication in the PR and was under the impression that this component is integrated within esphome, possible as esp32_ble? As I checked now, it only exposes improv components
Now that ESPHome supports secure PIN pairing i tried it but the connection is failing and the "server" is not displaying the pin.
config A:
esphome:
name: esp-a
esp32:
board: esp32dev
framework:
type: arduino
logger:
api:
***
ota:
***
wifi:
***
captive_portal:
web_server:
port: 80
external_components:
- source: github://wifwucite/esphome-ble-controller
esp32_ble_controller:
security_mode: secure
on_show_pass_key:
- logger.log:
format: "pass key is %s"
args: 'pass_key.c_str()'
on_authentication_complete:
- logger.log:
format: "BLE authentication complete %d" # shows 1 on success, 0 on failure
args: 'success'
maintenance: false
on_connected:
- logger.log: "Connected."
on_disconnected:
- logger.log: "Disconnected."
config B:
esphome:
name: esp-b
esp32:
board: esp32dev
framework:
type: arduino
logger:
api:
***
ota:
***
wifi:
***
captive_portal:
web_server:
port: 80
number:
- platform: template
name: "BLE Passkey"
id: ble_passkey
step: 1
min_value: 000000
max_value: 999999
optimistic: True
on_value:
then:
- ble_client.passkey_reply:
id: ble_itag
passkey: !lambda "return (int)id(ble_passkey).state;"
esp32_ble_tracker:
scan_parameters:
interval: 10s
continuous: true
ble_client:
- mac_address: EC:62:60:9C:9E:9A
id: ble_itag
on_passkey_request:
then:
- logger.log:
format: "Waiting on passkey"
on_passkey_notification:
then:
- logger.log:
format: "Enter this passkey on your BLE device: %06d"
args: [ passkey ]
on_numeric_comparison_request:
then:
- logger.log:
format: "Compare this passkey with the one on your BLE device: %06d"
args: [ passkey ]
- ble_client.numeric_comparison_reply:
id: ble_itag
accept: True
on_connect:
then:
- lambda: |-
ESP_LOGD("ble_client_lambda", "Connected to BLE device");
on_disconnect:
then:
- lambda: |-
ESP_LOGD("ble_client_lambda", "Disconnected from BLE device");
log A:
[D] [esp32_ble_controller:491] BLE server - connected
[D] [main:274] Connected.
[D] [esp32_ble_controller:467] BLE authentication - failed
[D] [main:268] BLE authentication complete 0
[D] [esp32_ble_controller:499] BLE server - disconnected
[D] [main:280] Disconnected.
log B:
[D] [esp32_ble_tracker:245] Starting scan...
[D] [esp32_ble_client:048] [0] [EC:62:60:9C:9E:9A] Found device
[D] [esp32_ble_tracker:213] Pausing scan to make connection...
[I] [esp32_ble_client:064] [0] [EC:62:60:9C:9E:9A] 0x00 Attempting BLE connection
[I] [esp32_ble_client:265] [0] [EC:62:60:9C:9E:9A] auth complete. remote BD_ADDR: ec62609c9e9a
[E] [esp32_ble_client:268] [0] [EC:62:60:9C:9E:9A] auth fail reason = 0x66
[D] [ble_client_lambda:166] Disconnected from BLE device
[D] [esp32_ble_tracker:245] Starting scan...
I have device which receives any data (digits) using ble and showing it on lcd
I'm using sketch in arduino ide for now.
Is it possible to send any data using ble with your module? I see only switch implementation
Thanks in advance
Hi @wifwucite!
I would like to create a smart lock with ESPhome.
(I dont want to publish a beacon with my phone)
My idea is to pair my andorid phone with the esphome device, for security reasons.
I guess it will auto-connect if in range.
I need to measure the rssi value to calculate distance, then set it as a sensor value.
I can't get pairing with the core esphome ble server.
What do you think about this?
Is it possible anyway and with your controller lib?
Hi!
First of all, thanks a lot for an amazing component! It's a shame something like this is not available in the official ESPHome.
I have to ESP32 nodes, and I'm setting up one with esphome-ble-controller
to expose some sensors (indoor air quality etc), and I plan to use the other one with ble_client
to consume the data, so that it could update the attached eInk display every time it awakes from deep sleep.
The issues is that ble_client
doesn't support secure connections, and this means I'd have to run esphome-ble-controller
in an insecure mode, potentially exposing my node for others to abuse. I'm looking to address this issue either by disabling the maintenance service so that even if someone connects they can only see the sensor data, or hiding the advertisement so that it's possible to connect to esphome-ble-controller
node only if you know its MAC address.
Thanks!
src/esphome/components/esp32_ble_controller/ble_command.cpp: In member function 'virtual void esphome::esp32_ble_controller::BLECommandLogLevel::execute(const std::vector<std::__cxx11::basic_string >&) const':
src/esphome/components/esp32_ble_controller/ble_command.cpp:144:33: error: 'parse_number' was not declared in this scope
const optional level = parse_number(log_level);
^
src/esphome/components/esp32_ble_controller/ble_command.cpp:144:46: error: expected primary-expression before 'int'
const optional level = parse_number(log_level);
^
*** [.pioenvs/sound_unit/src/esphome/components/esp32_ble_controller/ble_command.cpp.o] Error 1
Hello WiFiuCite,
nice developtment and thx for you pubishing. the code handles all values of sensors in the same format. Some clients are expecting GATT - Format so Temperature GATT-ID 2A6E like uint 16 with exp -2 - so 2343 for 23.43 °C.
If you are open for futher features you I can support you with another parameter on characteristics like
- characteristic: "00002a6e-0000-1000-8000-00805f9b34fb"
exposes: s_BME_T
GATT_Format: "16_2"
I have implemted in the fork sfeli if you are courios.
Thanks another time for the well done 99% of the solution.
I am trying to expose a template switch, I get the following error
[23:58:39]Fatal exception (0): IllegalInstruction
[23:58:39]epc1=0x4008033a, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
YAML
esphome:
name: esp32bleserver
platform: ESP32
board: nodemcu-32s
wifi:
fast_connect: True
networks:
- ssid: !secret myssid
password: !secret mypass
hidden: True
captive_portal:
web_server:
port: 8080
logger:
ota:
api:
external_components:
- source: github://wifwucite/esphome-ble-controller
esp32_ble_controller:
services:
- service: "4fafc201-1fb5-459e-8fcc-c5c9c331915d"
characteristics:
- characteristic: "beb5483e-36e1-4688-b7f5-ea07361b26ab"
exposes: fanon
remote_transmitter:
pin: 3
carrier_duty_percent: 50%
climate:
- platform: daikin
id: Aircon_BLE_Server
name: "Aircon_BLE_Server"
supports_heat: false
esp32_ble_server:
switch:
- platform: template
id: fanon
turn_on_action:
- climate.control:
id: Aircon_BLE_Server
mode: FAN_ONLY
I am using this module as BLE Server quite successfully. However, I realized I would need multiple client to use this. Hence can you check if the "Exposed" switch or sensor data can be pushed as value for Advertisement data? This way I could have multiple devices utilize this. I understand that depending upon the beacon interval, the sensor data may be a bit delayed, but thats okay
I am also trying to check how can I modify to incorporate the same, but I guess you would have already though about it
I was trying to setup esphome-ble-controller
and couldn't figure out why I only saw the maintenance service.
Only after I checked logs, I realized that all the sensors I was exposing were marked as internal, and esphome-ble-controller
was ignoring them.
I think it's a common pattern to use internal [template] sensors to format data etc, so that they're available on ESP, but are not pushed to HomeAssistant.
It'd be convenient if there was a flag to tell esphome-ble-controller
that I want my internal services exposed over BLE.
Also, it'd be very helpful if log messages such as about internal components being ignored would show up in the default log from ESP (to the best of my understanding they're only shown now if higher verbosity is enabled).
Thanks!
I have few very strange BLE sockets. I've parsed on/off commands and them looks like
0x0f06030001000005ffff - on
0x0f06030000000004ffff - off
This is hex values. Can I use your library to control this sockets?
This is not an issue, but I'm trying to figure out a way, how to use this to directly communicate between two ESP32s (toggle a light directly without wifi)
Form this #4 it seems possible
server exposes switch
my goal is when client calls the switch service it would toggle the light, however I do get nothing in the log on server. I do NOT even get message Cannot write to BLE characteristic - not connected
on client if the server is not powered on.
I can't connect two devices to one ble_controller at the same time is this a limitation or a bug?
I have one esp32 that is the ble_controller and two other connecting to it.
I Just wanted to ask if it is limitation as the "normal" ble_server supports 3 connections?
Hi,
Is it possible to connect two esphome devices without displays using an encrypted BLE connection? I tried different variations of security configurations with esp32_ble_controller
and ble_client
but didn't manage to get it to work. I'm thinking on the last example in the readme with security switched on.
I am new to BLE so not sure if this question is valid or makes sense. Is there a way for this to publish a notification with data? Or is the only way to poll the data?
Hi, i saw commented lines in the code for light control, why are they commented?
Is it possible to control lighting via ble?
Good day!
The attached code I use on an ESP32 Dev Kit C only advertises 4 of the configured 6 characteristics. Battery and Temperature are missing. Pressure is missing the Descriptors.
Many Greetings!
Remo
Is there a way to get the MAC address of the BLE controller? Could it be configured, logged, or reported via maintenance service?
Thanks!
I am currently working on a project with very high energy limitations. I use BLE for sending the WiFi credentials to the device for the first time. However, the BLE service service starts at boot and does not stop (never). In my use case, the BLE server becomes useless once the device has connected to a WiFi network.
For this reason, it would be ideal to be able to turn the BLE service off and on on demand with actions like ble.enable
and ble.disable
like the existing wifi.enable
and wifi.disable
. Furthermore, I having a parameter to select if the service should start at boot or not will be ideal for further energy savings if the device has already WiFi credentials.
@wifwucite, thanks a lot for the work. I know that managing an open source project like this can be exhausting. I can help if you provide me some indications. Do you think this feature fits this project? If that is the case, do you plan adding this feature in the near future? If not, I can work on a PR, but I will need some initial guidance on where I should start.
Compiling .pioenvs\core_v2\src\esphome\components\binary_sensor\automation.cpp.o
Compiling .pioenvs\core_v2\src\esphome\components\binary_sensor\binary_sensor.cpp.o
Compiling .pioenvs\core_v2\src\esphome\components\binary_sensor\filter.cpp.o
xtensa-esp32-elf-g++: fatal error: no input files
compilation terminated.
xtensa-esp32-elf-g++: fatal error: no input files
compilation terminated.
xtensa-esp32-elf-g++: fatal error: no input files
compilation terminated.
*** [.pioenvs\core_v2\src\esphome\components\binary_sensor\automation.cpp.o] Error 1
Compiling .pioenvs\core_v2\src\esphome\components\captive_portal\captive_portal.cpp.o
*** [.pioenvs\core_v2\src\esphome\components\binary_sensor\binary_sensor.cpp.o] Error 1
*** [.pioenvs\core_v2\src\esphome\components\binary_sensor\filter.cpp.o] Error 1
xtensa-esp32-elf-g++: fatal error: no input files
compilation terminated.
*** [.pioenvs\core_v2\src\esphome\components\captive_portal\captive_portal.cpp.o] Error 1
Does this work on ESP32-C3 or any of the other variants?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.