系统介绍
树莓派5B:系统核心,负责设备的通信管理、状态监测和数据处理。
Zigbee通信:通过 Zigbee 协调器模块进行硬件中继。系统采用 Zigbee2MQTT 框架,使 Zigbee 设备能够通过 MQTT 协议接入树莓派,实现数据的高效传输和控制。
BLE通信:由树莓派5B自身支持,直接用于与 BLE 设备的连接和数据交互,方便 BLE 终端设备的接入和管理。
WiFi通信:系统通过 WiFi 接入家庭或办公网络,终端设备连接至路由器后,树莓派5B能通过网络自动发现设备,实现无缝的设备接入与状态管理。
系统框图
树莓派开机系统配置
修改root密码
sudo -i
passwd root password
修改SSH配置,允许密码登录和root登录
sudo nano /etc/ssh/sshd_config
添加如下配置并保存
PermitRootLogin yes
PermitEmptyPasswords yes
重启ssh服务
sudo systemctl restart ssh
修改apt源
# 编辑这个文件
sudo nano /etc/apt/sources.list.d/raspi.list
# 注释掉原有的源,添加这个源
deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bookworm main
# 编辑这个文件
sudo nano /etc/apt/sources.list
# 注释掉原有的内容,添加下方内容
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
安装casaos导航页
方便安装和管理docker容器
curl -fsSL https://get.casaos.io | sudo bash
安装Zigbee2MQTT
casaos中使用如下配置文件新建一个应用
name: stirring_chiahui
services:
main_app:
cpu_shares: 10
command: []
container_name: Zigbee2MQTT
deploy:
resources:
limits:
memory: 256M
devices:
- /dev/ttyUSB0:/dev/ttyACM0
environment:
- TZ=Asia/Shanghai
image: koenkk/zigbee2mqtt:latest
labels:
icon: https://icon.casaos.io/main/all/zigbee2mqtt.png?x-oss-process=image/watermark,g_center,image_YXJ0aWNsZS9wdWJsaWMvd2F0ZXJtYXJrLnBuZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSxQXzQwCg,t_20
ports:
- target: 8080
published: "23080"
protocol: tcp
restart: unless-stopped
volumes:
- type: bind
source: /DATA/AppData/z2m/data
target: /app/data
- type: bind
source: /run/udev
target: /run/udev:ro
cap_add: []
network_mode: bridge
privileged: false
hostname: Zigbee2MQTT
x-casaos:
author: self
category: self
hostname: ""
icon: https://icon.casaos.io/main/all/zigbee2mqtt.png?x-oss-process=image/watermark,g_center,image_YXJ0aWNsZS9wdWJsaWMvd2F0ZXJtYXJrLnBuZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSxQXzQwCg,t_20
index: /
is_uncontrolled: false
port_map: "23080"
scheme: http
store_app_id: stirring_chiahui
title:
custom: Zigbee2MQTT
创建完成后停止运行,然后修改配置文件,按照如下修改,其他的不动
homeassistant: true
frontend: true
mqtt:
base_topic: zigbee2mqtt
server: mqtt://IP
user: user
password: passowrd
serial:
port: /dev/ttyACM0
其他配套软件
EMQX: MQTT Broker
Homeassistant: 控制中心
Node-Red: 可选,扩展应用
以下为视频演示: