安装 MQTT
1
2
3
4
5
|
mqtt-server/
├── docker-compose.yml
├── mosquitto/
│ ├── mosquitto.conf
│ └── passwd # 用户密码文件(可选)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
version: '3.8'
services:
mosquitto:
image: eclipse-mosquitto:2.0
container_name: mosquitto
restart: unless-stopped
ports:
- "1883:1883" # MQTT 协议
- "9001:9001" # WebSocket 支持
# - "8883:8883" # TLS(可选,需配置证书)
volumes:
- ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
# - ./mosquitto/passwd:/mosquitto/config/passwd # 认证文件
- mosquitto_data:/mosquitto/data
- mosquitto_log:/mosquitto/log
# 可选:设置时区
environment:
- TZ=Asia/Shanghai
# 网络模式(可选)
# network_mode: host
volumes:
mosquitto_data:
mosquitto_log:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# 监听端口
listener 1883
protocol mqtt
# WebSocket 支持
listener 9001
protocol websockets
# 持久化设置
persistence true
persistence_location /mosquitto/data/
# 日志
log_dest file /mosquitto/log/mosquitto.log
log_type all
# 关闭时间戳(Docker 日志已有)
log_timestamp false
# ==================================================
# 🔐 认证配置(可选:开启用户名密码)
# ==================================================
allow_anonymous true # 允许匿名访问
# password_file /mosquitto/config/passwd
# ==================================================
# 🔐 TLS 配置(可选:开启 HTTPS/WebSocket Secure)
# ==================================================
# listener 8883
# protocol mqtt
# cafile /mosquitto/config/certs/ca.crt
# certfile /mosquitto/config/certs/server.crt
# keyfile /mosquitto/config/certs/server.key
# require_certificate false
|
MQTT 开启用户名密码认证(可选)
步骤 1:生成密码文件
1
2
3
4
5
6
7
8
9
|
# 进入 mosquitto 目录
cd mqtt-server/mosquitto
# 创建 passwd 文件(第一次用 -c)
mosquitto_passwd -c passwd your_username
# 输入密码
# 再添加其他用户用(去掉 -c)
# mosquitto_passwd passwd another_user
|
步骤 2:取消 mosquitto.conf
中的认证注释
1
2
|
allow_anonymous false
password_file /mosquitto/config/passwd
|
开启 TLS 加密(可选)
如果你有证书,放入 mosquitto/certs/
目录,并取消 mosquitto.conf
中 TLS
部分注释。
端口映射加上:
部署 Frigate
1
2
3
4
|
frigate/
├── docker-compose.yml
├── config/
│ └── config.yml
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
services:
frigate:
container_name: frigate
restart: unless-stopped
stop_grace_period: 30s
image: docker.cnb.cool/frigate-cn/frigate:stable
volumes:
- ./config:/config
- ./storage:/media/frigate
- type: tmpfs # 可选:1GB内存,减少SSD/SD卡损耗
target: /tmp/cache
tmpfs:
size: 1000000000
ports:
- "8971:8971"
- "8554:8554" # RTSP 视频流
- "5050:5000" # Web UI
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
mqtt:
enabled: true
host: mosquitto
port: 1883
user: # 没有可以删除
password: # 没有可以删除
# 录制配置,保留7天的陆续变动
record:
enabled: true
retain:
days: 7
mode: motion
alerts:
retain:
days: 30
detections:
retain:
days: 30
snapshots:
enabled: true
retain:
default: 30
cameras:
camera_name: # <--- 此处改为你摄像头的名称,仅支持英文数字下划线与连接符
enabled: true
ffmpeg:
inputs:
- path: rtsp://账号:密码@摄像头IP:554/stream1 # <--- 此处改为你摄像头的rtsp地址
roles:
- detect
- record
detect:
enabled: true
width: 3840 # <- 可选,默认Frigate会尝试自动检测分辨率
height: 2160 # <- 可选,默认Frigate会尝试自动检测分辨率
objects:
filters:
person:
mask: 0.005,0.008,0.421,0.009,0.452,0.988,0.007,0.995
motion:
mask: 0.007,0.008,0.421,0.009,0.452,0.988,0.007,0.995
go2rtc:
streams:
tplink_dw: ## <- 这里的back为摄像头名称,根据你的实际情况进行调整
- "ffmpeg:rtsp://账号:密码@摄像头IP:554/stream1/cam/realmonitor?channel=1&subtype=2#video=copy#audio=copy#audio=aac#hardware"
version: 0.16-0
|
rtsp://账号:密码@摄像头IP:554/stream1
账号:密码
:在 Frigate
部署后,访问 UI
平台,账号默认是 admin
,密码自己设置
摄像头IP
:TP-LINK物联
APP -> 摄像头 -> 更多设置 -> 关于此摄像机 -> IP地址
HomeAssistant 中添加 Frigate
安装 Advanced Camera Card
和 Frigate
(图1
)
添加 MQTT
(图2
)
添加 Frigate
(图3
)
地址填写 Frigate
的 Web UI
地址
(图4
)
添加卡片
(图5
)
首页效果
(图6
)