1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-04 04:12:23 +01:00

add custom ble name

This commit is contained in:
Tomasz Duda
2024-02-12 21:58:14 +01:00
parent 9d3bd1a2ab
commit 856191760f
2 changed files with 9 additions and 0 deletions

View File

@@ -23,4 +23,5 @@ async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
zephyr_add_prj_conf("BT", True) zephyr_add_prj_conf("BT", True)
zephyr_add_prj_conf("BT_PERIPHERAL", True) zephyr_add_prj_conf("BT_PERIPHERAL", True)
zephyr_add_prj_conf("BT_DEVICE_NAME_DYNAMIC", True)
await cg.register_component(var, config) await cg.register_component(var, config)

View File

@@ -1,6 +1,7 @@
#include "ble_server.h" #include "ble_server.h"
#include "esphome/core/defines.h" #include "esphome/core/defines.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/application.h"
#include <zephyr/bluetooth/bluetooth.h> #include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h> #include <zephyr/bluetooth/conn.h>
@@ -64,7 +65,14 @@ void BLEServer::setup() {
int rc = bt_enable(bt_ready); int rc = bt_enable(bt_ready);
if (rc != 0) { if (rc != 0) {
ESP_LOGE(TAG, "Bluetooth enable failed: %d", rc); ESP_LOGE(TAG, "Bluetooth enable failed: %d", rc);
return;
} }
rc = bt_set_name(App.get_name().c_str());
if (rc != 0) {
ESP_LOGE(TAG, "Bluetooth set name failed: %d", rc);
return;
}
} }
} // namespace zephyr_ble_server } // namespace zephyr_ble_server