#include "ble_service.h"
#include "ble_config.h" // 假设你自己实现了该配置模块
#include "esp_log.h"
#include "esp_nimble_hci.h"
#include "nimble/nimble_port.h"
#include "nimble/nimble_port_freertos.h"
#include "host/ble_hs.h"
#include "host/util/util.h"
#include "services/gap/ble_svc_gap.h"
#include "services/gatt/ble_svc_gatt.h"
#include <string.h>
#include <stdio.h>
// 如果你没有实现 ble_at_parse,请注释掉相关逻辑或替换为 dummy 函数
extern esp_err_t ble_at_parse(const char *at_cmd); // 声明外部 AT 解析函数
static const char *TAG = "BLE_SERVICE";
// -------------------------------
// UUID 定义:Nordic UART Service (NUS) 风格
// -------------------------------
// 主服务 UUID: 6E400001-B5A3-F393-E0A9-E50E24DCCA9E
static const ble_uuid128_t gatt_svr_svc_uuid = BLE_UUID128_INIT(
0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0,
0x93, 0xF3, 0xA3, 0xB5, 0x01, 0x00, 0x40, 0x6E);
// 写特征 UUID: 6E400002-B5A3-F393-E0A9-E50E24DCCA9E
static const ble_uuid128_t gatt_svr_chr_write_uuid = BLE_UUID128_INIT(
0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0,
0x93, 0xF3, 0xA3, 0xB5, 0x02, 0x00, 0x40, 0x6E);
// 读特征 UUID: 6E400003-B5A3-F393-E0A9-E50E24DCCA9E
static const ble_uuid128_t gatt_svr_chr_read_uuid = BLE_UUID128_INIT(
0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0,
0x93, 0xF3, 0xA3, 0xB5, 0x03, 0x00, 0x40, 0x6E);
// -------------------------------
// 全局变量
// -------------------------------
static ble_event_callback_t g_event_callback = NULL;
static bool g_service_started = false;
static bool g_device_connected = false;
static uint16_t g_conn_handle = 0;
// ⚠️ 关键:必须用指针接收 handle 分配!
static uint16_t g_rx_val_handle; // 接收写入的 Characteristic Value Handle
static uint16_t g_tx_val_handle; // 发送通知的 Characteristic Value Handle
#define BLE_DATA_BUFFER_SIZE 512
static uint8_t g_data_buffer[BLE_DATA_BUFFER_SIZE];
// -------------------------------
// GATT 访问回调函数
// -------------------------------
/**
* @brief 处理客户端对 WRITE 特征的写操作
*/
static int
characteristic_write_cb(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg)
{
if (ctxt->op != BLE_GATT_ACCESS_OP_WRITE_CHR) {
return BLE_ATT_ERR_UNLIKELY;
}
size_t data_len = OS_MBUF_PKTLEN(ctxt->om);
if (data_len == 0 || data_len >= BLE_DATA_BUFFER_SIZE) {
return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
}
// 将 mbuf 数据拷贝到缓冲区
int rc = ble_hs_mbuf_to_flat(ctxt->om, g_data_buffer, BLE_DATA_BUFFER_SIZE, &data_len);
if (rc != 0) {
ESP_LOGE(TAG, "Failed to flatten mbuf: %d", rc);
return BLE_ATT_ERR_UNLIKELY;
}
g_data_buffer[data_len] = '\0';
ESP_LOGI(TAG, "Received write: %.*s", (int)data_len, g_data_buffer);
// 根据当前模式处理
if (ble_config_get_mode() == BLE_MODE_CONFIG) {
if (strcmp((char*)g_data_buffer, "+++") == 0) {
ble_config_set_mode(BLE_MODE_CONFIG);
if (g_event_callback) {
g_event_callback(BLE_EVENT_CONFIG_MODE_ENTERED, NULL, 0);
}
ble_service_send_string("OK\r\n");
} else if (strncmp((char*)g_data_buffer, "AT+", 3) == 0) {
esp_err_t ret = ble_at_parse((char*)g_data_buffer);
ble_service_send_string(ret == ESP_OK ? "OK\r\n" : "ERR\r\n");
}
} else {
if (g_event_callback) {
g_event_callback(BLE_EVENT_DATA_RECEIVED, g_data_buffer, data_len);
}
}
return 0;
}
/**
* @brief 处理 READ 特征的读请求(可选)
*/
static int
characteristic_read_cb(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg)
{
// 示例:返回静态字符串
const char *response = "Hello from BLE";
int len = strlen(response);
os_mbuf_append(ctxt->om, response, len);
return 0;
}
// -------------------------------
// GATT 服务定义
// -------------------------------
static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
{
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = &gatt_svr_svc_uuid.u,
.characteristics = (struct ble_gatt_chr_def[]) {
[0] = {
.uuid = &gatt_svr_chr_write_uuid.u,
.access_cb = characteristic_write_cb,
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ,
},
[1] = {
.uuid = &gatt_svr_chr_read_uuid.u,
.access_cb = characteristic_read_cb,
.flags = BLE_GATT_CHR_F_NOTIFY | BLE_GATT_CHR_F_READ,
.val_handle = &g_tx_val_handle, // ✅ 自动填充 handle
},
[2] = { 0 } // End of characteristics
}
},
{
0 // End of services
}
};
// -------------------------------
// GAP 事件处理器
// -------------------------------
static int
gap_event_handler(struct ble_gap_event *event, void *arg)
{
switch (event->type) {
case BLE_GAP_EVENT_CONNECT:
ESP_LOGI(TAG, "BLE connected");
g_conn_handle = event->connect.conn_handle;
g_device_connected = true;
struct ble_gap_conn_desc desc;
int rc = ble_gap_conn_find(g_conn_handle, &desc);
if (rc == 0) {
ESP_LOGI(TAG, "Conn interval=%dms latency=%d timeout=%dms",
desc.conn_itvl * 1.25,
desc.conn_latency,
desc.supervision_timeout * 10);
}
if (g_event_callback) {
g_event_callback(BLE_EVENT_CONNECTED, NULL, 0);
}
break;
case BLE_GAP_EVENT_DISCONNECT:
ESP_LOGI(TAG, "Disconnected, reason=%d", event->disconnect.reason);
g_device_connected = false;
g_conn_handle = 0;
g_tx_val_handle = 0; // Reset handle
if (g_event_callback) {
g_event_callback(BLE_EVENT_DISCONNECTED, NULL, 0);
}
// 可选择重新广播
if (g_service_started) {
ble_service_start();
}
break;
case BLE_GAP_EVENT_ADV_COMPLETE:
ESP_LOGI(TAG, "Advertising stopped");
break;
case BLE_GAP_EVENT_SUBSCRIBE:
ESP_LOGI(TAG, "Client subscribed to notify: val_handle=%d new_value=%d",
g_tx_val_handle, event->subscribe.cur_notify);
break;
default:
break;
}
return 0;
}
// -------------------------------
// NimBLE 同步与重置回调
// -------------------------------
static void
ble_on_sync(void)
{
ESP_LOGI(TAG, "BLE Host synced");
// 获取设备名
char device_name[64] = {0};
ble_config_get_param("BLE_NAME", device_name, sizeof(device_name));
if (strlen(device_name) == 0) {
strcpy(device_name, "SUPER BLE123");
}
ble_svc_gap_device_name_set(device_name);
// 开始广播(如果已启用)
if (g_service_started) {
struct ble_gap_adv_params adv_params = {0};
struct ble_hs_adv_fields fields = {0};
fields.flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP;
fields.tx_pwr_lvl_is_present = 1;
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
fields.name = (uint8_t *)device_name;
fields.name_len = strlen(device_name);
fields.name_is_complete = 1;
ble_gap_adv_set_fields(&fields);
adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
int rc = ble_gap_adv_start(BLE_OWN_ADDR_TYPE_PUBLIC, NULL, BLE_HS_FOREVER,
&adv_params, gap_event_handler, NULL);
if (rc != 0) {
ESP_LOGE(TAG, "Failed to start advertising: %d", rc);
} else {
ESP_LOGI(TAG, "Advertising started: %s", device_name);
}
}
}
static void
ble_on_reset(int reason)
{
ESP_LOGE(TAG, "Resetting BLE stack, reason=%d", reason);
}
// -------------------------------
// 主机任务(由 nimble_port_freertos_init 调用)
// -------------------------------
static void
ble_host_task(void *param)
{
ESP_LOGI(TAG, "BLE Host Task Running");
nimble_port_run(); // 永久阻塞运行
nimble_port_freertos_deinit();
vTaskDelete(NULL);
}
// -------------------------------
// API 实现
// -------------------------------
esp_err_t ble_service_init(ble_event_callback_t callback)
{
if (g_service_started) {
ESP_LOGW(TAG, "Already initialized");
return ESP_ERR_INVALID_STATE;
}
g_event_callback = callback;
// 初始化 HCI 层
esp_err_t ret = esp_nimble_hci_and_controller_init();
if (ret != ESP_OK) {
ESP_LOGE(TAG, "HCI init failed: %s", esp_err_to_name(ret));
return ret;
}
// 初始化 NimBLE 主机
nimble_port_init();
// 设置回调
ble_hs_cfg.sync_cb = ble_on_sync;
ble_hs_cfg.reset_cb = ble_on_reset;
// 注册 GATT 服务
int rc = ble_gatts_count_cfg(gatt_svr_svcs);
if (rc != 0) {
ESP_LOGE(TAG, "Service count failed: %d", rc);
goto err;
}
rc = ble_gatts_add_svcs(gatt_svr_svcs);
if (rc != 0) {
ESP_LOGE(TAG, "Add services failed: %d", rc);
goto err;
}
// 启动主机任务
nimble_port_freertos_init(ble_host_task);
ESP_LOGI(TAG, "BLE service initialized");
return ESP_OK;
err:
esp_nimble_hci_and_controller_deinit();
return ESP_FAIL;
}
esp_err_t ble_service_start(void)
{
if (g_service_started) {
ESP_LOGW(TAG, "Already started");
return ESP_ERR_INVALID_STATE;
}
g_service_started = true;
if (ble_hs_is_enabled()) {
ble_on_sync(); // 手动触发同步流程
}
return ESP_OK;
}
esp_err_t ble_service_stop(void)
{
if (!g_service_started) {
return ESP_ERR_INVALID_STATE;
}
ble_gap_adv_stop();
if (g_device_connected) {
ble_gap_terminate(g_conn_handle, BLE_ERR_REM_USER_CONN_TERM);
}
g_service_started = false;
g_device_connected = false;
ESP_LOGI(TAG, "BLE service stopped");
return ESP_OK;
}
esp_err_t ble_service_send_data(const uint8_t *data, size_t length)
{
if (!g_service_started || !g_device_connected) {
ESP_LOGW(TAG, "Not connected or not started");
return ESP_ERR_INVALID_STATE;
}
if (!data || length == 0) {
return ESP_ERR_INVALID_ARG;
}
if (g_tx_val_handle == 0) {
ESP_LOGE(TAG, "TX handle not assigned yet!");
return ESP_ERR_INVALID_STATE;
}
int rc = ble_gattc_notify_custom(g_conn_handle, g_tx_val_handle, length, (uint8_t *)data);
if (rc != 0) {
ESP_LOGE(TAG, "Notify failed: %d", rc);
return ESP_FAIL;
}
ESP_LOGD(TAG, "Sent %zu bytes via notify", length);
return ESP_OK;
}
esp_err_t ble_service_send_string(const char *str)
{
if (!str) return ESP_ERR_INVALID_ARG;
return ble_service_send_data((const uint8_t *)str, strlen(str));
}
esp_err_t ble_service_send_at_response(const char *response)
{
return ble_service_send_string(response);
}
bool ble_service_is_connected(void)
{
return g_device_connected;
}
ble_config_t* ble_service_get_config(void)
{
// 假设你有一个全局配置对象,否则请实现它
extern ble_config_t g_ble_config;
return &g_ble_config;
}
In file included from C:/Espressif/frameworks/esp-idf-v5.3.1/components/bt/host/nimble/nimble/porting/nimble/include/modlog/modlog.h:30,
from C:/Espressif/frameworks/esp-idf-v5.3.1/components/bt/host/nimble/nimble/nimble/host/include/host/ble_hs_log.h:36,
from C:/Espressif/frameworks/esp-idf-v5.3.1/components/bt/host/nimble/nimble/nimble/host/include/host/ble_hs.h:38:
E:/espdemo/LED/components/BLE/ble_service.c: In function 'gap_event_handler':
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:290:27: error: format '%d' expects argument of type 'int', but argument 6 has type 'double' [-Werror=format=]
290 | #define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
| ^~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:293:27: note: in expansion of macro 'LOG_COLOR'
293 | #define LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
| ^~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:307:37: note: in expansion of macro 'LOG_COLOR_E'
307 | #define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter #letter " (%" PRIu32 ") %s: " format LOG_RESET_COLOR "\n"
| ^~~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:435:86: note: in expansion of macro 'LOG_FORMAT'
435 | if (level==ESP_LOG_ERROR ) { esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
| ^~~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:463:41: note: in expansion of macro 'ESP_LOG_LEVEL'
463 | if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \
| ^~~~~~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:367:38: note: in expansion of macro 'ESP_LOG_LEVEL_LOCAL'
367 | #define ESP_LOGI( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~
E:/espdemo/LED/components/BLE/ble_service.c:165:17: note: in expansion of macro 'ESP_LOGI'
165 | ESP_LOGI(TAG, "Conn interval=%dms latency=%d timeout=%dms",
| ^~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:290:27: error: format '%d' expects argument of type 'int', but argument 6 has type 'double' [-Werror=format=]
290 | #define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
| ^~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:294:27: note: in expansion of macro 'LOG_COLOR'
294 | #define LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
| ^~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:307:37: note: in expansion of macro 'LOG_COLOR_W'
307 | #define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter #letter " (%" PRIu32 ") %s: " format LOG_RESET_COLOR "\n"
| ^~~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:436:86: note: in expansion of macro 'LOG_FORMAT'
436 | else if (level==ESP_LOG_WARN ) { esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
| ^~~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:463:41: note: in expansion of macro 'ESP_LOG_LEVEL'
463 | if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \
| ^~~~~~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:367:38: note: in expansion of macro 'ESP_LOG_LEVEL_LOCAL'
367 | #define ESP_LOGI( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~
E:/espdemo/LED/components/BLE/ble_service.c:165:17: note: in expansion of macro 'ESP_LOGI'
165 | ESP_LOGI(TAG, "Conn interval=%dms latency=%d timeout=%dms",
| ^~~~~~~~
E:/espdemo/LED/components/BLE/ble_service.c:168:1: error: format '%d' expects argument of type 'int', but argument 6 has type 'double' [-Werror=format=]
168 | desc.supervision_timeout * 10);
| ^
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:307:59: note: in definition of macro 'LOG_FORMAT'
307 | #define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter #letter " (%" PRIu32 ") %s: " format LOG_RESET_COLOR "\n"
| ^~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:463:41: note: in expansion of macro 'ESP_LOG_LEVEL'
463 | if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \
| ^~~~~~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:367:38: note: in expansion of macro 'ESP_LOG_LEVEL_LOCAL'
367 | #define ESP_LOGI( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~
E:/espdemo/LED/components/BLE/ble_service.c:165:17: note: in expansion of macro 'ESP_LOGI'
165 | ESP_LOGI(TAG, "Conn interval=%dms latency=%d timeout=%dms",
| ^~~~~~~~
E:/espdemo/LED/components/BLE/ble_service.c:168:1: error: format '%d' expects argument of type 'int', but argument 6 has type 'double' [-Werror=format=]
168 | desc.supervision_timeout * 10);
| ^
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:307:59: note: in definition of macro 'LOG_FORMAT'
307 | #define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter #letter " (%" PRIu32 ") %s: " format LOG_RESET_COLOR "\n"
| ^~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:463:41: note: in expansion of macro 'ESP_LOG_LEVEL'
463 | if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \
| ^~~~~~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:367:38: note: in expansion of macro 'ESP_LOG_LEVEL_LOCAL'
367 | #define ESP_LOGI( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~
E:/espdemo/LED/components/BLE/ble_service.c:165:17: note: in expansion of macro 'ESP_LOGI'
165 | ESP_LOGI(TAG, "Conn interval=%dms latency=%d timeout=%dms",
| ^~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:290:27: error: format '%d' expects argument of type 'int', but argument 6 has type 'double' [-Werror=format=]
290 | #define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
| ^~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:295:27: note: in expansion of macro 'LOG_COLOR'
295 | #define LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
| ^~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:307:37: note: in expansion of macro 'LOG_COLOR_I'
307 | #define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter #letter " (%" PRIu32 ") %s: " format LOG_RESET_COLOR "\n"
| ^~~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:439:86: note: in expansion of macro 'LOG_FORMAT'
439 | else { esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
| ^~~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:463:41: note: in expansion of macro 'ESP_LOG_LEVEL'
463 | if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \
| ^~~~~~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/log/include/esp_log.h:367:38: note: in expansion of macro 'ESP_LOG_LEVEL_LOCAL'
367 | #define ESP_LOGI( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~
E:/espdemo/LED/components/BLE/ble_service.c:165:17: note: in expansion of macro 'ESP_LOGI'
165 | ESP_LOGI(TAG, "Conn interval=%dms latency=%d timeout=%dms",
| ^~~~~~~~
E:/espdemo/LED/components/BLE/ble_service.c: In function 'ble_on_sync':
E:/espdemo/LED/components/BLE/ble_service.c:243:36: error: 'BLE_OWN_ADDR_TYPE_PUBLIC' undeclared (first use in this function); did you mean 'BLE_OWN_ADDR_PUBLIC'?
243 | int rc = ble_gap_adv_start(BLE_OWN_ADDR_TYPE_PUBLIC, NULL, BLE_HS_FOREVER,
| ^~~~~~~~~~~~~~~~~~~~~~~~
| BLE_OWN_ADDR_PUBLIC
E:/espdemo/LED/components/BLE/ble_service.c:243:36: note: each undeclared identifier is reported only once for each function it appears in
E:/espdemo/LED/components/BLE/ble_service.c: In function 'ble_service_init':
E:/espdemo/LED/components/BLE/ble_service.c:286:21: error: implicit declaration of function 'esp_nimble_hci_and_controller_init' [-Werror=implicit-function-declaration]
286 | esp_err_t ret = esp_nimble_hci_and_controller_init();
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:/espdemo/LED/components/BLE/ble_service.c:319:5: error: implicit declaration of function 'esp_nimble_hci_and_controller_deinit' [-Werror=implicit-function-declaration]
319 | esp_nimble_hci_and_controller_deinit();
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:/espdemo/LED/components/BLE/ble_service.c: In function 'ble_service_send_data':
E:/espdemo/LED/components/BLE/ble_service.c:372:70: warning: passing argument 3 of 'ble_gattc_notify_custom' makes pointer from integer without a cast [-Wint-conversion]
372 | int rc = ble_gattc_notify_custom(g_conn_handle, g_tx_val_handle, length, (uint8_t *)data);
| ^~~~~~
| |
| size_t {aka unsigned int}
In file included from C:/Espressif/frameworks/esp-idf-v5.3.1/components/bt/host/nimble/nimble/nimble/host/include/host/ble_hs.h:34:
C:/Espressif/frameworks/esp-idf-v5.3.1/components/bt/host/nimble/nimble/nimble/host/include/host/ble_gatt.h:858:45: note: expected 'struct os_mbuf *' but argument is of type 'size_t' {aka 'unsigned int'}
858 | struct os_mbuf *om);
| ~~~~~~~~~~~~~~~~^~
E:/espdemo/LED/components/BLE/ble_service.c:372:14: error: too many arguments to function 'ble_gattc_notify_custom'
372 | int rc = ble_gattc_notify_custom(g_conn_handle, g_tx_val_handle, length, (uint8_t *)data);
| ^~~~~~~~~~~~~~~~~~~~~~~
C:/Espressif/frameworks/esp-idf-v5.3.1/components/bt/host/nimble/nimble/nimble/host/include/host/ble_gatt.h:857:5: note: declared here
857 | int ble_gattc_notify_custom(uint16_t conn_handle, uint16_t att_handle,
| ^~~~~~~~~~~~~~~~~~~~~~~
E:/espdemo/LED/components/BLE/ble_service.c: At top level:
E:/espdemo/LED/components/BLE/ble_service.c:50:17: