我是靠谱客的博主 俭朴曲奇,最近开发中收集的这篇文章主要介绍玩转树莓派之ZigBee网关,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

*参考文档:ug129-zigbee-gateway-ref-design-guide>>

1.树莓派ZigBee网关架构:

ZigBee Host应用程序运行在树莓派系统上,EM3588 USB CEL或者EFR332MG开发板作为NCP,Host与NCP之间通过串口连接,并通过串口通讯协议EZSP进行通讯

2.通过SSH远程登录树莓派后,输入以下命令安装好软件(请不要复制前面的“$”符号以及后面的注释),附上软件源列表文件

$ sudo apt-get update //更新软件源
$ sudo apt-get install dirmngr //安装dirmngr
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 90CE4F77 //添加公秘钥
$ sudo chmod 666 /etc/apt/sources.list//更改文档操作权限
$ sudo echo deb http://devtools.silabs.com/solutions/apt stretch main >> /etc/apt/sources.list//添加Silabs的软件源
$ sudo echo deb http://mirrors.aliyun.com/raspbian/raspbian/ stretch main non-free contrib >> /etc/apt/sources.list //添加aliyun的软件源
$ sudo apt-get update //更新软件源
$ sudo apt-get install silabs-zigbee-gateway //安装ZigBee gateway的host应用软件
$ sudo apt-get install silabs-networking //安装芯科的WiFi网络
$ sudo reboot //最后重启树莓派
 GNU nano 2.7.4                              文件: /etc/apt/sources.list                                       

deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi
deb http://devtools.silabs.com/solutions/apt stretch main
deb http://mirrors.aliyun.com/raspbian/raspbian/ stretch main non-free contrib

3.烧录对应的NCP软件和Bootloader

文件路径:
C:SiliconLabsSimplicityStudiov4developersdksgecko_sdk_suitev2.5protocolzigbeencp-images
Bootloader路径:
C:SiliconLabsSimplicityStudiov4developersdksgecko_sdk_suitev2.5platformbootloadersample-apps

 目前最新的V6.5.3.0版本SDK中EFR32系列只有“ncp-spi”和“ncp-uart-hw”两种固件,EM3XX系列有“ncp-spi”、“ncp-uart-hw”和“ncp-uart-sw”三种固件

“ncp-uart-hw”和“ncp-uart-sw”两种固件的区别在于前者的波特率是基于RTS/CTS的硬件控制流,后者是基于xon/xoff的软件控制流,BootLoader也是需要一起烧录的

