SIG BLE Mesh 搭建指南

硬件准备

Raspberry PI3一块
乐鑫ESP32 Devkitc两块
微雪NRF51822开发板两块

软件环境搭建

目前,我们使用运行在Raspberry PI 3上的Bluez作为provisioner。要在Raspberry PI3上运行Bluez meshctl作为provisioner,需要对Raspberry PI的编译选项进行调整,使能一些安全相关特性,才能够正常运行meshctl。在linux上交叉编译Raspberry PI kernel。

Raspberry PI kernel

目前,我们使用运行在Raspberry PI 3上的Bluez作为provisioner。要在Raspberry PI3上运行Bluez meshctl作为provisioner,需要对Raspberry PI的编译选项进行调整,使能一些安全相关特性,才能够正常运行meshctl。在linux上交叉编译Raspberry PI kernel。
下载Raspberry PI系统源代码
git clone https://github.com/raspberrypi/linux.git
设置交叉编译工具链路径。
1
[email protected]:~/raspberry-pi/linux$ export CCPREFIX=/home/luwang/raspberry-pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-
2
[email protected]:~/raspberry-pi/linux$ ${CCPREFIX}gcc -v
3
Using built-in specs.
4
COLLECT_GCC=/home/luwang/raspberry-pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc
5
COLLECT_LTO_WRAPPER=/home/luwang/raspberry-pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../libexec/gcc/arm-linux-gnueabihf/4.8.3/lto-wrapper
6
Target: arm-linux-gnueabihf
7
Configured with: /cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/src/gcc-linaro-4.8-2014.01/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu --target=arm-linux-gnueabihf --prefix=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install --with-sysroot=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-languages=c,c++,fortran --disable-multilib --enable-multiarch --with-arch=armv6 --with-tune=arm1176jz-s --with-fpu=vfp --with-float=hard --with-pkgversion='crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11' --with-bugurl=https://bugs.launchpad.net/gcc-linaro --enable-__cxa_atexit --enable-libmudflap --enable-libgomp --enable-libssp --with-gmp=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpfr=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpc=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-isl=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-cloog=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-libelf=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --enable-threads=posix --disable-libstdcxx-pch --enable-linker-build-id --enable-plugin --enable-gold --with-local-prefix=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-c99 --enable-long-long --with-float=hard
8
Thread model: posix
9
gcc version 4.8.3 20140106 (prerelease) (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11)
10
[email protected]:~/raspberry-pi/linux$
Copied!
获取kernel编译文件.config。这里从现有的Raspberry PI上获取内核编译的.config。Raspberry PI上安装的镜像是2017-11-29-raspbian-stretch.img。
在Raspberry PI上输入以下命令,生成内核配置文件
sudo modprobe configs
在linux机器上拷贝生成的Raspberry PI kernel配置文件,并解压。
scp [email protected]:/proc/config.gz PATH_TO_RASPBERRY_PI/linux gunzip -c config.gz > .config
修改配置文件以下配置选项
1
CONFIG_CRYPTO_CMAC=y
2
CONFIG_CRYPTO_USER_API=y
3
CONFIG_CRYPTO_USER_API_HASH=y
4
CONFIG_CRYPTO_USER_API_SKCIPHER=y
Copied!
编译生成内核
1
cd PATH_TO_RASPBERRY_PI/linux
2
ARCH=arm CROSS_COMPILE=${CCPREFIX} make
Copied!
生成内核modules
ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=../modules make modules_install
得到以下log信息
1
INSTALL sound/soc/codecs/snd-soc-tas5713.ko
2
INSTALL sound/soc/codecs/snd-soc-tpa6130a2.ko
3
INSTALL sound/soc/codecs/snd-soc-wm-adsp.ko
4
INSTALL sound/soc/codecs/snd-soc-wm5102.ko
5
INSTALL sound/soc/codecs/snd-soc-wm8731.ko
6
INSTALL sound/soc/codecs/snd-soc-wm8741.ko
7
INSTALL sound/soc/codecs/snd-soc-wm8804-i2c.ko
8
INSTALL sound/soc/codecs/snd-soc-wm8804.ko
9
INSTALL sound/soc/generic/snd-soc-simple-card-utils.ko
10
INSTALL sound/soc/generic/snd-soc-simple-card.ko
11
INSTALL sound/soc/snd-soc-core.ko
12
INSTALL sound/usb/6fire/snd-usb-6fire.ko
13
INSTALL sound/usb/caiaq/snd-usb-caiaq.ko
14
INSTALL sound/usb/misc/snd-ua101.ko
15
INSTALL sound/usb/snd-usb-audio.ko
16
INSTALL sound/usb/snd-usbmidi-lib.ko
17
INSTALL .modules/lib/firmware/emi26/loader.fw
18
INSTALL .modules/lib/firmware/emi26/firmware.fw
19
INSTALL .modules/lib/firmware/emi26/bitstream.fw
20
INSTALL .modules/lib/firmware/emi62/loader.fw
21
INSTALL .modules/lib/firmware/emi62/bitstream.fw
22
INSTALL .modules/lib/firmware/emi62/spdif.fw
23
INSTALL .modules/lib/firmware/emi62/midi.fw
24
INSTALL .modules/lib/firmware/kaweth/new_code.bin
25
INSTALL .modules/lib/firmware/kaweth/trigger_code.bin
26
INSTALL .modules/lib/firmware/kaweth/new_code_fix.bin
27
INSTALL .modules/lib/firmware/kaweth/trigger_code_fix.bin
28
INSTALL .modules/lib/firmware/ti_3410.fw
29
INSTALL .modules/lib/firmware/ti_5052.fw
30
INSTALL .modules/lib/firmware/mts_cdma.fw
31
INSTALL .modules/lib/firmware/mts_gsm.fw
32
INSTALL .modules/lib/firmware/mts_edge.fw
33
INSTALL .modules/lib/firmware/edgeport/boot.fw
34
INSTALL .modules/lib/firmware/edgeport/boot2.fw
35
INSTALL .modules/lib/firmware/edgeport/down.fw
36
INSTALL .modules/lib/firmware/edgeport/down2.fw
37
INSTALL .modules/lib/firmware/edgeport/down3.bin
38
INSTALL .modules/lib/firmware/whiteheat_loader.fw
39
INSTALL .modules/lib/firmware/whiteheat.fw
40
INSTALL .modules/lib/firmware/keyspan_pda/keyspan_pda.fw
41
INSTALL .modules/lib/firmware/keyspan_pda/xircom_pgs.fw
42
INSTALL .modules/lib/firmware/cpia2/stv0672_vp4.bin
43
INSTALL .modules/lib/firmware/yam/1200.bin
44
INSTALL .modules/lib/firmware/yam/9600.bin
45
DEPMOD 4.9.77-v7+
46
[email protected]:~/raspberry-pi/linux$
Copied!
上半部log由于篇幅原因省略。这里记住版本信息是4.9.77-v7+。
在linux机器上,从linux拷贝生成的kernel到Raspberry PI
cd PATH_TO_RASPBERRY_PI/linux/arch/arm/boot/zImage [email protected]:/tmp/kernel_new.img
在linux机器上,从linux拷贝生成的modules到Raspberry PI
1
cd PATH_TO_RASPBERRY_PI/modules
2
tar czf modules.tgz *
3
scp modules.tgz [email protected]:/tmp
Copied!
将拷贝到Raspberry PI上的kernel和modules移动到boot和lib下面
1
sudo cp /tmp/kernel_new.img /boot
2
sudo tar zxf /tmp/modules.tgz
3
sudo cp -rf /tmp/lib/firmware /lib/firmware
4
sudo cp -rf /tmp/lib/modules /lib/modules
Copied!
在Raspberry PI启动配置文件config.tx,文件最后面加入下面内容,指定从刚生成的kernel_new.img中启动。
kernel=kernel_new.img
重启Raspberry PI
sudo shutdown -r now
确认内核信息已经更新为新生成的kernel
uname -r 4.9.77-v7+
安装后续所需依赖
1
sudo apt-get update
2
sudo apt-get install -y libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev autotools-dev automake libtool
Copied!

