Skip to content

Commit

Permalink
Issue #4: Some Mosquitto mqtt configuration for Frigate.
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Jan 12, 2023
1 parent 77b2264 commit 4e62043
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ The Frigate `docker-compose` configures the Frigate storage volume to be synced

In my case, I either set up a RAID volume or a single disk (NVMe, SSD, or HDD), and made sure it was mounted at the path `/mnt/frigate` before running the playbook.

> There are a number of great guides for Frigate out there, but I am indebted especially to [this Frigate guide from Simplepush](https://www.simplepush.io/blog/frigate-nvr-push-notification-guide#run-mosquitto-mqtt-in-docker) for a broad understanding of all Frigate's moving parts.
### Shinobi setup

After the playbook completes, visit the URL of your NVR, at the `/super` path, e.g. `http://dvr.local:8080/super`. The default login credentials are:
Expand Down
5 changes: 5 additions & 0 deletions example.inventory.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@

[dvr:vars]
ansible_user=admin

frigate_rtsp_password=changeme
frigate_configure_mqtt_broker=1
frigate_mosquitto_password=changeme
frigate_mosquitto_extra_user=myusername
frigate_mosquitto_extra_user_password=changeme
19 changes: 19 additions & 0 deletions frigate/docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,22 @@ services:
- "1935:1935" # RTMP feeds
environment:
FRIGATE_RTSP_PASSWORD: "{{ frigate_rtsp_password }}"
{% if frigate_configure_mqtt_broker %}

mqtt:
container_name: mqtt
image: eclipse-mosquitto:2
volumes:
- ./mosquitto/logs/:/mosquitto/logs/
- ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
- ./mosquitto/mqtt-auth.conf:/mosquitto/config/mqtt-auth.conf
- ./mosquitto/mqtt-acl.conf:/mosquitto/config/mqtt-acl.conf
restart: unless-stopped
networks:
- frigate
ports:
- "1883:1883"
{% endif %}

networks:
frigate:
23 changes: 23 additions & 0 deletions frigate/frigate.yml.j2
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
database:
path: /db/frigate.db
mqtt:
host: mqtt
topic_prefix: frigate
client_id: frigate
user: frigate
password: {{ frigate_mosquitto_password }}
detectors:
coral:
type: edgetpu
device: usb
cameras:
office:
ffmpeg:
inputs:
- path: rtsp://10.0.10.10:554/rtsp
roles:
- detect
- rtmp
rtmp:
enabled: False # RTMP should be disabled if your stream is not H264
detect:
width: 1280 # update for your camera's resolution
height: 720 # update for your camera's resolution
25 changes: 20 additions & 5 deletions frigate/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,41 @@
- docker-compose
state: present

- name: Create Frigate folder on Pi.
- name: Create Frigate folders on Pi.
ansible.builtin.file:
path: "~/frigate"
path: "{{ item }}"
state: directory
mode: '0755'
become: false
with_items:
- "~/frigate"
- "~/frigate/mosquitto"
- "~/frigate/mosquitto/logs"
register: create_folders

- name: Copy Frigate files to Pi.
ansible.builtin.template:
src: "{{ item }}"
src: "{{ item }}.j2"
dest: "~/frigate/{{ item }}"
mode: '0640'
become: false
notify: Restart frigate
with_items:
- docker-compose.yml.j2
- frigate.yml.j2
- docker-compose.yml
- frigate.yml
- mosquitto/mosquitto.conf
- mosquitto/mqtt-auth.conf
- mosquitto/mqtt-acl.conf

- name: Ensure Frigate is running.
community.docker.docker_compose:
project_src: "~/frigate/"
build: false
become: false

# TODO: This is the right command... but it doesn't seem to be running.
- name: Encrypt the mosquitto passwords.
community.docker.docker_container_exec:
container: mqtt
command: 'mosquitto_passwd -U /mosquitto/config/mqtt-auth.conf'
when: frigate_configure_mqtt_broker
10 changes: 10 additions & 0 deletions frigate/mosquitto/mosquitto.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
persistence true
persistence_location /mosquitto/data

log_dest file /mosquitto/logs/mosquitto.log
log_dest stdout

listener 1883

allow_anonymous false
password_file /mosquitto/config/mqtt-auth.conf
5 changes: 5 additions & 0 deletions frigate/mosquitto/mqtt-acl.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
user frigate
topic frigate/#

user {{ frigate_mosquitto_extra_user }}
topic frigate/#
2 changes: 2 additions & 0 deletions frigate/mosquitto/mqtt-auth.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
frigate: {{ frigate_mosquitto_password }}
{{ frigate_mosquitto_extra_user }}: {{ frigate_mosquitto_extra_user_password }}
2 changes: 1 addition & 1 deletion main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
become: true

vars:
docker_users: ['pi']
docker_users: ['{{ ansible_user }}']

handlers:
- name: reboot pi
Expand Down

0 comments on commit 4e62043

Please sign in to comment.