系統介紹
樹莓派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: 可選,擴展應用
以下為視頻演示: