ESP-IDF学习——gatt_server_service_table添加Service

项目环境

项目 版本
ESP-IDF v5.1.1
开发板 ESP32-WROOM-32
example project gatt_server_service_table
Visual Stdio Code April 2023 (version 1.78)

添加Service

1.添加宏定义配置

// 日志前缀
#define GATTS_TABLE_TAG "GATTS_TABLE"
#define GATTS_MY_TAG "GATTS_MY_TABLE"   //自定义Tag

#define PROFILE_NUM 2                   //修改Service总数

#define PROFILE_APP_IDX 0               //Profile索引
#define PROFILE_MY_APP_IDX 1            //自定义Profile索引

#define SVC_INST_ID 0                   //服务启动ID
#define SVC_INST_MY_ID 1                //自定义服务启动ID

//句柄
uint16_t heart_rate_handle_table[HRS_IDX_NB];
uint16_t my_handle_table[MY_LENGTH];	//自定义句柄

//gatt状态机回调函数
static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
static void gatts_my_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);	//自定义回调函数声明

//装入自定义回调函数
static struct gatts_profile_inst heart_rate_profile_tab[PROFILE_NUM] = {
   
    [PROFILE_APP_IDX] = {
   
        .gatts_cb = gatts_profile_event_handler,
        .gatts_if = ESP_GATT_IF_NONE, /* Not get the gatt_if, so initial is ESP_GATT_IF_NONE */
    },
    [PROFILE_MY_APP_IDX] = {
   
        .gatts_cb = gatts_my_profile_event_handler, 
        .gatts_if = ESP_GATT_IF_NONE,
    },
};

//UUID配置
static const uint16_t GATTS_SERVICE_UUID_TEST = 0x00FF;
static const uint16_t GATTS_CHAR_UUID_TEST_A = 0xFF01;
static const uint16_t GATTS_CHAR_UUID_TEST_B = 0xFF02;
static const uint16_t GATTS_CHAR_UUID_TEST_C = 0xFF03;

static const uint16_t GATTS_SERVICE_UUID_MY = 0x0077;   //自定义Service UUID
static const uint16_t GATTS_SERVICE_UUID_MY_A = 0x7701; //自定义Characteristic UUID

//项目额外配置
static const uint8_t char_prop_read_write = ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE;
static const uint8_t my_value[4] = {
   0x11, 0x85, 0x35, 0x95};

2. 添加Service结构

Service Declaration
— Characteristic Declaration
— Characteristic Value
— Characteristic Description

gatts_table_creat_demo.h内定义以下枚举类,该枚举类对应在调

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值