nordic论坛
我想要设置广播名称为 “一二三四五”,当广播名称为FULL_NAME时,但是广播显示还是“一?”,“?”是乱码,后来打开nrf connect观察广播,在没连接的时候,点击一下,看了一下显示Shortened Local Name :“一?”
static uint16_t adv_set_data_size_max_get(ble_advertising_t const * const p_advertising)
{uint16_t adv_set_data_size_max;if (p_advertising->adv_modes_config.ble_adv_extended_enabled == true){
#ifdef BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_CONNECTABLE_MAX_SUPPORTEDadv_set_data_size_max = BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_CONNECTABLE_MAX_SUPPORTED;
#elseadv_set_data_size_max = BLE_GAP_ADV_SET_DATA_SIZE_MAX;
#endif // BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_CONNECTABLE_MAX_SUPPORTED}else{adv_set_data_size_max = BLE_GAP_ADV_SET_DATA_SIZE_MAX;}return adv_set_data_size_max;
}
后来发现BLE_GAP_ADV_SET_DATA_SIZE_MAX = 31;广播信息只有31字节。
应该是广播信息超过了,导致名称显示乱码。
例程里面,init.srdata要改为init.advdata,要不然会报错
init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);init.srdata.uuids_complete.p_uuids = m_adv_uuids;
改为下边的
static void advertising_init(void)
{ret_code_t err_code;ble_advertising_init_t init;memset(&init, 0, sizeof(init));init.advdata.name_type = BLE_ADVDATA_FULL_NAME;init.advdata.include_appearance = true;init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);init.advdata.uuids_complete.p_uuids = m_adv_uuids;init.config.ble_adv_fast_enabled = true;init.config.ble_adv_extended_enabled = true; //添加这条init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;init.config.ble_adv_fast_timeout = APP_ADV_DURATION;init.evt_handler = on_adv_evt;err_code = ble_advertising_init(&m_advertising, &init);APP_ERROR_CHECK(err_code);ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
}
但是有个问题就是 init.config.ble_adv_extended_enabled = true;之后,搜不到蓝牙了。
//**********************添加蓝牙5.0**************************//init.config.ble_adv_primary_phy = BLE_GAP_PHY_1MBPS;init.config.ble_adv_secondary_phy = BLE_GAP_PHY_2MBPS;init.config.ble_adv_extended_enabled = true;
//***********************************************************//
需要修改蓝牙app的搜索模式。