-
Notifications
You must be signed in to change notification settings - Fork 9
MQTT Integration
MiBee NVR supports MQTT-based recording triggers for smart home automation and event-driven recording. When an MQTT message is received, the system can start recording on a specific camera for a configurable duration.
- Protocol: MQTT (Message Queuing Telemetry Transport)
-
Topic Pattern:
{prefix}/trigger/{camera_id} -
Payload: JSON with
actionfield -
Actions:
record,stop,snapshot - Auto-reconnect: Built-in with exponential backoff
mqtt:
broker_url: "tcp://192.168.1.100:1883"
client_id: "mibee-nvr"
topic_prefix: "mibee"
username: "mqtt_user"
password: "mqtt_password"| Field | Required | Type | Default | Description |
|---|---|---|---|---|
broker_url |
Yes | string | - | MQTT broker address (e.g., tcp://192.168.1.100:1883) |
client_id |
Yes | string | - | Unique client ID for MQTT connection |
topic_prefix |
Yes | string | - | Prefix for trigger topics (e.g., mibee) |
username |
No | string | - | MQTT username (if broker requires auth) |
password |
No | string | - | MQTT password (if broker requires auth) |
mqtt:
broker_url: "tcp://mqtt.example.com:1883"
client_id: "mibee-nvr-home"
topic_prefix: "home/security"
username: "smart_home_user"
password: "secure_password_123"Start recording on a specific camera for a set duration:
{
"action": "record"
}Topic: home/security/trigger/front-door
Message: {"action": "record"}
Topic: home/security/trigger/backyard
Message: {"action": "record"}
Stop recording on a specific camera:
{
"action": "stop"
}Topic: home/security/trigger/front-door
Message: {"action": "stop"}
Take a snapshot from a specific camera:
{
"action": "snapshot"
}Topic: home/security/trigger/front-door
Message: {"action": "snapshot"}
# Home Assistant MQTT Automation
- alias: Motion Detection - Front Door
trigger:
- platform: mqtt
topic: "zigbee2mqtt/front-door-motion/occupancy"
payload: "ON"
action:
- service: mqtt.publish
data:
topic: "home/security/trigger/front-door"
payload: '{"action": "record"}'
retain: false// Node-RED Flow Example
[
{"id": "1", "type": "mqtt in", "topic": "zigbee2mqtt/occupancy/+", "z": "2"},
{"id": "2", "type": "switch", "name": "Motion Detection", "property": "payload", "propertyType": "msg", "rules": [{"t": "eq", "v": "ON"}], "checkall": "true", "outputs": 1},
{"id": "3", "type": "function", "name": "Get Camera ID", "func": "const camera = msg.topic.split('/')[1]; msg.camera = camera; return msg;", "outputs": 1},
{"id": "4", "type": "function", "name": "Build MQTT Message", "func": "msg.topic = `home/security/trigger/${msg.camera}`; msg.payload = '{\"action\": \"record\"}'; return msg;", "outputs": 1},
{"id": "5", "type": "mqtt out", "topic": "home/security/trigger/+", "qos": "0", "retain": "false"}
]// ESP8266 Motion Detection Example
#include <PubSubClient.h>
#include <WiFi.h>
const char* mqtt_server = "192.168.1.100";
const char* topic_prefix = "home/security";
void setup() {
pinMode(D1, INPUT); // PIR sensor pin
WiFi.begin("your_ssid", "password");
client.setServer(mqtt_server, 1883);
}
void loop() {
if (digitalRead(D1) == HIGH) {
// Motion detected, trigger recording
String payload = "{\"action\": \"record\"}";
String topic = String(topic_prefix) + "/trigger/front-door";
client.publish(topic.c_str(), payload.c_str());
delay(30000); // Wait 30 seconds before next trigger
}
delay(1000);
}# Python MQTT Publisher Example
import paho.mqtt.client as mqtt
import json
import time
def on_connect(client, userdata, flags, rc):
print("Connected to MQTT broker")
client = mqtt.Client("mibee-nvr-trigger")
client.username_pw_set("mqtt_user", "mqtt_password")
client.connect("192.168.1.100", 1883)
# Trigger recording from Python
def trigger_recording(camera_id, action="record"):
topic = f"home/security/trigger/{camera_id}"
payload = json.dumps({"action": action})
client.publish(topic, payload)
print(f"Triggered {action} for {camera_id}")
# Example usage
trigger_recording("front-door", "record")
time.sleep(30) # Record for 30 seconds
trigger_recording("front-door", "stop")Check MQTT connection status and messages:
# View system logs
journalctl -u mibee-nvr -f | grep mqtt
# Docker logs
docker logs -f mibee-nvr | grep mqttVerify MQTT client status:
curl -u admin:password http://localhost:9090/api/system/healthLook for "mqtt": {"status": "ok"} in the response.
Connection Failed
WARN: mqtt connection failed: connection refused
- Solution: Check broker URL, ensure broker is running
-
Debug: Test with
mosquitto_pub -h 192.168.1.100 -t test -m hello
Authentication Failed
WARN: mqtt authentication failed
- Solution: Verify username and password in configuration
-
Debug: Test with credentials:
mosquitto_pub -u user -P pass -h broker -t test -m hello
Message Not Processed
WARN: invalid mqtt message payload format
-
Solution: Ensure JSON payload contains
actionfield - Debug: Validate payload with JSON validator
mqtt:
broker_url: "tcp://192.168.1.100:1883"
client_id: "mibee-nvr"
topic_prefix: "security"Multiple cameras can be triggered on the same broker:
security/trigger/camera1
security/trigger/camera2
security/trigger/camera3
mqtt:
broker_url: "ssl://mqtt.example.com:8883"
client_id: "mibee-nvr"
topic_prefix: "home/security"
username: "secure_user"
password: "complex_password"
# For SSL, certificates must be properly configured
ca_cert: "/path/to/ca.crt"
client_cert: "/path/to/client.crt"
client_key: "/path/to/client.key"# Zigbee2MQTT Integration
mqtt:
broker_url: "tcp://192.168.1.100:1883"
client_id: "mibee-nvr"
topic_prefix: "zigbee2mqtt"
# Camera trigger from motion sensor# Home Assistant automation to record when someone rings doorbell
- alias: Doorbell Recording
trigger:
- platform: mqtt
topic: "zigbee2mqtt/doorbell/bell_pressed"
payload: "ON"
action:
- service: mqtt.publish
data:
topic: "zigbee2mqtt/trigger/doorbell"
payload: '{"action": "record", "duration": 60}'
retain: false- Topic Organization: Use meaningful topic prefixes to organize different areas
-
Payload Validation: Always include the
actionfield in JSON payloads - Connection Reliability: Configure broker for auto-reconnect
- Error Handling: Implement retry logic in client applications
- Message Retention: Use appropriate message retention policies on the broker
- Security: Use strong passwords and SSL/TLS for production deployments
-
Verify broker is reachable:
ping 192.168.1.100 nc -zv 192.168.1.100 1883
-
Test MQTT connection manually:
mosquitto_sub -h 192.168.1.100 -t "test" -u user -P pass mosquitto_pub -h 192.168.1.100 -t "test" -m "hello" -u user -P pass
-
Check logs for processing errors:
journalctl -u mibee-nvr -f | grep mqtt -
Verify topic matching:
# Test topic matching echo '{"action": "record"}' | mosquitto_pub -h 192.168.1.100 -t "security/trigger/camera1" -u user -P pass
Validate configuration file:
./mibee-nvr -config mibee-nvr.yaml --validateEnable debug logging:
mqtt:
broker_url: "tcp://192.168.1.100:1883"
client_id: "mibee-nvr"
topic_prefix: "home/security"
observability:
log_level: "debug"GitHub | Report Issue | MIT License
Setup & Basics
Camera & Streaming
Integrations
Advanced
安装配置
摄像头与流媒体
集成
进阶