BLE:是否读取值需要先发送写请求?
创始人
2024-12-22 18:00:35
0

是的,为了读取BLE的值,需要先发送写请求。以下是使用Nordic nRF52 SDK中的代码示例:

首先,必须在特征值上启用通知。以下代码演示如何启用通知:

uint32_t err_code; ble_gatts_value_t gatts_value; ble_gatts_char_md_t char_md; ble_gatts_attr_md_t attr_md; ble_gatts_attr_t attr_char_value; ble_uuid_t char_uuid;

// 初始化UUID char_uuid.type = p_custom_service->uuid_type; char_uuid.uuid = SOME_UUID;

// 初始化属性元数据的值 memset(&char_md, 0, sizeof(char_md)); char_md.char_props.notify = 1; char_md.p_char_user_desc = NULL; char_md.p_char_pf = NULL; char_md.p_user_desc_md = NULL; char_md.p_cccd_md = NULL; char_md.p_sccd_md = NULL;

// 初始化属性管理数据的值 memset(&attr_md, 0, sizeof(attr_md)); attr_md.read_perm = p_custom_service->custom_value_char_attr_md.read_perm; attr_md.write_perm = p_custom_service->custom_value_char_attr_md.write_perm; attr_md.vloc = BLE_GATTS_VLOC_STACK; attr_md.rd_auth = 0; attr_md.wr_auth = 0; attr_md.vlen = 0;

// 初始化GATT属性值的值 memset(&gatts_value, 0, sizeof(ble_gatts_value_t)); gatts_value.len = sizeof(uint32_t); gatts_value.offset = 0; gatts_value.p_value = (uint8_t *) initial_custom_value;

// 初始化GATT属性的值 memset(&attr_char_value, 0, sizeof(attr_char_value)); attr_char_value.p_uuid = &char_uuid; attr_char_value.p_attr_md = &attr_md; attr_char_value.init_len = sizeof(uint32_t); attr_char_value.init_offs = 0; attr_char_value.max_len = MAX_CUSTOM_VALUE_CHAR_LEN; attr_char_value.p_value = (uint8_t *) initial_custom_value;

// 添加要添加到属性列表中的属性 err_code = sd_ble_gatts_characteristic_add(p_custom_service->service_handle, &char_md, &attr_char_value, &p_custom_service->custom_value_handles); if (err_code != NRF_SUCCESS) { return err_code; }

然后,可以使用以下代码发送写请求:

uint32_t err_code; ble_gatts_value_t gatts_value;

// 初始化写请求 memset(&gatts_value, 0, sizeof(gatts_value));

相关内容

热门资讯

透视插件!wepoker可以设... 透视插件!wepoker可以设置盖牌-关于开挂透视辅助教程(有挂教学)透视插件!wepoker可以设...
最新技巧“浙江游戏大厅修改器”... 最新技巧“浙江游戏大厅修改器”原先有开挂辅助挂(确实有挂);1、这是跨平台的浙江游戏大厅修改器黑科技...
透视挂透视!hhpoker可以... 透视挂透视!hhpoker可以开挂-揭露开挂透视辅助攻略(有挂攻略)1、hhpoker可以开挂系统规...
玩家必看分享“小程序微乐游戏辅... 玩家必看分享“小程序微乐游戏辅助器”其实有开挂辅助器(详细教程);1、让任何用户在无需AI插件第三方...
透视工具!wepoker国外版... 透视工具!wepoker国外版透视-教你开挂透视辅助工具(了解有挂)1、全新机制【wepoker国外...
专业讨论“欢乐游戏城破解版内置... 专业讨论“欢乐游戏城破解版内置修改器”本来有开挂辅助脚本(了解有挂);详细欢乐游戏城破解版内置修改器...
一分钟教你“宝宝游戏辅助”好像... 您好:宝宝游戏辅助这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别...
透视最新!hhpoker透视挂... 透视最新!hhpoker透视挂实战视频-解谜开挂透视辅助攻略(有挂技术)1、超多福利:超高返利,海量...
9分钟了解“四川家园游戏辅助器... 9分钟了解“四川家园游戏辅助器平台交易”果然有开挂辅助下载(有挂规律);亲真的是有正版授权,小编(透...
透视科技!wepoker智能辅... 透视科技!wepoker智能辅助插件-教你开挂透视辅助插件(有挂方针)1、进入到wepoker智能辅...