运行nordic的 mesh light例子
选择light例子,使用RTT的方式进行log记录,尝试了很久uart的方式没有log输出。
prj.cof
#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
CONFIG_NCS_SAMPLES_DEFAULTS=y
# Deffered logging helps improve LPN power consumption
# when friendship is established.
CONFIG_LOG_MODE_DEFERRED=y
# General configuration
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_HWINFO=y
CONFIG_DK_LIBRARY=y
CONFIG_PM_SINGLE_IMAGE=y
CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x8000
CONFIG_SOC_FLASH_NRF_PARTIAL_ERASE=y
# Bluetooth configuration
CONFIG_BT=y
CONFIG_BT_COMPANY_ID=0x0059
CONFIG_BT_DEVICE_NAME="Mesh Light"
CONFIG_BT_L2CAP_TX_BUF_COUNT=8
CONFIG_BT_OBSERVER=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_SETTINGS=y
# Increase RX stack size to avoid overflow during provisioning
CONFIG_BT_RX_STACK_SIZE=2700
# Disable unused Bluetooth features
CONFIG_BT_CTLR_DUP_FILTER_LEN=0
CONFIG_BT_CTLR_LE_ENC=n
CONFIG_BT_PHY_UPDATE=n
CONFIG_BT_CTLR_MIN_USED_CHAN=n
CONFIG_BT_CTLR_PRIVACY=n
# Bluetooth mesh configuration
CONFIG_BT_MESH=y
CONFIG_BT_MESH_RELAY=y
CONFIG_BT_MESH_FRIEND=y
CONFIG_BT_MESH_TX_SEG_MAX=10
CONFIG_BT_MESH_PB_GATT=y
CONFIG_BT_MESH_GATT_PROXY=y
CONFIG_BT_MESH_PROXY_USE_DEVICE_NAME=y
CONFIG_BT_MESH_DK_PROV=y
# Bluetooth mesh models
CONFIG_BT_MESH_ONOFF_SRV=y
CONFIG_BT_SETTINGS=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_BT_MESH_PROV_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_ACCESS_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_PROXY_LOG_LEVEL_INF=y
CONFIG_BT_MESH_CDB_LOG_LEVEL_INF=y
CONFIG_BT_MESH_CFG_LOG_LEVEL_INF=y
CONFIG_KERNEL_LOG_LEVEL_INF=y
CONFIG_BT_HCI_MESH_EXT=y
CONFIG_BT_DEBUG_SERVICE=y
CONFIG_BT_MESH_DEBUG=y
CONFIG_BT_MESH_DEBUG_NET=y
CONFIG_BT_MESH_DEBUG_RPL=y
CONFIG_BT_MESH_DEBUG_TRANS=y
CONFIG_BT_MESH_DEBUG_BEACON=y
CONFIG_BT_MESH_DEBUG_CRYPTO=y
CONFIG_BT_MESH_DEBUG_KEYS=y
CONFIG_BT_MESH_DEBUG_PROV=y
CONFIG_BT_MESH_DEBUG_PROVISIONER=y
CONFIG_BT_MESH_DEBUG_ACCESS=y
CONFIG_BT_MESH_DEBUG_MODEL=y
CONFIG_BT_MESH_DEBUG_ADV=y
CONFIG_BT_MESH_DEBUG_LOW_POWER=y
CONFIG_BT_MESH_DEBUG_FRIEND=y
CONFIG_BT_MESH_DEBUG_PROXY=y
CONFIG_BT_MESH_DEBUG_SETTINGS=y
CONFIG_BT_MESH_DEBUG_CFG=y
CONFIG_BT_MESH_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_NET_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_RPL_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_TRANS_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_BEACON_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_KEYS_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_PROVISIONER_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_MODEL_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_DFU_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y# CONFIG_BT_CTLR=y
# CONFIG_BT_HCI_DRIVER_LOG_LEVEL_INF=y
# CONFIG_BT_RPA_LOG_LEVEL_DBG=y
# CONFIG_BT_MESH_LOG_LEVEL_INF=y
# CONFIG_BT_MESH_PROVISIONER_LOG_LEVEL_DEFAULT=y
为了可以看到完整的配网流程我把mesh各层的打印都打开了,打印的配置可以在kconfig配置
配置路径:Subsystems and OS Services->Bluetooth->Bluetooth logging->Mesh,真**难找,打开其中的debug,因为nordic代码里面大部分都是debug打印,这个能看到的流程最多
用以上方法配置完后可以看到以下打印,上电后是未配网状态
[00:20:11.225,830] <dbg> bt_mesh_beacon: unprovisioned_beacon_send:
[00:20:11.225,921] <dbg> bt_mesh_adv: bt_mesh_adv_send: type 0x02 len 23: 00050bf688c7594194baf4097738a66e6b000000000000
[00:20:11.225,982] <dbg> bt_mesh_adv: process_events: ev->state 4
[00:20:11.226,043] <dbg> bt_mesh_adv_ext: buf_send: type 2 len 23: 00050bf688c7594194baf4097738a66e6b000000000000
[00:20:11.226,043] <dbg> bt_mesh_adv_ext: buf_send: count 3 interval 20ms duration 90ms
[00:20:11.287,628] <dbg> bt_mesh_adv_ext: send_pending_adv: Advertising stopped after 61 ms for (1) local adv
[00:20:16.226,013] <dbg> bt_mesh_beacon: beacon_send:
[00:20:16.226,043] <dbg> bt_mesh_beacon: unprovisioned_beacon_send:
[00:20:16.226,135] <dbg> bt_mesh_adv: bt_mesh_adv_send: type 0x02 len 23: 00050bf688c7594194baf4097738a66e6b000000000000
[00:20:16.226,196] <dbg> bt_mesh_adv: process_events: ev->state 4
[00:20:16.226,257] <dbg> bt_mesh_adv_ext: buf_send: type 2 len 23: 00050bf688c7594194baf4097738a66e6b000000000000
[00:20:16.226,257] <dbg> bt_mesh_adv_ext: buf_send: count 3 interval 20ms duration 90ms
[00:20:16.284,179] <dbg> bt_mesh_adv_ext: send_pending_adv: Advertising stopped after 58 ms for (1) local adv
[00:20:21.226,226] <dbg> bt_mesh_beacon: beacon_send:
[00:20:21.226,257] <dbg> bt_mesh_beacon: unprovisioned_beacon_send:
[00:20:21.226,348] <dbg> bt_mesh_adv: bt_mesh_adv_send: type 0x02 len 23: 00050bf688c7594194baf4097738a66e6b000000000000
[00:20:21.226,409] <dbg> bt_mesh_adv: process_events: ev->state 4
[00:20:21.226,470] <dbg> bt_mesh_adv_ext: buf_send: type 2 len 23: 00050bf688c7594194baf4097738a66e6b000000000000
[00:20:21.226,470] <dbg> bt_mesh_adv_ext: buf_send: count 3 interval 20ms duration 90ms
[00:20:21.283,050] <dbg> bt_mesh_adv_ext: send_pending_adv: Advertising stopped after 56 ms for (1) local adv
[00:20:26.226,440] <dbg> bt_mesh_beacon: beacon_send:
[00:20:26.226,470] <dbg> bt_mesh_beacon: unprovisioned_beacon_send:
[00:20:26.226,562] <dbg> bt_mesh_adv: bt_mesh_adv_send: type 0x02 len 23: 00050bf688c7594194baf4097738a66e6b000000000000
[00:20:26.226,623] <dbg> bt_mesh_adv: process_events: ev->state 4
[00:20:26.226,684] <dbg> bt_mesh_adv_ext: buf_send: type 2 len 23: 00050bf688c7594194baf4097738a66e6b000000000000
[00:20:26.226,684] <dbg> bt_mesh_adv_ext: buf_send: count 3 interval 20ms duration 90ms
[00:20:26.282,348] <dbg> bt_mesh_adv_ext: send_pending_adv: Advertising stopped after 55 ms for (1) local adv
完成配网后,bind appkey和 订阅group就能使用手机进行灯的亮灭控制了
mesh功能也是类似的操作,它的前台执行程序和后台执行程序分别是mesh-cfgclient和bluetooth-meshd,核心的业务逻辑在bluetooth-meshd中实现。
tools/mesh-cfgclient:通过dbus和bluetooth-meshd通信,实现了mesh协议的adv bear层的scan,provision和configuration功能,支持发送config消息,但是却没有generic onoff的代码实现,需要使用者自己实现generic onoff和vendor消息。
mesh/bluetooth-meshd:后台运行,linux系统不会默认启动,需要手动启动或者在systemd,init.rc等启动配置文件中手动添加。需要说明的是启动bluetooth-meshd的时候,需要关闭bluetoothd。
tools/mesh-cfgtest:测试bluetooth-meshd和client是否可以正常通信的工具,它在源码中会fork出来一个进程去执行bluetooth-meshd程序,然后mesh-cfgtest的主程序会和bluetooth-meshd进行通信,根据相对路径找到mesh/bluetooth-meshd可执行程序然后执行,因此如果执行失败,可以看看是否是因为找不到bluetooth-meshd程序导致的。
tools/meshctl:该程序实现了mesh协议栈的proxy特性,同样可以扫描,provision和configuration,并且有控制灯开关的generic onoff代码实现,但是它是基于gatt bear层实现的,并不是通过adv bear层实现。 另外一点是它并不依赖bluetooth-meshd程序,它是与bluetoothd后台程序进行通信的。
bluetooth-meshd:源码在bluez-5.71/mesh/目录中,是mesh协议栈的核心代码。
mesh-cfgclient:源码在bluez-5.71/tools/mesh目录中,tools/mesh-cfgclient.c文件是程序的入口。
mesh-cfgtest:源码在bluez-5.71/tools/mesh目录中,tools/mesh-cfgtest.c文件时程序的入口。
meshctl:源码在bluez-5.71/tools/mesh-gatt目录中,meshctl.c是程序的入口。
上述相关meshctl内容参考from:https://blog.csdn.net/wanguofeng8023/article/details/129387756、
采用的是杰理AC632N SDK的mesh
SIG_MESH_GENERIC_ONOFF_SERVER
例子
[meshctl]# discover-unprovisioned on
SetDiscoveryFilter success
Failed to start discovery: org.bluez.Error.InProgress
Mesh Provisioning Service (00001827-0000-1000-8000-00805f9b34fb)
Device UUID: 67554433222200000000000000000000
OOB: 0000
[NEW] Device 22:22:33:44:55:67 AC632N_1
[meshctl]# provision 67554433222200000000000000000000
Trying to connect Device 22:22:33:44:55:67 AC632N_1
[DEL] Device 26:86:5F:72:DD:FE 26-86-5F-72-DD-FE
[DEL] Device 31:3D:B4:5F:87:8E 31-3D-B4-5F-87-8E
[DEL] Device F1:36:2A:49:63:40 F1-36-2A-49-63-40
[DEL] Device 42:EC:E3:6B:FF:44 42-EC-E3-6B-FF-44
[DEL] Device 01:D4:AE:40:7A:A0 01-D4-AE-40-7A-A0
[DEL] Device 6D:F3:57:18:81:12 6D-F3-57-18-81-12
[DEL] Device 04:2E:9E:8D:71:76 04-2E-9E-8D-71-76
[DEL] Device 75:A2:AA:E5:17:7D 75-A2-AA-E5-17-7D
[DEL] Device C1:4A:6D:0B:E5:7F C1-4A-6D-0B-E5-7F
[DEL] Device 7F:7C:2E:41:D8:B6 7F-7C-2E-41-D8-B6
[DEL] Device 1C:40:54:1F:BB:43 1C-40-54-1F-BB-43
[DEL] Device 6E:5E:E1:0D:20:8A 6E-5E-E1-0D-20-8A
[DEL] Device 0C:9F:6A:15:B3:82 0C-9F-6A-15-B3-82
[DEL] Device 62:45:5C:39:72:D8 62-45-5C-39-72-D8
[DEL] Device 79:6E:5A:6D:04:3D 79-6E-5A-6D-04-3D
[DEL] Device 54:CB:F7:95:F8:81 54-CB-F7-95-F8-81
[DEL] Device 15:71:E6:8B:DB:7A 15-71-E6-8B-DB-7A
[DEL] Device 3B:5A:32:76:51:1D 3B-5A-32-76-51-1D
[DEL] Device 0C:DF:00:CF:AD:00 0C-DF-00-CF-AD-00
[DEL] Device 76:E1:BB:2B:14:03 76-E1-BB-2B-14-03
[DEL] Device E0:26:15:85:5C:FE E0-26-15-85-5C-FE
[DEL] Device EF:E2:E2:A4:91:7C EF-E2-E2-A4-91-7C
[DEL] Device 22:6F:4B:FF:8E:0E 22-6F-4B-FF-8E-0E
[DEL] Device 5D:BA:BA:AE:DF:62 5D-BA-BA-AE-DF-62
[DEL] Device 6C:78:4F:F8:38:17 6C-78-4F-F8-38-17
[DEL] Device EF:15:36:35:BA:44 EF-15-36-35-BA-44
[DEL] Device C8:FF:AB:4B:3C:A6 C8-FF-AB-4B-3C-A6
[DEL] Device 65:2F:02:DB:0A:1B 65-2F-02-DB-0A-1B
[DEL] Device CC:B5:F2:69:FB:34 CC-B5-F2-69-FB-34
[DEL] Device F9:C7:A9:7F:59:B1 F9-C7-A9-7F-59-B1
[DEL] Device C7:6C:CF:E4:AA:59 C7-6C-CF-E4-AA-59
[DEL] Device EC:74:ED:F5:3E:D1 EC-74-ED-F5-3E-D1
[DEL] Device 09:81:A3:98:B4:FE 09-81-A3-98-B4-FE
[DEL] Device 1D:84:55:27:C5:28 1D-84-55-27-C5-28
[DEL] Device CF:22:89:EC:2C:A8 CF-22-89-EC-2C-A8
[DEL] Device F5:2B:52:8F:57:DA F5-2B-52-8F-57-DA
[DEL] Device 45:14:96:5C:1E:AD 45-14-96-5C-1E-AD
[DEL] Device CF:A6:21:D9:B8:82 CF-A6-21-D9-B8-82
[DEL] Device C1:C5:3B:B0:16:29 C1-C5-3B-B0-16-29
[DEL] Device 7C:EB:A5:67:B8:4C 7C-EB-A5-67-B8-4C
Adapter property changed
[CHG] Controller 8C:88:4B:65:AB:B2 Discovering: no
Connection successful
Service added /org/bluez/hci0/dev_22_22_33_44_55_67/service0004
Service added /org/bluez/hci0/dev_22_22_33_44_55_67/service0008
Char added /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char0009:
Char added /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char000b:
Services resolved yes
Found matching char: path /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char0009, uuid 00002adb-0000-1000-8000-00805f9b34fb
Found matching char: path /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char000b, uuid 00002adc-0000-1000-8000-00805f9b34fb
Start notification on /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char000b
Characteristic property changed /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char000b
AcquireNotify success: fd 7 MTU 517
Notify for Mesh Provisioning Out Data started
Open-Node: 0x564818b5fcd0
Open-Prov: 0x564818bf9090
Open-Prov: proxy 0x564818beb840
Initiated provisioning
Characteristic property changed /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char0009
AcquireWrite success: fd 8 MTU 517
GATT-TX: 03 00 10
GATT-RX: 03 01 01 00 01 00 00 00 00 00 00 00 00
Got provisioning data (12 bytes)
01 01 00 01 00 00 00 00 00 00 00 00
GATT-TX: 03 02 00 00 00 00 00
GATT-TX: 03 03 12 4c 8d 12 ba 5a dd bf 80 37 70 78 04 3d
GATT-TX: 18 55 e8 22 d8 b7 0d 50 27 ba c5 60 b9 b8 87 c7
GATT-TX: 59 0d b2 0c f4 4c dd 96 c1 d7 af bd d5 24 18 9e
GATT-TX: 99 78 2f 29 11 9a e5 8f 61 66 cf 0c 3f c0 6d 91
GATT-TX: 5a 9a
GATT-RX: 03 03 81 07 3a c7 3d f8 b6 88 64 12 6d ee 1e e5
GATT-RX: 60 b4 a7 48 b7 44 28 c1 ca a2 c0 84 95 5a 51 3d
GATT-RX: fd f4 db 68 f2 d5 ce 61 9e d8 d0 68 de 10 00 e9
GATT-RX: 39 1c 2f f5 22 fc 42 2d 63 dc 35 b7 02 c8 0f d8
GATT-RX: 7c 79
Got provisioning data (65 bytes)
03 81 07 3a c7 3d f8 b6 88 64 12 6d ee 1e e5 60
b4 a7 48 b7 44 28 c1 ca a2 c0 84 95 5a 51 3d fd
f4 db 68 f2 d5 ce 61 9e d8 d0 68 de 10 00 e9 39
1c 2f f5 22 fc 42 2d 63 dc 35 b7 02 c8 0f d8 7c
79
GATT-TX: 03 05 d5 0a 2b f3 a9 ea 19 cc 2f b4 dc f7 98 c1
GATT-TX: 64 a0
GATT-RX: 03 05 6d 86 73 e0 56 6a 97 86 2d 3b f8 41 a2 44
GATT-RX: e6 55
Got provisioning data (17 bytes)
05 6d 86 73 e0 56 6a 97 86 2d 3b f8 41 a2 44 e6
55
GATT-TX: 03 06 a0 73 22 20 3e 87 7e f6 eb dd 11 26 d7 4b
GATT-TX: 41 23
GATT-RX: 03 06 49 64 38 fe fd b7 a2 f5 4d 72 84 ef 2d f9
GATT-RX: c9 db
Got provisioning data (17 bytes)
06 49 64 38 fe fd b7 a2 f5 4d 72 84 ef 2d f9 c9
db
Confirmation Validated
S-Key 37 28 eb 0d 84 2c bb 4a b5 ee 82 27 b3 bc 7a 7a
S-Nonce e0 13 19 56 b8 6f 53 d0 cb de 61 0f 96
DevKey 60 5f d6 65 b1 51 c7 ec 76 55 cc d6 bd 61 83 54
Data 18 ee d9 c2 a5 6a dd 85 04 9f fc 3c 59 ad 0e 12
Data 00 00 00 00 00 00 05 01 04
DataEncrypted + mic 4d 44 78 a5 96 b1 69 3e b3 6b 57 75 68 d8 d4 10
DataEncrypted + mic cf 96 da c7 62 02 ab 03 23 57 66 f7 58 6e 8a a2
DataEncrypted + mic a0
GATT-TX: 03 07 4d 44 78 a5 96 b1 69 3e b3 6b 57 75 68 d8
GATT-TX: d4 10 cf 96 da c7 62 02 ab 03 23 57 66 f7 58 6e
GATT-TX: 8a a2 a0
GATT-RX: 03 08
Got provisioning data (1 bytes)
08
Provision success. Assigned Primary Unicast 0104
Attempting to disconnect from 22:22:33:44:55:67
Characteristic property changed /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char000b
Write closed
Services resolved no
Characteristic property changed /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char0009
SetDiscoveryFilter success
Discovery started
Adapter property changed
[CHG] Controller 8C:88:4B:65:AB:B2 Discovering: yes
Mesh Proxy Service (00001828-0000-1000-8000-00805f9b34fb)
Identity for node 0104
Trying to connect to mesh
Adapter property changed
[CHG] Controller 8C:88:4B:65:AB:B2 Discovering: no
Connection successful
Service added /org/bluez/hci0/dev_22_22_33_44_55_67/service0008
Char added /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char0009:
Char added /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char000b:
Services resolved yes
Found matching char: path /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char0009, uuid 00002add-0000-1000-8000-00805f9b34fb
Found matching char: path /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char000b, uuid 00002ade-0000-1000-8000-00805f9b34fb
Start notification on /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char000b
Characteristic property changed /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char000b
AcquireNotify success: fd 7 MTU 517
Notify for Mesh Proxy Out Data started
Trying to open mesh session
[AC632N_1-Node-0104]# menu config
Menu config:
Available commands:
-------------------
target <unicast> Set target node to configure
composition-get [page_num] Get composition data
netkey-add <net_idx> Add network key
netkey-del <net_idx> Delete network key
appkey-add <app_idx> Add application key
appkey-del <app_idx> Delete application key
bind <ele_idx> <app_idx> <mod_id> [cid] Bind app key to a model
mod-appidx-get <ele_addr> <model id> Get model app_idx
ttl-set <ttl> Set default TTL
ttl-get Get default TTL
pub-set <ele_addr> <pub_addr> <app_idx> <per (step|res)> <re-xmt (cnt|per)> <mod id> [cid]
Set publication
pub-get <ele_addr> <model> Get publication
proxy-set <proxy> Set proxy state
proxy-get Get proxy state
ident-set <net_idx> <state> Set node identity state
ident-get <net_idx> Get node identity state
beacon-set <state> Set node identity state
beacon-get Get node beacon state
relay-set <relay> <rexmt count> <rexmt steps> Set relay
relay-get Get relay
hb-pub-set <pub_addr> <count> <period> <ttl> <features> <net_idx> Set heartbeat publish
hb-pub-get Get heartbeat publish
hb-sub-set <src_addr> <dst_addr> <period> Set heartbeat subscribe
hb-sub-get Get heartbeat subscribe
sub-add <ele_addr> <sub_addr> <mod id> [cid] Add subscription
sub-get <ele_addr> <model id> Get subscription
node-reset Reset a node and remove it from network
back Return to main menu
version Display version
quit Quit program
exit Quit program
help Display help about this program
export Print environment variables
[AC632N_1-Node-0104]# target 0104
Configuring node 0104
[config: Target = 0104]# netkey-add 0
Characteristic property changed /org/bluez/hci0/dev_22_22_33_44_55_67/service0008/char0009
AcquireWrite success: fd 8 MTU 517
GATT-TX: 00 f4 4b 20 52 4f 7a 51 bd fe 33 79 10 60 88 dc
GATT-TX: 8f 63 e6 43 93 5f b7 12 f8 1c f3 bf 00 60
GATT-TX: 00 f4 d2 75 b4 61 50 b0 65 68 8d 45 86 33 a2 d8
GATT-TX: 0d 55 ef b6 5b de 21 37 90 6d f0 80 c9 b8
GATT-RX: 00 f4 5b eb 17 dd 47 9e 36 9a f7 0f c0 35 03 d5
GATT-RX: f1 c4 63 92 72 d6 d3 76 94
GATT-RX: 01 01 00 d4 76 79 43 3f db 10 4a 00 00 00 05 f4
GATT-RX: 0a 41 fa b0 af 32 0b
iv_upd_state = IV_UPD_NORMAL
GATT-TX: 02 f4 b6 f1 b6 1b 6a 39 22 ea 85 f9 ae b2 02 14
GATT-TX: 35 97 01 f2
Mesh session is open
GATT-TX: 00 f4 c9 c3 4e e1 49 62 ad a5 2f 7b 75 77 dd 43
GATT-TX: c9 9c 51 a1 d5 3b
GATT-RX: 00 f4 99 bd 50 76 4f ef f0 0b ac 78 be d1 f0 62
GATT-RX: 43 87 b0 d1 40 78 6d 90
Node 0104 NetKey status Success
NetKey 000
GATT-RX: 02 f4 64 2f 03 ff 04 2a 7f 5e ec 57 df 72 bd ee
GATT-RX: 98 00 2e af f8 22
Proxy Accept list filter length: 0
GATT-RX: 00 f4 eb d8 51 b6 2c 3f 38 95 e8 fe 84 b8 0a c9
GATT-RX: 28 8d 11 64 eb 9d 34 7e 75 bb 24 67 97 a2
GATT-RX: 00 f4 df 56 57 94 d0 ee 34 cc c9 5a 07 15 40 c2
GATT-RX: 12 55 ad 2d 1e 64 04 01 24 f7 13 4a 7e 9c
GATT-RX: 00 f4 e9 32 09 77 b6 81 eb 2e 2e 97 9a ff 6c bd
GATT-RX: ae b2 1a df 9b 5e
Composition data for node 0104 {
"cid":"05d6",
"pid":"0000",
"vid":"0000",
"crpl":"000a",
"features":{
"relay":true,
"proxy":true,
"friend":false,
"lpn":false
},
"elements":[
{
"elementIndex":0,
"location":"0000",
"models":[
"0000",
"1000"
]
}
]
}
GATT-TX: 00 f4 e1 f5 d4 6d 35 da 6a 1e 87 8c ee f5 12 ca
GATT-TX: 72 4c 6d 3f ad 33 41 aa c7
[config: Target = 0104]# appkey-add 1
GATT-TX: 00 f4 85 39 cf bd ec 19 0d 70 72 07 35 97 b5 a7
GATT-TX: 21 06 fc 1c ba db 4a d7 9d d6 d9 2d d2 26
GATT-TX: 00 f4 aa 8b 46 0c 51 70 4f ff 22 9e 48 26 32 23
GATT-TX: 2b a1 e6 92 b3 34 36 1a 86 a2 34 4f 88 d1
GATT-RX: 00 f4 48 4b fc 76 9b 3c f9 a5 1f ab 00 2f 15 df
GATT-RX: a6 3c ce f1 0f 74 9c 5a 9e
GATT-RX: 00 f4 a2 bd 66 83 46 de c5 d9 6f 77 2b 77 d0 9e
GATT-RX: fd 68 cb c0 ae 3d fd 39 99
Node 0104 AppKey status Success
NetKey 000
AppKey 001
[config: Target = 0104]# bind 0 1 1000
GATT-TX: 00 f4 e3 aa a0 3d 56 5b 44 aa e9 f2 3c fc d1 66
GATT-TX: 8e 81 64 72 fd 12 00 0e a8 6f 26
GATT-RX: 00 f4 6f 52 bf df d7 dc 25 1b e4 af a6 f2 6f 77
GATT-RX: c3 8a 2b 54 86 92 8a 79 bb 02 0a 02
Node 0104 Model App status Success
Element Addr 0104
Model Id 1000
AppIdx 001
[config: Target = 0104]# back
Menu main:
Available commands:
-------------------
config Configuration Model Submenu
onoff On/Off Model Submenu
list List available controllers
show [ctrl] Controller information
select <ctrl> Select default controller
security [0(low)/1(medium)/2(high)] Display or change provision security level
info [dev] Device information
connect [net_idx] [dst] Connect to mesh network or node on network
discover-unprovisioned <on/off> Look for devices to provision
provision <uuid> Initiate provisioning
power <on/off> Set controller power
disconnect [dev] Disconnect device
mesh-info Mesh networkinfo (provisioner)
local-info Local mesh node info
menu <name> Select submenu
version Display version
quit Quit program
exit Quit program
help Display help about this program
export Print environment variables
[config: Target = 0104]# menu onoff
Menu onoff:
Available commands:
-------------------
target <unicast> Set node to configure
get Get ON/OFF status
onoff <0/1> Send "SET ON/OFF" command
back Return to main menu
version Display version
quit Quit program
exit Quit program
help Display help about this program
export Print environment variables
[config: Target = 0104]# onoff 0
Destination not set
[config: Target = 0104]# target 0104
Controlling ON/OFF for node 0104
[on/off: Target = 0104]# onoff 0
GATT-TX: 00 f4 1e c3 f4 c3 67 37 69 83 5c ef 76 4a ff 9c
GATT-TX: 75 3a 64 15 d7 3b 31
GATT-RX: 00 f4 4b b4 f3 fc fd 65 82 aa ba 7e 0b 14 bf 81
GATT-RX: bc b1 dd f1 66 6e
On Off Model Message received (1) opcode 8204
00
[on/off: Target = 0104]# onoff 1
GATT-TX: 00 f4 d4 3e a6 0b b0 5a 01 4e b8 5f b0 34 ac 64
GATT-TX: 93 b2 d6 0a 60 60 a1
GATT-RX: 00 f4 47 3c 97 63 b3 ea 09 8b b6 a6 2c f5 ba 74
GATT-RX: b0 1c 23 d9 94 06
On Off Model Message received (1) opcode 8204
01
[on/off: Target = 0104]# onoff 0
GATT-TX: 00 f4 04 a2 ed 32 b7 24 ae 32 43 2d b7 11 61 db
GATT-TX: de d6 45 2b bc a0 07
GATT-RX: 00 f4 51 87 2d 6a 7d e1 08 f0 c4 15 90 5b 5c 46
GATT-RX: 64 ff b4 5b 47 a5
On Off Model Message received (1) opcode 8204
00
[on/off: Target = 0104]# onoff 1
GATT-TX: 00 f4 f0 45 44 68 0f 1e 95 7e 0f 23 ae 7d d4 6d
GATT-TX: 59 9d d6 1e 21 68 3a
GATT-RX: 00 f4 34 01 72 34 c9 4d 16 27 98 e9 aa e4 9c fc
GATT-RX: f4 a8 24 59 a2 94
On Off Model Message received (1) opcode 8204
01
[on/off: Target = 0104]# onoff 0
GATT-TX: 00 f4 b4 e2 95 13 4e ae ac cc ba 88 8f e8 b8 1c
GATT-TX: bc f7 b8 3b df 61 f7
GATT-RX: 00 f4 f0 fb 99 73 a9 cd c2 f8 8a 56 34 2b 0b c5
GATT-RX: 6d 38 35 67 2a 1a
On Off Model Message received (1) opcode 8204
00
meshctl #需要注意配置文件的路径
discover-unprovisioned on
meshctl.c
static void cmd_security(int argc, char *argv[])
{
uint8_t level;
char *end;
if (argc == 1)
goto done;
level = strtol(argv[1], &end, 10);
if (end == argv[1] || !prov_set_sec_level(level)) {
bt_shell_printf("Invalid security level %s\n", argv[1]);
return bt_shell_noninteractive_quit(EXIT_FAILURE);
}
done:
bt_shell_printf("Provision Security Level set to %u (%s)\n",
prov_get_sec_level(),
security2str(prov_get_sec_level()));
return bt_shell_noninteractive_quit(EXIT_SUCCESS);
}
prov.c
......
if (sec_level == MESH_PROV_SEC_HIGH) {
/* Enforce High Security */
if (prov->conf_in.caps.pub_type != 1 &&
prov->conf_in.caps.static_type != 1)
return prov_complete(node,
PROV_ERR_INVALID_PDU);
} else if (sec_level == MESH_PROV_SEC_MED) {
/* Enforce Medium Security */
if (prov->conf_in.caps.pub_type != 1 &&
prov->conf_in.caps.static_type != 1 &&
prov->conf_in.caps.input_size == 0 &&
prov->conf_in.caps.output_size == 0)
return prov_complete(node,
PROV_ERR_INVALID_PDU);
}
....
可以看到走的流程是不一样的
provision
# menu config
# target 0101(这个0101对应node的number shell的名字)
# netkey-add 0
# appkey-add 1
# bind 0 1 1000 (第一个0并不是netkey的index,而是element index)
# back
# menu onoff
# target 0101
# onoff 0
# onoff 1
和杰理不同,nordic sdk支持 input oob和output oob配网方式,实操发现即使设置了security 0也无法配网成功,最终还是暴力修改nordic源码完成配网
prov_device.c
static void prov_invite(const uint8_t *data)
{
printk("prov_invite\n");
PROV_BUF(buf, PDU_LEN_CAPABILITIES);
LOG_DBG("Attention Duration: %u seconds", data[0]);
if (data[0]) {
bt_mesh_attention(NULL, data[0]);
}
memcpy(bt_mesh_prov_link.conf_inputs.invite, data, PDU_LEN_INVITE);
bt_mesh_prov_buf_init(&buf, PROV_CAPABILITIES);
/* Number of Elements supported */
net_buf_simple_add_u8(&buf, bt_mesh_elem_count());
uint16_t algorithm_bm = 0;
uint8_t oob_type = bt_mesh_prov->static_val ?
BT_MESH_STATIC_OOB_AVAILABLE : 0;
// uint8_t oob_type = 0;
bool oob_availability = bt_mesh_prov->output_size > 0 ||
bt_mesh_prov->input_size > 0 || bt_mesh_prov->static_val;
// bool oob_availability = 0;
if (IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM)) {
WRITE_BIT(algorithm_bm, BT_MESH_PROV_AUTH_HMAC_SHA256_AES_CCM, 1);
}
if (IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_CMAC_AES128_AES_CCM)) {
WRITE_BIT(algorithm_bm, BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM, 1);
}
if (oob_availability && IS_ENABLED(CONFIG_BT_MESH_OOB_AUTH_REQUIRED)) {
oob_type |= BT_MESH_OOB_AUTH_REQUIRED;
WRITE_BIT(algorithm_bm, BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM, 0);
}
/* Supported algorithms */
net_buf_simple_add_be16(&buf, algorithm_bm);
/* Public Key Type */
// net_buf_simple_add_u8(&buf,
// bt_mesh_prov->public_key_be == NULL ? PUB_KEY_NO_OOB : PUB_KEY_OOB);
net_buf_simple_add_u8(&buf,
PUB_KEY_NO_OOB);
/* Static OOB Type */
// net_buf_simple_add_u8(&buf, oob_type);
net_buf_simple_add_u8(&buf, 0);
/* Output OOB Size */
// net_buf_simple_add_u8(&buf, bt_mesh_prov->output_size);
net_buf_simple_add_u8(&buf, 0);
/* Output OOB Action */
// net_buf_simple_add_be16(&buf, bt_mesh_prov->output_actions);
net_buf_simple_add_be16(&buf, 0);
/* Input OOB Size */
// net_buf_simple_add_u8(&buf, bt_mesh_prov->input_size);
net_buf_simple_add_u8(&buf, 0);
/* Input OOB Action */
// net_buf_simple_add_be16(&buf, bt_mesh_prov->input_actions);
net_buf_simple_add_be16(&buf, 0);
memcpy(bt_mesh_prov_link.conf_inputs.capabilities, &buf.data[1], PDU_LEN_CAPABILITIES);
// bt_mesh_prov_link.oob_method = AUTH_METHOD_NO_OOB;
if (bt_mesh_prov_send(&buf, NULL)) {
LOG_ERR("Failed to send capabilities");
return;
}
bt_mesh_prov_link.expect = PROV_START;
}
这样强制修改oob认证方式,改成no oob,这样配网者就没得选了吧?其他配网流程和杰理node开发板一致,直接配网成功
https://blog.csdn.net/love131452098/article/details/116258471[基于Bluez的Bluetoothctl BLE开发]
https://blog.csdn.net/qq_33475105/article/details/115415570[基于树莓派4B部署Bluez v5.54打造BLE Mesh Provisioner]
https://codeantenna.com/a/o5V3Wpwpqw[深入理解蓝牙Mesh的Bluez协议栈支持(1/5)]
https://codeantenna.com/a/PNX7g3QEUA[深入理解蓝牙Mesh的Bluez协议栈支持(2/5)]
https://www.cnblogs.com/zjutlitao/p/9576589.html[]
https://lupyuen.github.io/articles/bluetooth-mesh-with-nrf52-and-apache-mynewt[Bluetooth Mesh with nRF52 and Apache Mynewt]
https://blog.csdn.net/qq_33475105/article/details/115416937
【开发你的第一个nRF Connect SDK(NCS)/Zephyr应用程序】[中文互联网发现的最详细的ncs教学]
https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-3-elements-of-an-nrf-connect-sdk-application/【nordic官方ncs入门教程】