谢谢分享,有个疑问:SDK中beacon中例子,每5秒钟改变广播消息,感觉没有走这样的流程。我把代码贴出来了:
/* Private functions ---------------------------------------------------------*/
void app_ble_connected(void);
void app_ble_disconnected(void);
void app_printf_ibeacon(uint8_t* uuid, uint16_t major, uint16_t minor, int8_t rssi)
{
NS_LOG_INFO("\r\nUUID(hex):");
for(uint8_t i=0;i<16;i++)
{
NS_LOG_INFO(" %02X",uuid);
}
NS_LOG_INFO("\r\nMajor: %d",major );
NS_LOG_INFO("\r\nMinor: %d",minor );
NS_LOG_INFO("\r\nRSSI at 1m: %d dBm\r\n",rssi );
}
void app_update_ibeacon(uint8_t* uuid, uint16_t major, uint16_t minor, int8_t rssi)
{
uint8_t ibc_data[27] =
{0x1a,0xff,
0x4c,0x00,0x02,
0x15,
0x10,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff,
0x12,0x34,
0x56,0x78,
0xCE};
memcpy(&ibc_data[6], uuid, 16);
memcpy(&ibc_data[22], &major, 2);
memcpy(&ibc_data[24], &minor, 2);
ibc_data[26] = rssi;
ns_ble_adv_data_set(ibc_data,27);
}
/**
* @brief user message handler
* @param
* @return
* @NOTE
*/
void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param)
{
switch (msgid)
{
case APP_CUSTS_TEST_EVT:
{
major = rand(); //random
minor = rand(); //random
app_update_ibeacon(uuid,major,minor,rssi);
app_printf_ibeacon(uuid,major,minor,rssi);
//repeat timer
ke_timer_set(APP_CUSTS_TEST_EVT,TASK_APP,5000);
}
break;
default:
break;
}
}
/**
* @brief ble message handler
* @param
* @return
* @note
*/
void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg)
{
switch (p_ble_msg->msg_id)
{
case APP_BLE_OS_READY:
NS_LOG_INFO("APP_BLE_OS_READY\r\n");
ke_timer_set(APP_CUSTS_TEST_EVT,TASK_APP,5000);
break;
case APP_BLE_GAP_CONNECTED:
app_ble_connected();
break;
case APP_BLE_GAP_DISCONNECTED:
app_ble_disconnected();
break;
default:
break;
}
}
直接在协议栈初始化完成后创建一个定时器来修改广播参数。 |
@cooldog123pp :N32WB031-STB开发板,上面淘宝链接的就是
什么开发板!