json-c

下载json-c源代码
git clone https://github.com/json-c/json-c.git
编译并安装
1
cd PATH_TO_JSON_C
2
sh autogen.sh
3
./configure
4
make
5
sudo make install
Copied!

Bluez

从以下链接下载bluez-5.48.tar.gz,并解压到本地目录
1
https://git.kernel.org/pub/scm/bluetooth/bluez.git
2
tar xvf bluez-5.48.tar.gz
Copied!
修改mesh gatt在处理数据分段时的逻辑,diff如下
1
[email protected]:~/bluez$ git diff mesh/gatt.c
2
diff --git a/mesh/gatt.c b/mesh/gatt.c
3
index 9116a9d..8d564a9 100644
4
--- a/mesh/gatt.c
5
+++ b/mesh/gatt.c
6
@@ -393,7 +393,10 @@ static bool pipe_read(struct io *io, bool prov, void *user_data)
7
break;
8
9
res = buf;
10
- mesh_gatt_sar(&res, len);
11
+ len = mesh_gatt_sar(&res, len);
12
+ if (len == 0) {
13
+ break;
14
+ }
15
16
if (prov)
17
prov_data_ready(node, res, len);
Copied!
编译安装
1
cd PATH_TO_BLUEZ
2
./bootstrap
3
./configure --enable-mesh --enable-debug
4
make
5
sudo make install
Copied!

Bluetooth controller

Bluetooth controller使用的是zephyr的bluetooth/hci_uart应用,使用的分支branch是v1.10-branch。
修改串口波特率为115200.
1
[email protected]:~/zephyr/samples/bluetooth/hci_uart$ git diff nrf5.conf
2
diff --git a/samples/bluetooth/hci_uart/nrf5.conf b/samples/bluetooth/hci_uart/nrf5.conf
3
index 4a507be..9aea95f 100644
4
--- a/samples/bluetooth/hci_uart/nrf5.conf
5
+++ b/samples/bluetooth/hci_uart/nrf5.conf
6
@@ -4,7 +4,7 @@ CONFIG_UART_CONSOLE=n
7
CONFIG_GPIO=y
8
CONFIG_SERIAL=y
9
CONFIG_UART_INTERRUPT_DRIVEN=y
10
-CONFIG_UART_NRF5_BAUD_RATE=1000000
11
+CONFIG_UART_NRF5_BAUD_RATE=115200
12
CONFIG_UART_NRF5_FLOW_CONTROL=y
13
CONFIG_MAIN_STACK_SIZE=512
14
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=51
Copied!

Server端和Client端应用程序

下载AliOS-Things源代码
git clone [email protected]:alibaba/AliOS-Things.git
编译生成Server端应用
1
cd PATH_TO_AOS
2
aos make [email protected] hci_h4=1
Copied!
编译生成Client端应用
cd PATH_TO_AOS aos make [email protected] hci_h4=1
将生成的镜像利用esptool烧录到ESP32.

