1概述
参考网址:网址 Long Range 是BLE 5.0中新增加的特性,主要是通过扩频的方式,提高了天线接收的灵敏度,同时将最大的发送功率,从4.0/4.1/4.2中的10mW增大到5.0的100mW。相对于BLE来说,确实增加了通信的距离。
nRF52832 不支持 code 模式
2:代码编程
#include "ble_adv.h"
#include "ble_advdata.h"
#include "app_error.h"
uint8_t beacon_info
[23] =
{
0x02,
0x15,
0xE2,0xC5,0x6D,0xB5,0xDF,0xFB,0x48,0xD2,0xB0,0x60,0xD0,0xF5,0xA7,0x10,0x96,0xE0,
0X00,0x00,
0x00,0x00,
0xC3
};
static uint8_t m_enc_advdata
[BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_MAX_SUPPORTED
];
static uint8_t m_adv_handle
= BLE_GAP_ADV_SET_HANDLE_NOT_SET
;
ble_gap_adv_data_t m_adv_data
=
{
.adv_data
=
{
.p_data
= m_enc_advdata
,
.len
= BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_MAX_SUPPORTED
,
},
.scan_rsp_data
=
{
.p_data
=NULL,
.len
=0,
}
};
uint8_t test_data
[40];
void ble_adv_init(void)
{
uint32_t err_code
;
ble_advdata_t advdata
;
ble_advdata_manuf_data_t manuf_specific_data
;
memset(&manuf_specific_data
,0,sizeof(manuf_specific_data
));
manuf_specific_data
.company_identifier
= 0x00C7;
manuf_specific_data
.data
.p_data
= (uint8_t
*) beacon_info
;
manuf_specific_data
.data
.size
= sizeof(beacon_info)
;
memset(&advdata
, 0, sizeof(advdata
));
advdata
.name_type
= BLE_ADVDATA_NO_NAME
;
advdata
.flags
= BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE
;
advdata
.p_manuf_specific_data
= &manuf_specific_data
;
err_code
= ble_advdata_encode(&advdata
, m_adv_data
.adv_data
.p_data
,
&m_adv_data
.adv_data
.len
);
APP_ERROR_CHECK(err_code
);
ble_gap_adv_params_t adv_params
;
memset(&adv_params
, 0, sizeof(adv_params
));
adv_params
.primary_phy
= BLE_GAP_PHY_CODED
;
adv_params
.secondary_phy
= BLE_GAP_PHY_CODED
;
adv_params
.properties
.type
= BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_UNDIRECTED
;
adv_params
.p_peer_addr
= NULL;
adv_params
.filter_policy
= BLE_GAP_ADV_FP_ANY
;
adv_params
.interval
= 64;
adv_params
.duration
= 0;
err_code
= sd_ble_gap_adv_set_configure(&m_adv_handle
, &m_adv_data
, &adv_params
);
APP_ERROR_CHECK(err_code
);
}
void ble_adv_start(void)
{
ret_code_t err_code
;
err_code
= sd_ble_gap_adv_start(m_adv_handle
, 1);
APP_ERROR_CHECK(err_code
);
}
实际测量和应用 1:广播longrange模式下,常规的BLE主机无法扫描到该设备,建议双方同时处于longrange模式下,进行相互连接和通信 2. 远距离发起连接容易超时导致连接失败,因为BLE连接需要比较严格的通信时序,因为longrang模式下数据速率会降低些
可以加入QQ群:687360507 与大伙沟通交流,技术在于分享而进步