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

设置交叉编译工具链路径。

luwang@ubuntu:~/raspberry-pi/linux$ export CCPREFIX=/home/luwang/raspberry-pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf- 
luwang@ubuntu:~/raspberry-pi/linux$ ${CCPREFIX}gcc -v
Using built-in specs.
COLLECT_GCC=/home/luwang/raspberry-pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc
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
Target: arm-linux-gnueabihf
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
Thread model: posix
gcc version 4.8.3 20140106 (prerelease) (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11) 
luwang@ubuntu:~/raspberry-pi/linux$

获取kernel编译文件.config。这里从现有的Raspberry PI上获取内核编译的.config。Raspberry PI上安装的镜像是2017-11-29-raspbian-stretch.img。

在Raspberry PI上输入以下命令,生成内核配置文件

sudo modprobe configs

在linux机器上拷贝生成的Raspberry PI kernel配置文件,并解压。

scp pi@raspberrypi:/proc/config.gz PATH_TO_RASPBERRY_PI/linux gunzip -c config.gz > .config

修改配置文件以下配置选项

编译生成内核

生成内核modules

ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=../modules make modules_install

得到以下log信息

上半部log由于篇幅原因省略。这里记住版本信息是4.9.77-v7+。

在linux机器上,从linux拷贝生成的kernel到Raspberry PI

cd PATH_TO_RASPBERRY_PI/linux/arch/arm/boot/zImage pi@RASPBARRY:/tmp/kernel_new.img

在linux机器上,从linux拷贝生成的modules到Raspberry PI

将拷贝到Raspberry PI上的kernel和modules移动到boot和lib下面

在Raspberry PI启动配置文件config.tx,文件最后面加入下面内容,指定从刚生成的kernel_new.img中启动。

kernel=kernel_new.img

重启Raspberry PI

sudo shutdown -r now

确认内核信息已经更新为新生成的kernel

uname -r 4.9.77-v7+

安装后续所需依赖

json-c

下载json-c源代码

git clone https://github.com/json-c/json-c.git

编译并安装

Bluez

从以下链接下载bluez-5.48.tar.gz,并解压到本地目录

修改mesh gatt在处理数据分段时的逻辑,diff如下

编译安装

Bluetooth controller

Bluetooth controller使用的是zephyr的bluetooth/hci_uart应用,使用的分支branch是v1.10-branch。

修改串口波特率为115200.

Server端和Client端应用程序

下载AliOS-Things源代码

git clone git@github.com:alibaba/AliOS-Things.git

编译生成Server端应用

编译生成Client端应用

cd PATH_TO_AOS aos make bluetooth.blemesh_cli@esp32devkitc hci_h4=1

将生成的镜像利用esptool烧录到ESP32.

温度监测网络的搭建

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

Provisioning和配置Server节点

在Raspberry PI上,运行并进入meshctl命令行

server节点上电,并开启发现unprovisioned 设备模式,发现新unprovisioned设备

认证该设备

查看server命令行OOB输出

在Raspberry PI上键入9023,进行后续provision,后续会打印一长串log

上述log分为两个阶段,第一个阶段是利用provisioning connection进行provision,第二个阶段是建立mesh proxy connection,后续需要在这个connection上传输网络配置信息。

当上述log完整打印后,server端会打印provision成功完成的信息

接下来,是在刚才建立的mesh proxy connection上传递网络配置信息

首先是进入菜单

选择配置节点,这里可以看到节点ucast addr是0x0100

配置app key

增加sensor server model (0x1100)订阅发布地址0xc000的信息

设置sensor server model (0x1100)使用app key index = 1的app key发布信息,发布地址是0xc000,

Provisioning和配置Client节点

在Raspberry PI上,运行并进入meshctl命令行

client节点上电,并开启发现unprovisioned 设备模式,发现新unprovisioned设备

认证该设备

查看server命令行OOB输出

在Raspberry PI上键入4159,进行后续provision,后续会打印一长串log

上述log分为两个阶段,第一个阶段是利用provisioning connection进行provision,第二个阶段是建立mesh proxy connection,后续需要在这个connection上传输网络配置信息。

当上述log完整打印后,server端会打印provision成功完成的信息

接下来,是在刚才建立的mesh proxy connection上传递网络配置信息

首先是进入菜单

选择配置节点,这里可以看到节点ucast addr是0x0101

配置app key

将client节点的element 0的sensor client model (0x1102)绑定到app key index =1的app key上

增加sensor client model (0x1102)订阅发布地址0xc000的信息

设置sensor client model (0x1102)使用app key index = 1的app key发布信息,发布地址是0xc000,

上述配置全部完成后,可以在client节点看到周期性发送温度请求信息和收到回复的log

在server节点可以看到周期性接收到温度请求和发送回复的log

Last updated