温度监测网络的搭建

温度监测网络包括三种角色,provisioner,server和client。Server是温度信息的发布者,client是温度信息的订阅者。

Provisioning和配置Server节点

在Raspberry PI上,运行并进入meshctl命令行
1
[email protected]:~/bluez-5.48/mesh $ ./meshctl .
2
Local config directory not provided.
3
netkeys = 1
4
appkeys = 2
5
provisioners = 1
6
On/Off client model: new binding 0001
7
[NEW] Controller B8:27:EB:B2:E7:4A raspberrypi [default]
8
[NEW] Device EC:60:BA:B5:36:D0 AOS Device
9
Service added /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a
10
Char added /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000d:
11
Char added /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000b:
12
Service added /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service0006
Copied!
server节点上电,并开启发现unprovisioned 设备模式,发现新unprovisioned设备
1
[meshctl]# discover-unprovisioned on
2
SetDiscoveryFilter success
3
Discovery started
4
Adapter property changed
5
[CHG] Controller B8:27:EB:B2:E7:4A Discovering: yes
6
Mesh Provisioning Service (00001827-0000-1000-8000-00805f9b34fb)
7
Device UUID: dddd0000000000000000000000000000
8
OOB: 0000
Copied!
认证该设备
1
[meshctl]# provision dddd
2
Trying to connect Device EC:60:BA:B5:36:D0 AOS Device
3
Adapter property changed
4
[CHG] Controller B8:27:EB:B2:E7:4A Discovering: no
5
Connection successful
6
Services resolved yes
7
Found matching char: path /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000b, uuid 00002adb-0000-1000-8000-00805f9b34fb
8
Found matching char: path /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000d, uuid 00002adc-0000-1000-8000-00805f9b34fb
9
Start notification on /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000d
10
Characteristic property changed /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000d
11
AcquireNotify success: fd 7 MTU 65
12
Notify for Mesh Provisioning Out Data started
13
Open-Node: 0x1758dc8
14
Open-Prov: 0x1757598
15
Open-Prov: proxy 0x175a1c8
16
Initiated provisioning
17
Characteristic property changed /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000b
18
AcquireWrite success: fd 8 MTU 65
19
GATT-TX: 03 00 10
20
GATT-RX: 03 01 01 00 01 00 00 04 00 08 00 00 00
21
Got provisioning data (12 bytes)
22
01 01 00 01 00 00 04 00 08 00 00 00
23
GATT-TX: 03 02 00 00 02 03 04
24
GATT-TX: 03 03 09 da d3 a0 1e 4f 15 34 3c 1f 88 e2 1f 93
25
GATT-TX: f6 38 9b 8a 2d 3a a0 49 7a 0b 01 c6 5c 61 d9 cc
26
GATT-TX: 49 be 26 78 5c 5c de c1 05 86 6f 5a 88 0d 93 b8
27
GATT-TX: 60 e2 77 67 3d 72 f4 46 b4 5f d3 b1 87 53 cd 96
28
GATT-TX: fc ce
29
GATT-RX: 43 03 d2 68 da 6f fe cc f8 97 0e 99 84 e6 eb 93
30
GATT-RX: 15 15 aa 1d 15 5b 2a f2 e7 1f 4d c1 93 51 14 29
31
GATT-RX: 7e b7 75 0c 8d 5a 51 c8 14 29 8d 3a 73 de fa 95
32
GATT-RX: 09 42 7e 7f 0a be e2 ed e5 ff 27 43 26 f7
33
GATT-RX: c3 ab 8b ef 6f
34
Got provisioning data (65 bytes)
35
03 d2 68 da 6f fe cc f8 97 0e 99 84 e6 eb 93 15
36
15 aa 1d 15 5b 2a f2 e7 1f 4d c1 93 51 14 29 7e
37
b7 75 0c 8d 5a 51 c8 14 29 8d 3a 73 de fa 95 09
38
42 7e 7f 0a be e2 ed e5 ff 27 43 26 f7 ab 8b ef
39
6f
40
Request decimal key (0 - 9999)
41
[AOS 1m[mesh] Enter Numeric key:
Copied!
查看server命令行OOB输出
1
Initializing...
2
Bluetooth initialized
3
Server
4
Mesh initialized
5
attention_on()
6
OOB Number: 9023
7
attention_off()
Copied!
在Raspberry PI上键入9023,进行后续provision,后续会打印一长串log
1
[AOS 1m[mesh] Enter Numeric key: 9023
2
GATT-TX: 03 05 fe 7f b1 04 84 f6 e9 0d 9e c7 62 19 6d 1f
3
GATT-TX: 03 64
4
GATT-RX: 03 05 ca f5 8e 55 ff 1d 92 86 26 fa 8e 22 8c 33
5
GATT-RX: 69 80
6
Got provisioning data (17 bytes)
7
05 ca f5 8e 55 ff 1d 92 86 26 fa 8e 22 8c 33 69
8
80
9
GATT-TX: 03 06 d6 63 cd 7c e6 3b b5 9b 2b a3 f5 3e e6 7c
10
GATT-TX: 15 f1
11
GATT-RX: 03 06 7a 94 aa 7a 3b f3 1c 33 92 cf 8a 3c 86 ec
12
GATT-RX: 9d 0c
13
Got provisioning data (17 bytes)
14
06 7a 94 aa 7a 3b f3 1c 33 92 cf 8a 3c 86 ec 9d
15
0c
16
Confirmation Validated
17
S-Key 5e ee f5 44 72 cc 88 c7 3a 9a 56 db 11 4a d5 44
18
S-Nonce 82 b4 a8 f2 7b 9b 76 c7 72 8b 3f e2 07
19
DevKey f8 a9 4d 78 25 b8 47 3d 0d 3d 20 50 91 45 db 20
20
Data 18 ee d9 c2 a5 6a dd 85 04 9f fc 3c 59 ad 0e 12
21
Data 00 00 00 00 00 00 05 01 00
22
DataEncrypted + mic b7 8a f4 17 c3 e8 05 66 84 4d d6 5e 22 69 73 1c
23
DataEncrypted + mic 90 10 91 8c 5f f7 30 55 bf d1 1c 29 e9 d6 3e 78
24
DataEncrypted + mic f1
25
GATT-TX: 03 07 b7 8a f4 17 c3 e8 05 66 84 4d d6 5e 22 69
26
GATT-TX: 73 1c 90 10 91 8c 5f f7 30 55 bf d1 1c 29 e9 d6
27
GATT-TX: 3e 78 f1
28
GATT-RX: 03 08
29
Got provisioning data (1 bytes)
30
08
31
Provision success. Assigned Primary Unicast 0100
32
Attempting to disconnect from EC:60:BA:B5:36:D0
33
Characteristic property changed /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000d
34
Write closed
35
Service added /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a
36
Char added /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000b:
37
Char added /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000d:
38
Services resolved no
39
SetDiscoveryFilter success
40
Discovery started
41
Adapter property changed
42
[CHG] Controller B8:27:EB:B2:E7:4A Discovering: yes
43
44
Mesh Proxy Service (00001828-0000-1000-8000-00805f9b34fb)
45
Identity for node 0100
46
Trying to connect to mesh
47
Adapter property changed
48
[CHG] Controller B8:27:EB:B2:E7:4A Discovering: no
49
Connection successful
50
Services resolved yes
51
Found matching char: path /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000b, uuid 00002add-0000-1000-8000-00805f9b34fb
52
Found matching char: path /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000d, uuid 00002ade-0000-1000-8000-00805f9b34fb
53
Start notification on /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000d
54
Characteristic property changed /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000d
55
AcquireNotify success: fd 7 MTU 65
56
Notify for Mesh Proxy Out Data started
57
Trying to open mesh session
58
GATT-RX: 01 01 00 d4 76 79 43 3f db 10 4a 00 00 00 05 f4
59
GATT-RX: 0a 41 fa b0 af 32 0b
60
iv_upd_state = IV_UPD_NORMAL
61
Mesh session is open
62
Characteristic property changed /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000b
63
AcquireWrite success: fd 8 MTU 65
64
GATT-TX: 02 f4 9e 64 99 fe 13 cd c8 9b 0e 1c e5 61 82 cc
65
GATT-TX: ab f5 83 70
66
GATT-TX: 00 f4 b3 a6 53 65 b2 a0 cd 7a 74 9e 95 1d b7 13
67
GATT-TX: 06 e6 48 68 d5 5c
68
GATT-RX: 02 f4 e7 02 fe d4 84 81 a3 32 e7 6e 4b 1b 74 4a
69
GATT-RX: 13 95 f5 61 7f eb
70
Proxy Whitelist filter length: 0
71
GATT-RX: 00 f4 60 4f af f8 ba 30 1f a6 70 d9 cb 5f 12 dd
72
GATT-RX: 8b 0b 71 6b 68 ad 00 90 07 cf ec e0 28 fe
73
GATT-RX: 00 f4 2a e4 87 bb f8 21 34 0d 45 4c c3 de 5b e3
74
GATT-RX: 21 bb 57 9a 34 94 5a de 4d e8 ca c8 91 cd
75
GATT-RX: 00 f4 b7 a0 67 ff da 92 a3 32 4c c2 c2 4e a5 5c
76
GATT-RX: 7f 12 c7 5f 02 bc 0b 23 9f 13
77
Composition data for node 0100 {
78
"cid":"0002",
79
"pid":"0000",
80
"vid":"0000",
81
"crpl":"0005",
82
"features":{
83
"relay":false,
84
"proxy":true,
85
"friend":false,
86
"lpn":false
87
},
88
"elements":[
89
{
90
"elementIndex":0,
91
"location":"0000",
92
"models":[
93
"0000",
94
"0001",
95
"0002",
96
"1100"
97
]
98
}
99
]
100
}
101
GATT-TX: 00 f4 2b d6 e6 46 66 5b 65 31 1d 78 08 28 5d 16
102
GATT-TX: aa e2 97 b6 18 84 1f 29 7f
Copied!
上述log分为两个阶段,第一个阶段是利用provisioning connection进行provision,第二个阶段是建立mesh proxy connection,后续需要在这个connection上传输网络配置信息。
当上述log完整打印后,server端会打印provision成功完成的信息
1
Provisioning completed!
2
Net ID: 0
3
Unicast addr: 0x0100
Copied!
接下来,是在刚才建立的mesh proxy connection上传递网络配置信息
首先是进入菜单
1
[AOS Devic-Node-0100]# menu config
2
Menu config:
3
Available commands:
4
-------------------
5
target <unicast> Set target node to configure
6
composition-get [page_num] Get Composition Data
7
netkey-add <net_idx> Add network key
8
netkey-del <net_idx> Delete network key
9
appkey-add <app_idx> Add application key
10
appkey-del <app_idx> Delete application key
11
bind <ele_idx> <app_idx> <mod_id> [cid] Bind app key to a model
12
ttl-set <ttl> Set default TTL
13
ttl-get Get default TTL
14
pub-set <ele_addr> <pub_addr> <app_idx> <per (step|res)> <re-xmt (cnt|per)> <mod id> [cid]
15
Set publication
16
pub-get <ele_addr> <model> Get publication
17
proxy-set <proxy> Set proxy state
18
proxy-get Get proxy state
19
ident-set <net_idx> <state> Set node identity state
20
ident-get <net_idx> Get node identity state
21
relay-set <relay> <rexmt count> <rexmt steps> Set relay
22
relay-get Get relay
23
hb-pub-set <pub_addr> <count> <period> <features> <net_idx> Set heartbeati publish
24
sub-add <ele_addr> <sub_addr> <model id> Subscription add
25
sub-get <ele_addr> <model id> Subscription get
26
app-get <ele_addr> <model id> Get App Keys
27
back Return to main menu
28
version Display version
29
quit Quit program
30
exit Quit program
31
help Display help about this program
Copied!
选择配置节点,这里可以看到节点ucast addr是0x0100
1
[AOS Devic-Node-0100]# target 0100
2
3
Configuring node 0100
4
5
[config: Target = 0100]# target 0100[config: Target = 0100]#
Copied!
配置app key
1
[config: Target = 0100]# target 0100[config: Target = 0100]# appkey-add 1
2
GATT-TX: 00 f4 e5 ca a3 ba 03 7b db 7f a6 aa 7c 02 25 75
3
GATT-TX: 6b 2a cf d4 93 0a 02 c3 8d 22 7d 30 ee 21
4
GATT-TX: 00 f4 41 5a 17 27 bf 6f 70 59 1e 4e 60 2d be 4f
5
GATT-TX: 1e f9 0d 88 e1 d6 c1 50 f3 51 cc 6d 43 d8
6
GATT-RX: 00 f4 04 00 5a d6 cc af 78 b3 eb 70 e5 78 e9 1b
7
GATT-RX: 87 fc 43 8c b0 ad 90 a2 7a
8
GATT-RX: 00 f4 56 a5 24 11 02 10 62 67 45 42 77 77 3a 7a
9
GATT-RX: ec 3e 8f 2f 26 56 4f d3 ba
10
Node 0100 AppKey Status Success
11
NetKey 000, AppKey 001
12
13
将server节点的element 0的sensor server model (0x1100)绑定到app key index =1的app key上
14
15
[config: Target = 0100]# bind 0 1 1100
16
GATT-TX: 00 f4 cb 2a f4 45 0f 4d 25 b0 47 d8 15 72 ba 89
17
GATT-TX: 61 fc ec 15 7e fe 8c dc 30 e6 04
18
GATT-RX: 00 f4 af 08 09 a9 12 03 dd fa df 1a 5f e4 7e c1
19
GATT-RX: 4f c8 58 84 82 77 8c 62 d1 cb 59 f9
20
Node 0100 Model App Status Success
21
Element 0100 AppIdx 001
22
ModelId 1100
Copied!
增加sensor server model (0x1100)订阅发布地址0xc000的信息
1
[config: Target = 0100]# sub-add 0100 c000 1100
2
GATT-TX: 00 f4 fe fa 07 e1 60 7a 1a ac d1 26 3a 45 8e f7
3
GATT-TX: 5e 8e ff 79 9d aa 90 10 ab b8 ef
4
GATT-RX: 00 f4 a8 c7 92 53 ee 9e 15 c7 fb 47 3e e8 07 fb
5
GATT-RX: c4 ea 8a f7 2d 71 3a 33 da 12 e9 0f
6
7
Subscription changed for node 0100 status: Success
8
Element Addr: 0100
9
Subscr Addr: c000
10
Model ID: 1100
Copied!
设置sensor server model (0x1100)使用app key index = 1的app key发布信息,发布地址是0xc000,
1
[config: Target = 0100]# pub-set 0100 c000 1 0 0 1100
2
GATT-TX: 00 f4 d1 a1 54 ee 1b 9f 18 4e 3c 44 ab 57 f9 82
3
GATT-TX: 73 41 9e 9c ab 3d 5c dd ad 27 c3 18 b7 22
4
GATT-TX: 00 f4 d0 95 d8 43 e4 87 12 96 14 bf 52 55 5a 8a
5
GATT-TX: ad 00 b0 4c b4 46
6
GATT-RX: 00 f4 34 4f 18 3f cf 94 bd 90 49 6a 6d 0e 83 78
7
GATT-RX: 0c b8 7c 14 00 7e 3f b6 fa
8
GATT-RX: 00 f4 66 8c 52 14 1b f9 b8 e2 d9 27 17 0d b0 87
9
GATT-RX: 28 1a 12 65 e6 7f 36 b9 92 c2 c0 79 e8 2d
10
GATT-RX: 00 f4 60 7b 6a a5 b6 9b d4 a2 f0 80 5b e6 9e 0b
11
GATT-RX: 70 0c c9 34 a3 65 11 7f
12
13
Set publication for node 0100 status: Success
14
Publication address: 0xc000
15
Period: 0 ms
16
Retransmit count: 0
17
Retransmit Interval Steps: 0
18
GATT-TX: 00 f4 d2 0f fb e4 49 24 a0 6c 7d 34 a8 bd dc ca
19
GATT-TX: c6 a8 9f 17 d0 eb 5b 46 31
20
[config: Target = 0100]#
Copied!

Provisioning和配置Client节点

在Raspberry PI上,运行并进入meshctl命令行
1
[email protected]:~/bluez-5.48/mesh $ ./meshctl .
2
Local config directory not provided.
3
netkeys = 1
4
appkeys = 2
5
provisioners = 1
6
provisioned nodes = 1
7
On/Off client model: new binding 0001
8
[NEW] Controller B8:27:EB:B2:E7:4A raspberrypi [default]
9
[NEW] Device D6:FB:47:4F:7E:A9 AOS Device
10
Service added /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a
11
Char added /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000d:
12
Char added /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service000a/char000b:
13
Service added /org/bluez/hci0/dev_EC_60_BA_B5_36_D0/service0006
Copied!
client节点上电,并开启发现unprovisioned 设备模式,发现新unprovisioned设备
1
[meshctl]# discover-unprovisioned on
2
SetDiscoveryFilter success
3
Discovery started
4
Adapter property changed
5
[CHG] Controller B8:27:EB:B2:E7:4A Discovering: yes
6
Mesh Provisioning Service (00001827-0000-1000-8000-00805f9b34fb)
7
Device UUID: dddd0000000000000000000000000000
8
OOB: 0000
Copied!
认证该设备
1
[meshctl]# provision dddd
2
Trying to connect Device D6:FB:47:4F:7E:A9 AOS Device
3
Adapter property changed
4
[CHG] Controller B8:27:EB:B2:E7:4A Discovering: no
5
Connection successful
6
Service added /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service0006
7
Service added /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a
8
Char added /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000b:
9
Char added /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000d:
10
Services resolved yes
11
Found matching char: path /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000b, uuid 00002adb-0000-1000-8000-00805f9b34fb
12
Found matching char: path /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000d, uuid 00002adc-0000-1000-8000-00805f9b34fb
13
Start notification on /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000d
14
Characteristic property changed /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000d
15
AcquireNotify success: fd 7 MTU 65
16
Notify for Mesh Provisioning Out Data started
17
Open-Node: 0xe51ab0
18
Open-Prov: 0xe59bf0
19
Open-Prov: proxy 0xe4c200
20
Initiated provisioning
21
Characteristic property changed /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000b
22
AcquireWrite success: fd 8 MTU 65
23
GATT-TX: 03 00 10
24
GATT-RX: 03 01 01 00 01 00 00 04 00 08 00 00 00
25
Got provisioning data (12 bytes)
26
01 01 00 01 00 00 04 00 08 00 00 00
27
GATT-TX: 03 02 00 00 02 03 04
28
GATT-TX: 03 03 86 03 e8 b6 50 d7 4d 33 e3 fd aa c0 fa 46
29
GATT-TX: d5 1c a8 58 91 c1 4d de 96 30 26 8c a0 3c c3 5b
30
GATT-TX: c6 87 f4 e9 b9 08 a7 e7 2d 67 ae 3a 7c f7 1c 42
31
GATT-TX: 6a da 6d 41 ba 77 17 69 25 a1 75 46 e5 eb 31 ee
32
GATT-TX: 07 5d
33
GATT-RX: 43 03 26 00 86 9a 35 54 40 b8 be 53 a0 88 e1 55
34
GATT-RX: 19 33 ee f4 4d 03 35 12 59 6d a5 63 de a2 0a dc
35
GATT-RX: 24 e4 a7 8a 8d 42 27 76 d8 2c a9 87 69 27 68 61
36
GATT-RX: 2b 56 f8 97 3c a9 bf de b6 64 00 f5 77 91
37
GATT-RX: c3 73 3f 94 62
38
Got provisioning data (65 bytes)
39
03 26 00 86 9a 35 54 40 b8 be 53 a0 88 e1 55 19
40
33 ee f4 4d 03 35 12 59 6d a5 63 de a2 0a dc 24
41
e4 a7 8a 8d 42 27 76 d8 2c a9 87 69 27 68 61 2b
42
56 f8 97 3c a9 bf de b6 64 00 f5 77 91 73 3f 94
43
62
44
Request decimal key (0 - 9999)
45
[AOS 1m[mesh] Enter Numeric key:
Copied!
查看server命令行OOB输出
1
Initializing...
2
Bluetooth initialized
3
Mesh initialized
4
OOB Number: 4159
Copied!
在Raspberry PI上键入4159,进行后续provision,后续会打印一长串log
1
[AOS 1m[mesh] Enter Numeric key: 4159
2
GATT-TX: 03 05 20 2e 58 e4 b8 06 93 0d a2 b5 2f 7b eb 16
3
GATT-TX: 99 07
4
GATT-RX: 03 05 fd ee fd f5 3d 54 71 42 91 92 64 a4 69 46
5
GATT-RX: f7 bc
6
Got provisioning data (17 bytes)
7
05 fd ee fd f5 3d 54 71 42 91 92 64 a4 69 46 f7
8
bc
9
GATT-TX: 03 06 e6 4e 15 4c 75 e4 2d 76 d3 0b 13 64 91 f0
10
GATT-TX: ac e4
11
GATT-RX: 03 06 54 65 35 17 f6 cb 77 bc ae af 19 8e 7c 92
12
GATT-RX: 71 f3
13
Got provisioning data (17 bytes)
14
06 54 65 35 17 f6 cb 77 bc ae af 19 8e 7c 92 71
15
f3
16
Confirmation Validated
17
S-Key b4 dc cb 8f 1d 62 4e c4 95 f5 74 6d ff bc 42 d9
18
S-Nonce 54 c1 e5 68 cf a6 ec c0 47 3b 8f f4 25
19
DevKey 0c c5 26 e9 12 e3 d2 89 39 20 3a af 27 a4 f9 d2
20
Data 18 ee d9 c2 a5 6a dd 85 04 9f fc 3c 59 ad 0e 12
21
Data 00 00 00 00 00 00 05 01 01
22
DataEncrypted + mic 80 bb ca b9 3f ca ff 49 5d 22 3c d3 5a 70 45 61
23
DataEncrypted + mic ae a4 a7 7b b6 15 b6 ed df 7c 47 8f 84 8d d4 dc
24
DataEncrypted + mic db
25
GATT-TX: 03 07 80 bb ca b9 3f ca ff 49 5d 22 3c d3 5a 70
26
GATT-TX: 45 61 ae a4 a7 7b b6 15 b6 ed df 7c 47 8f 84 8d
27
GATT-TX: d4 dc db
28
GATT-RX: 03 08
29
Got provisioning data (1 bytes)
30
08
31
Provision success. Assigned Primary Unicast 0101
32
Attempting to disconnect from D6:FB:47:4F:7E:A9
33
Characteristic property changed /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000d
34
Write closed
35
Service added /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a
36
Char added /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000b:
37
Char added /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000d:
38
Services resolved no
39
SetDiscoveryFilter success
40
Discovery started
41
Adapter property changed
42
[CHG] Controller B8:27:EB:B2:E7:4A Discovering: yes
43
44
Mesh Proxy Service (00001828-0000-1000-8000-00805f9b34fb)
45
Identity for node 0101
46
Trying to connect to mesh
47
Adapter property changed
48
[CHG] Controller B8:27:EB:B2:E7:4A Discovering: no
49
Connection successful
50
Services resolved yes
51
Found matching char: path /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000b, uuid 00002add-0000-1000-8000-00805f9b34fb
52
Found matching char: path /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000d, uuid 00002ade-0000-1000-8000-00805f9b34fb
53
Start notification on /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000d
54
Characteristic property changed /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000d
55
AcquireNotify success: fd 7 MTU 65
56
Notify for Mesh Proxy Out Data started
57
Trying to open mesh session
58
GATT-RX: 01 01 00 d4 76 79 43 3f db 10 4a 00 00 00 05 f4
59
GATT-RX: 0a 41 fa b0 af 32 0b
60
iv_upd_state = IV_UPD_NORMAL
61
Mesh session is open
62
Characteristic property changed /org/bluez/hci0/dev_D6_FB_47_4F_7E_A9/service000a/char000b
63
AcquireWrite success: fd 8 MTU 65
64
GATT-TX: 02 f4 8c 6d ef 98 ac 2e 79 c8 e0 2c 83 2b 4a b4
65
GATT-TX: c9 1f e3 a9
66
GATT-TX: 00 f4 95 a2 60 a7 67 ec a4 40 e9 18 1a 69 a4 00
67
GATT-TX: c1 54 c7 3d a9 d7
68
GATT-RX: 02 f4 35 d1 c4 66 28 17 1b 6d ed 86 f9 26 19 ca
69
GATT-RX: d5 6f 3c 9e 7b cd
70
Proxy Whitelist filter length: 0
71
GATT-RX: 00 f4 98 0a 63 16 58 d9 d6 34 75 81 6d 7e a3 5f
72
GATT-RX: 83 2f 1c 58 17 ad 23 17 7d 7b 50 ee 4e 61
73
GATT-RX: 00 f4 cf 10 98 83 f6 b7 13 22 45 a0 6b 53 1b 51
74
GATT-RX: c8 35 4b a7 f4 0e f4 f3 d4 c2 0c 25 12 ec
75
GATT-RX: 00 f4 a3 1e 00 1c 07 b8 e8 a6 9f 29 aa 84 7e eb
76
GATT-RX: ee 7a 7c 6b 13 63 37 ce
77
Composition data for node 0101 {
78
"cid":"0002",
79
"pid":"0000",
80
"vid":"0000",
81
"crpl":"0005",
82
"features":{
83
"relay":false,
84
"proxy":true,
85
"friend":false,
86
"lpn":false
87
},
88
"elements":[
89
{
90
"elementIndex":0,
91
"location":"0000",
92
"models":[
93
"0000",
94
"0001",
95
"1102"
96
]
97
}
98
]
99
}
100
GATT-TX: 00 f4 71 66 e6 89 61 44 19 6b c1 75 a4 a9 b8 f2
101
GATT-TX: ed 9b b9 ee 99 b5 96 bc 05
Copied!
上述log分为两个阶段,第一个阶段是利用provisioning connection进行provision,第二个阶段是建立mesh proxy connection,后续需要在这个connection上传输网络配置信息。
当上述log完整打印后,server端会打印provision成功完成的信息
1
Provisioning completed!
2
Net ID: 0
3
Unicast addr: 0x0101
Copied!
接下来,是在刚才建立的mesh proxy connection上传递网络配置信息
首先是进入菜单
1
[AOS Device-Node-0101]# menu config
2
Menu config:
3
Available commands:
4
-------------------
5
target <unicast> Set target node to configure
6
composition-get [page_num] Get Composition Data
7
netkey-add <net_idx> Add network key
8
netkey-del <net_idx> Delete network key
9
appkey-add <app_idx> Add application key
10
appkey-del <app_idx> Delete application key
11
bind <ele_idx> <app_idx> <mod_id> [cid] Bind app key to a model
12
ttl-set <ttl> Set default TTL
13
ttl-get Get default TTL
14
pub-set <ele_addr> <pub_addr> <app_idx> <per (step|res)> <re-xmt (cnt|per)> <mod id> [cid]
15
Set publication
16
pub-get <ele_addr> <model> Get publication
17
proxy-set <proxy> Set proxy state
18
proxy-get Get proxy state
19
ident-set <net_idx> <state> Set node identity state
20
ident-get <net_idx> Get node identity state
21
relay-set <relay> <rexmt count> <rexmt steps> Set relay
22
relay-get Get relay
23
hb-pub-set <pub_addr> <count> <period> <features> <net_idx> Set heartbeati publish
24
sub-add <ele_addr> <sub_addr> <model id> Subscription add
25
sub-get <ele_addr> <model id> Subscription get
26
app-get <ele_addr> <model id> Get App Keys
27
back Return to main menu
28
version Display version
29
quit Quit program
30
exit Quit program
31
help Display help about this program
Copied!
选择配置节点,这里可以看到节点ucast addr是0x0101
1
[AOS Device-Node-0101]# target 0101
2
Configuring node 0101
3
[config: Target = 0101]# target 0101[config: Target = 0101]#
Copied!
配置app key
1
[config: Target = 0101]# target 0101[config: Target = 0101]# appkey-add 1
2
GATT-TX: 00 f4 2b 37 95 64 e7 fe ba 41 b3 c8 d9 0c f4 0c
3
GATT-TX: 76 36 a4 f0 f9 c4 f8 93 73 8a 3d 7d 7e c1
4
GATT-TX: 00 f4 43 6e 87 5d 09 0b 4b 05 a0 1b c0 48 da a1
5
GATT-TX: bf d6 9b 21 91 68 d8 b0 b4 27 57 90 61 06
6
GATT-RX: 00 f4 7f d6 9d 40 6d bc 10 5f 41 67 68 56 9c d8
7
GATT-RX: b9 77 dc 71 b5 10 ec b1 85
8
GATT-RX: 00 f4 81 91 ee 63 66 b4 5a 42 6f 70 f6 d2 12 93
9
GATT-RX: 2d 9f 21 2d fa a3 89 2f 4b
10
Node 0101 AppKey Status Success
11
NetKey 000, AppKey 001
Copied!
将client节点的element 0的sensor client model (0x1102)绑定到app key index =1的app key上
1
[config: Target = 0101]# bind 0 1 1102
2
GATT-TX: 00 f4 97 c8 22 ee 6f 11 c3 c6 7c 5c 4f 88 e4 3d
3
GATT-TX: 36 9e 19 c7 3f a8 f3 d3 d4 7d 90
4
GATT-RX: 00 f4 e9 e9 33 90 5a f3 cb 88 c1 3e 44 af f6 61
5
GATT-RX: d0 ef 47 35 35 c3 03 8a c9 43 01 7d
6
Node 0101 Model App Status Success
7
Element 0101 AppIdx 001
8
ModelId 1102
Copied!
增加sensor client model (0x1102)订阅发布地址0xc000的信息
1
[config: Target = 0101]# sub-add 0101 c000 1102
2
GATT-TX: 00 f4 c5 5e 47 70 42 84 3b 28 14 26 60 83 01 69
3
GATT-TX: 7c 25 c3 c2 d9 1d d3 fb c0 e5 65
4
GATT-RX: 00 f4 6f 71 02 d9 ec 00 cf c1 96 f0 3a 7f ea a9
5
GATT-RX: b1 fb 6d 70 31 62 d8 d0 4b 5d 81 a6
6
7
Subscription changed for node 0101 status: Success
8
Element Addr: 0101
9
Subscr Addr: c000
10
Model ID: 1102
Copied!
设置sensor client model (0x1102)使用app key index = 1的app key发布信息,发布地址是0xc000,
1
[config: Target = 0101]# pub-set 0101 c000 1 0 0 1102
2
GATT-TX: 00 f4 5a 22 c5 d2 d0 76 94 a9 7f 70 6e 64 c1 f3
3
GATT-TX: be 58 43 fc f1 61 f0 ac dc ce 4d 0b 9c f1
4
GATT-TX: 00 f4 1a 8a af 58 92 d2 d5 38 b2 0f 62 56 34 96
5
GATT-TX: 5f 08 9e 5a c6 54
6
GATT-RX: 00 f4 eb 12 ea 4f 6f 1f f8 e6 f2 92 c4 d7 82 a0
7
GATT-RX: ad 9e c9 92 9e 91 d4 a6 3c
8
GATT-RX: 00 f4 2a 11 82 c6 86 27 0a 4a 88 bf a6 02 74 56
9
GATT-RX: d5 2d 28 72 24 cd ae 91 fa dc 72 35 d7 be
10
GATT-RX: 00 f4 a7 08 14 6c 95 bd 62 07 67 1b c6 c8 95 b8
11
GATT-RX: f2 a9 3b 03 d2 82 d1 97
12
13
Set publication for node 0101 status: Success
14
Publication address: 0xc000
15
Period: 0 ms
16
Retransmit count: 0
17
Retransmit Interval Steps: 0
18
GATT-TX: 00 f4 f0 60 6a 70 db 3b e2 60 a6 c8 50 d9 03 36
19
GATT-TX: d5 a1 47 c9 2f 25 49 5e 47
Copied!
上述配置全部完成后,可以在client节点看到周期性发送温度请求信息和收到回复的log
1
Sensor status Get request sent with OpCode 0x00008231
2
Got the sensor status
3
Sensor ID: 0x2a1f
4
Temperature value: 27
Copied!
在server节点可以看到周期性接收到温度请求和发送回复的log
1
Sensor Status Get request received
2
Sensor status sent with OpCode 0x00000052
Copied!