Solution: Tencent ble iot vehicle¶
1 功能概述¶
此项目演示模拟蓝牙感应钥匙功能,当手机足够接近电动车时,会自动解锁电动车。实际该项目通过灯的状态来观察开关,通过距离远近会影响灯的开关以及亮度。
2 环境要求¶
board: pan108xxb1_mesh_dongle
uart (option): 显示串口shell
测试硬件:智能手机,微信小程序
PC工具: 软件shell工具(支持串口,波特率921600)
确认zephyr同级目录modules文件夹向下:存在
modules\lib\qcloud-iot-ble
文件夹。
3 编译和烧录¶
例程位置:zephyr\samples_panchip\solutions\tencent_ble_iot_vehicle
,编译时board请选pan108xxb1_mesh_dongle
编译时会将modules\lib\qcloud-iot-ble\qcloud_llsync
文件夹拷贝到tencent_ble_iot_vehicle
项目文件夹下,如果编译失败并且qcloud_llsync
中内容为空,建议删除qcloud_llsync
重新编译。
默认原生支持EVB为pan108xxb1_mesh_dongle
。
使用 ZAL 工具可以对其进行编译、烧录、打开 VS Code 调试等操作。关于 ZAL 工具的详细介绍请参考:Zephyr APP Launcher 工具介绍。
4 演示说明¶
将tencent_ble_iot_vehicle烧录至EVB板后,使用shell工具连接上EVB开发板(波特率921600),会显示如下log。通过连续双击tab可以显示出当前可用的命令。
Try to load HW calibration data.. DONE.
*** Booting Zephyr OS build zephyr-v2.7.0-1248-gd03ebd76a3f5 ***
*** llcontroller-v1.0.0-0559423d ***
controller initializing....
Bluetooth initialized
Version:0.0.1
Set up key1 at GPIO_P1 pin 0
c8 ad 65 47 bd d8 qiot debug: bind state: 0 ---> 0
device id : 80Q7CA6M37C8AD6547BDD8 device psk : xo33NXGcLMTo/fuImd2fsA==
qrcode str : https://iot.cloud.tencent.com/bind?d=80Q7CA6M37C8AD6547BDD8&sig=13b4e90b41dd03bbf6ee3e96edb469be
Advertising stopped
qiot debug: bind state: 0 ---> 1
ble qiot dump: broadcast, length: 17
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
===============================================
39 C8 AD 65 47 BD D8 38 30 51 37 43 41 36 4D 33 | 9..eG..80Q7CA6M3
37 | 7
Advertising successfully started
qiot info: start wait advertising
[00:00:00.002,000] <wrn> bt_hci_core: Failed to set device name (-12)
[00:00:00.100,000] <inf> bt_hci_core: Identity: D4:A3:B3:49:9B:D8 (random)
[00:00:00.100,000] <inf> bt_hci_core: HCI: version 5.1 (0x0a) revision 0x0003, manufacturer 0x07d1
[00:00:00.100,000] <inf> bt_hci_core: LMP: version 5.1 (0x0a) subver 0x0000
[00:00:00.122,000] <inf> bt_adv: Start Advertising as C8:AD:65:47:BD:D8 (random)
uart:~$
打开微信程序,搜索腾讯连连,打开腾讯连连小程序,扫一扫二维码(
tencent_ble_iot_vehicle\wechat_qrcode.png
),也可以直接参考下图二维码。二维码的生成信息在启动log中会显示,见下(也可以参考上段启动log信息):
qrcode str : https://iot.cloud.tencent.com/bind?d=80Q7CA6M37C8AD6547BDD8&sig=13b4e90b41dd03bbf6ee3e96edb469be
使用https://cli.im/
此网站,贴入https://iot.cloud.tencent.com/bind?d=80Q7CA6M37C8AD6547BDD8&sig=13b4e90b41dd03bbf6ee3e96edb469be
该信息,点击生成二维码即可。
配对成功后我们就可以通过微信小程序进行控制了。
启动无感解锁,无感解锁时需要设置小程序的蓝牙权限总是打开。
5 支持的测试命令¶
测试命令 |
功能描述 |
---|---|
|
设置mac地址,同时也是设置device name(三元组信息之一)。tencent wheeler sdk中要求ble mac地址和设备名称是保持一致的。 |
|
设置product id字符信息(三元组信息之一) |
|
设置secret字符信息(三元组信息之一) |
|
保存三元组信息到flash,同时重启芯片。三元组信息请同时修改。 |
|
腾讯连连认证测试命令(详情见认证文档) |
|
腾讯连连认证测试命令(详情见认证文档) |
|
腾讯连连认证测试命令(详情见认证文档) |
|
腾讯连连认证测试命令(详情见认证文档) |
|
使能或者关闭 |
我们可以看到更新三元组后重启后广播地址也发生变化了,并且上电打印的key信息和命令设置中的一致。
下框为关闭打开rssi log功能:
uart:~$ test ble_rssi_log_enable 0
ble_set_rssi_log
disable ble_set_rssi_log
uart:~$ test ble_rssi_log_enable 1
ble_set_rssi_log
enable ble_set_rssi_log
uart:~$
7 腾讯云控制台导入物模型¶
腾讯云控制台新建产品时导入二轮电动车模型时,可以直接使用modules\lib\qcloud-iot-ble\qcloud_llsync\date_template\two_wheeler.json
详情参考以下蓝牙设备接入指引的创建数据模板
章节:
https://cloud.tencent.com/document/product/1081/50969
8 腾讯连连调参指南¶
8.1 广播周期调整¶
ble_qiot_ret_status_t ble_advertising_start(adv_info_s *adv)
{
int err;
uint8_t len = 0;
memcpy(manufacturer_buffer, &adv->manufacturer_info.company_identifier, sizeof(uint16_t));
len = sizeof(uint16_t);
memcpy(manufacturer_buffer + len, adv->manufacturer_info.adv_data, adv->manufacturer_info.adv_data_len);
len += adv->manufacturer_info.adv_data_len;
ad[MANUFACTURER_AD_INDEX].data_len = len;
ad[MANUFACTURER_AD_INDEX].data = manufacturer_buffer;
/*此处广播周期由BT_GAP_ADV_FAST_INT_MAX_1来决定,可以在项目找到该宏定义或者合适的宏,甚至自定义相应的值来调整广播周期。自定义的值请遵守蓝牙规范*/
err = bt_le_adv_start(BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE,BT_GAP_ADV_FAST_INT_MAX_1,BT_GAP_ADV_FAST_INT_MAX_1,NULL),
ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
if (err) {
printk("Advertising failed to start (err %d)\n", err);
}
printk("Advertising successfully started\n");
return 0 == err ? BLE_QIOT_RS_OK : BLE_QIOT_RS_ERR;
}
8.2 腾讯连连软件算法调参¶
//This macro is an encryption function of the LLSync firmware. When turned on, LLSync encrypts data during the binding、
//connection and control phases. (Open this macro to note whether encryption is turned on in the cloud platform)
#define BLE_QIOT_SESSION_ENCRYPT (1)
#if BLE_QIOT_SESSION_ENCRYPT
// Sensorless locking macro, which automatically closes the lock when the specified rssi value is reached if it is switched on
#define BLE_QIOT_SLIENCE_LOCK (1)
#if BLE_QIOT_SLIENCE_LOCK
// The rssi value will fluctuate, this value is the fluctuation range of the anti-shake
/*去抖参数*/
#define BLE_QIOT_JITTER_VALUE (5)
// The number of times the threshold value is exceeded, after which the lock-off logic is executed
/*连续达到开关逻辑RSSI阈值的次数*/
#define BLE_QIOT_MORE_THAN_RSSI_NUM (6)
// Testing rssi's mode, 0-off 1-on, Only the scanned rssi values are printed when switched on, no locking action is performed
#define BLE_QIOT_RSSI_TEST (0)
// Slience lock timer detection cycle (ms)
/*RSSI采样定时器参数*/
#define BLE_QIOT_SILENCE_LOCK_TIMEOUT (150)
// Near distance off lock rssi values
/*触发近距离开关的RSSI阈值*/
#define BLE_QIOT_CONN_RSSI_NEAR (-50)
// Medium distance off lock rssi values
/*触发中距离开关的RSSI阈值*/
#define BLE_QIOT_CONN_RSSI_MEDIUM (-63)
// Far distance off lock rssi values
/*触发远距离开关的RSSI阈值*/
#define BLE_QIOT_CONN_RSSI_FAR (-73)
#endif
#endif
BLE_QIOT_MORE_THAN_RSSI_NUM
* BLE_QIOT_SILENCE_LOCK_TIMEOUT
为实际触发开关的最小时间,请根据实际测试结果进行调参。
9 腾讯连连认证证书¶
10 RAM/Flash资源使用情况¶
Memory region Used Size Region Size %age Used
FLASH: 148956 B 384 KB 37.88%
SRAM: 46512 B 50 KB 90.84%