Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MQTT TLS and custom MQTT port support #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Create a `config.yml` file in your docker volume with the following contents:
frigate:
frigate_url: http://127.0.0.1:5000
mqtt_server: 127.0.0.1
mqtt_port: 1883
mqtt_tls: false
mqtt_tls_cert_chain: "/config/certchain.crt"
mqtt_auth: false
mqtt_username: username
mqtt_password: password
Expand All @@ -28,7 +31,11 @@ dog_classification:
logger_level: INFO
```

Update your frigate url, mqtt server settings. If you are using mqtt authentication, update the username and password. Update the camera name(s) to match the camera name in your frigate config.
Update your frigate url, mqtt server settings. If you are using mqtt authentication, update the username and password.

If you are using mqtt with TLS, change mqtt_port to 8883, mqtt_tls to true and create your certchain.crt. This file should include the public key of your mqtt server and any intermediate and root CA certs in the chain.

Update the camera name(s) to match the camera name in your frigate config.

You can also update the threshold for the bird and dog classification. The threshold is the minimum confidence level for the classification to be considered valid. The default is 0.7.

Expand Down
10 changes: 7 additions & 3 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from tflite_support.task import vision
from tflite_support import metadata_schema_py_generated as _metadata_fb

import ssl
import paho.mqtt.client as mqtt
import hashlib
import yaml
Expand All @@ -28,7 +29,7 @@
firstmessage = True
_LOGGER = None

VERSION = '1.0.5'
VERSION = '1.0.6'

CONFIG_PATH = './config/config.yml'
DB_PATH = './config/classifier.db'
Expand Down Expand Up @@ -335,7 +336,7 @@ def load_config():
config = yaml.safe_load(config_file)

def run_mqtt_client():
_LOGGER.info(f"Starting MQTT client. Connecting to: {config['frigate']['mqtt_server']}")
_LOGGER.info(f"Starting MQTT client. Connecting to: {config['frigate']['mqtt_server']}:{config['frigate']['mqtt_port']}")
now = datetime.now()
current_time = now.strftime("%Y%m%d%H%M%S")

Expand All @@ -351,7 +352,10 @@ def run_mqtt_client():
password = config['frigate']['mqtt_password']
client.username_pw_set(username, password)

client.connect(config['frigate']['mqtt_server'])
if config['frigate']['mqtt_tls']:
client.tls_set(config['frigate']['mqtt_tls_cert_chain'], tls_version=ssl.PROTOCOL_TLSv1_2)

client.connect(config['frigate']['mqtt_server'], config['frigate']['mqtt_port'])
client.loop_forever()

def load_logger():
Expand Down