4.(若EFR32开发板做NCP请跳过此步骤EM35XX(CP2104USB驱动芯片)作NCP需要修改ncp.py文件,输入以下命令

$ sudo nano /opt/siliconlabs/zigbeegateway/tools/ncp-updater/ncp.py

修改ncp.py文件里面的scan函数的两个if判断条件(注意python是严格的编程规范,否则会报错):

a.

# Check which USB NCP device
            if vid == CEL_VID and pid == CEL_PID or vid == WSTK_VID and pid == WSTK_PID or vid == ETRX_VID and pid == ETRX_PID or vid == CP201x_VID and pid == CP201x_PID: and pid == CEL_PID or vid == WSTK_VID and pid == WSTK_PID or vid == ETRX_VID and pid == ETRX_PID or vid == CP201x_VID and pid == CP201x_PID:

去掉PID限制条件,改成

# Check which USB NCP device
            if vid == CEL_VID  or vid == WSTK_VID  or vid == ETRX_VID  or vid == CP201x_VID:

b.

# Check if WSTK board
if vid == WSTK_VID and pid == WSTK_PID:
    BAUD = WSTK_BAUDand pid == WSTK_PID:
    BAUD = WSTK_BAUD

去掉PID限制条件,改成

# Check if WSTK board
if vid == WSTK_VID:
    BAUD = WSTK_BAUD

5.调用scan函数扫描USB NCP设备,查看网关(host)与开发板(ncp)连接状态

$ sudo python /opt/siliconlabs/zigbeegateway/tools/ncp-updater/ncp.py scan

输出如下,说明已经可以扫描到设备了:

Connecting to.. /dev/ttyUSB0 57600 True False 
Exception: <class 'serial.serialutil.SerialException'> /dev/ttyUSB0 
Exception: <type 'exceptions.IndexError'> /dev/ttyAMA0 
{"ports": [{"deviceType": "unknown", "pid": "EA60", "port": "/dev/ttyUSB0", "vid": "10C4"}, {"deviceType": "unknown", "port": "/d

6.开启/关闭网关Host服务

可以通过页面的“设置”图标,设置ZigBee的网络的信道、PanID和发射功率,也可以通过以下命令随机参数建网

$ sudo service siliconlabsgateway start  //开启host服务
$ sudo service siliconlabsgateway stop   //关闭host服务

7.重启host服务,需输入以下命令(请不要复制前面的“$”符号以及后面的注释)

$ ls /dev/tty* -lh    //查看开发板NCP的USB端口名称,通过时间戳筛选
$ cd /opt/siliconlabs/zigbeegateway/bin/    //切换目录
$ sudo service siliconlabsgateway stop
$ sudo ./siliconlabsgateway -n 0 -p /dev/ttyACM0   //启动NCP EFR32MG系列
或者
$ sudo ./siliconlabsgateway -n 0 -p /dev/ttyUSB0   //启动NCP EM35XX系列

如果host和ncp的EmberZNet stack版本不一致会导致无法匹配,出现问题如无法建网>>

同时会打印信息如下:

Reset info: 11 (SOFTWARE)
ERROR: NCP EZSP protocol version of 0x05 does not match Host version 0x06
siliconlabsgateway: ../../../protocol/zigbee/app/framework/util/af-main-host.c:1171: emAfCliVersionCommand: Assertion `0' failed.
Z3GatewayHost>已放弃

此时只需要将NCP软件烧录成6.2.3版本的即可恢复正常,初始化建网成功打印信息如下:

Reset info: 11 (SOFTWARE)
ezsp ver 0x06 stack type 0x02 stack ver. [6.2.3 GA build 204]
Ezsp Config: set source route table size to 0x00FA:Success: set
Ezsp Config: set security level to 0x0005:Success: set
Ezsp Config: set address table size to 0x0002:Success: set
Ezsp Config: set TC addr cache to 0x0002:Success: set
Ezsp Config: set stack profile to 0x0002:Success: set
Ezsp Config: set MAC indirect TX timeout to 0x1E00:Success: set
Ezsp Config: set max hops to 0x001E:Success: set
Ezsp Config: set tx power mode to 0x8000:Success: set
Ezsp Config: set supported networks to 0x0001:Success: set
Ezsp Policy: set binding modify to "allow for valid endpoints & clusters only":Success: set
Ezsp Policy: set message content in msgSent to "return":Success: set
Ezsp Value : set maximum incoming transfer size to 0x00000052:Success: set
Ezsp Value : set maximum outgoing transfer size to 0x00000052:Success: set
Ezsp Config: set binding table size to 0x0010:Success: set
Ezsp Config: set key table size to 0x0000:Success: set
Ezsp Config: set max end device children to 0x0020:Success: set
NCP supports maxing out packet buffers
Ezsp Config: set packet buffers to 255
Ezsp Config: set end device poll timeout to 0x0005:Success: set
Ezsp Config: set end device poll timeout shift to 0x0006:Success: set
Ezsp Config: set zll group addresses to 0x0000:Success: set
Ezsp Config: set zll rssi threshold to 0xFF80:Success: set
Ezsp Config: set transient key timeout to 0x00B4:Success: set
Ezsp Endpoint 1 added, profile 0x0104, in clusters: 8, out clusters 19
Ezsp Endpoint 242 added, profile 0xA1E0, in clusters: 0, out clusters 1
MQTT not connected, message not sent: relays - {"relays":[]}
HA Gateweay EUI64 = 000B57FFFE0BC5FD
MQTT Client Init
MQTT Client ID = gw000B57FFFE0BC5FD
Found 0 files

EMBER_NETWORK_UP 0x0000

建网成功后,敲“回车”,可输入CLI命令控制网关组网、允许设备加入、find and bind 等

8.如果树莓派系统是桌面版本,还可以通过VNC Viewer连接树莓派桌面,打开浏览器输入“localhost,进入host管理界面:

加入一个新设备,点击“+ZigBee3.0 Device”按钮,开启PJoin 180s时间:

最后

以上就是俭朴曲奇为你收集整理的玩转树莓派之ZigBee网关的全部内容,希望文章能够帮你解决玩转树莓派之ZigBee网关所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部