Migrated MQTT to internal Docker network #1
Squashed commit of the following:
commit cc7419ff856867009e48aae1f1685382352a1ded
Author: Ashish D'Souza <sudouser512@gmail.com>
Date:   Sun Oct 29 20:32:38 2023 -0500
    Removed MQTT auth from pipeline
commit ef80c5a56a9d0f5adb821bfc3e83d9f2d3726c7b
Author: Ashish D'Souza <sudouser512@gmail.com>
Date:   Sun Oct 29 20:32:09 2023 -0500
    Removed forced MQTT auth from source
commit 4c00200f8e77c1c4c24d1e6ac9f425e1f3ed83a6
Author: Ashish D'Souza <sudouser512@gmail.com>
Date:   Sun Oct 29 20:31:35 2023 -0500
    Updated configs
			
			
This commit is contained in:
		
							parent
							
								
									415d4e0094
								
							
						
					
					
						commit
						3642e26c7a
					
				| 
						 | 
				
			
			@ -14,7 +14,7 @@ pipeline {
 | 
			
		|||
                    frigate_config = readJSON file: 'frigate_config.json'
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                ansiblePlaybook credentialsId: 'rivendell-ssh-key', disableHostKeyChecking: true, extras: "--extra-vars 'mqtt_password=\"${frigate_config.mqtt.password}\" ipgeolocation_api_key=\"${frigate_config.ipgeolocation.api_key}\" garage_rtsp_password=\"${frigate_config.rtsp.garage.password}\" front_door_rtsp_password=\"${frigate_config.rtsp.front_door.password}\" doorbell_rtsp_password=\"${frigate_config.rtsp.doorbell.password}\" driveway_rtsp_password=\"${frigate_config.rtsp.driveway.password}\" back_door_rtsp_password=\"${frigate_config.rtsp.back_door.password}\" family_room_rtsp_password=\"${frigate_config.rtsp.family_room.password}\"'", playbook: 'install.yaml'
 | 
			
		||||
                ansiblePlaybook credentialsId: 'rivendell-ssh-key', disableHostKeyChecking: true, extras: "--extra-vars 'ipgeolocation_api_key=\"${frigate_config.ipgeolocation.api_key}\" garage_rtsp_password=\"${frigate_config.rtsp.garage.password}\" front_door_rtsp_password=\"${frigate_config.rtsp.front_door.password}\" doorbell_rtsp_password=\"${frigate_config.rtsp.doorbell.password}\" driveway_rtsp_password=\"${frigate_config.rtsp.driveway.password}\" back_door_rtsp_password=\"${frigate_config.rtsp.back_door.password}\" family_room_rtsp_password=\"${frigate_config.rtsp.family_room.password}\"'", playbook: 'install.yaml'
 | 
			
		||||
                ansiblePlaybook credentialsId: 'rivendell-ssh-key', disableHostKeyChecking: true, playbook: 'stop.yaml'
 | 
			
		||||
                ansiblePlaybook credentialsId: 'rivendell-ssh-key', disableHostKeyChecking: true, playbook: 'start.yaml'
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,5 @@
 | 
			
		|||
mqtt:
 | 
			
		||||
  host: mqtt
 | 
			
		||||
  user: '{FRIGATE_MQTT_USERNAME}'
 | 
			
		||||
  password: '{FRIGATE_MQTT_PASSWORD}'
 | 
			
		||||
 | 
			
		||||
detectors:
 | 
			
		||||
  cpu1:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,6 +7,8 @@ services:
 | 
			
		|||
    labels:
 | 
			
		||||
      autoheal: 'true'
 | 
			
		||||
    restart: unless-stopped
 | 
			
		||||
    depends_on:
 | 
			
		||||
    - mqtt
 | 
			
		||||
    healthcheck:
 | 
			
		||||
      test: ls /media/frigate && curl -s -f http://localhost:5000 -o /dev/null
 | 
			
		||||
      interval: 60s
 | 
			
		||||
| 
						 | 
				
			
			@ -14,8 +16,6 @@ services:
 | 
			
		|||
      start_period: 30s
 | 
			
		||||
      timeout: 30s
 | 
			
		||||
    environment:
 | 
			
		||||
      FRIGATE_MQTT_USERNAME: frigate
 | 
			
		||||
      FRIGATE_MQTT_PASSWORD: ${MQTT_PASSWORD}
 | 
			
		||||
      FRIGATE_GARAGE_RTSP_USERNAME: motion
 | 
			
		||||
      FRIGATE_GARAGE_RTSP_PASSWORD: ${FRIGATE_GARAGE_RTSP_PASSWORD}
 | 
			
		||||
      FRIGATE_FRONT_DOOR_RTSP_USERNAME: motion
 | 
			
		||||
| 
						 | 
				
			
			@ -46,19 +46,18 @@ services:
 | 
			
		|||
      source: /etc/localtime
 | 
			
		||||
      target: /etc/localtime
 | 
			
		||||
      read_only: true
 | 
			
		||||
#    networks:
 | 
			
		||||
#    - frigate
 | 
			
		||||
    networks:
 | 
			
		||||
    - frigate
 | 
			
		||||
    ports:
 | 
			
		||||
    - 127.0.0.1:10000:5000
 | 
			
		||||
    extra_hosts:
 | 
			
		||||
    - mqtt:192.168.0.6
 | 
			
		||||
  notify:
 | 
			
		||||
    container_name: frigate-notify
 | 
			
		||||
    image: frigate-notify:latest
 | 
			
		||||
    restart: unless-stopped
 | 
			
		||||
    depends_on:
 | 
			
		||||
    - frigate
 | 
			
		||||
    - mqtt
 | 
			
		||||
    environment:
 | 
			
		||||
      MQTT_USERNAME: frigate
 | 
			
		||||
      MQTT_PASSWORD: ${MQTT_PASSWORD}
 | 
			
		||||
      REQUESTS_CA_BUNDLE: /etc/ssl/certs/ca-certificates.crt
 | 
			
		||||
    volumes:
 | 
			
		||||
    - type: bind
 | 
			
		||||
| 
						 | 
				
			
			@ -69,14 +68,17 @@ services:
 | 
			
		|||
      source: /etc/localtime
 | 
			
		||||
      target: /etc/localtime
 | 
			
		||||
      read_only: true
 | 
			
		||||
    extra_hosts:
 | 
			
		||||
    - mqtt:192.168.0.6
 | 
			
		||||
    networks:
 | 
			
		||||
    - frigate
 | 
			
		||||
  webcontrol:
 | 
			
		||||
    container_name: frigate-webcontrol
 | 
			
		||||
    image: frigate-webcontrol:latest
 | 
			
		||||
    labels:
 | 
			
		||||
      autoheal: 'true'
 | 
			
		||||
    restart: unless-stopped
 | 
			
		||||
    depends_on:
 | 
			
		||||
    - frigate
 | 
			
		||||
    - mqtt
 | 
			
		||||
    healthcheck:
 | 
			
		||||
      test: curl -s -f http://localhost -o /dev/null
 | 
			
		||||
      interval: 60s
 | 
			
		||||
| 
						 | 
				
			
			@ -84,40 +86,35 @@ services:
 | 
			
		|||
      start_period: 30s
 | 
			
		||||
      timeout: 30s
 | 
			
		||||
    environment:
 | 
			
		||||
      MQTT_USERNAME: frigate
 | 
			
		||||
      MQTT_PASSWORD: ${MQTT_PASSWORD}
 | 
			
		||||
      IPGEOLOCATION_API_KEY: ${IPGEOLOCATION_API_KEY}
 | 
			
		||||
    volumes:
 | 
			
		||||
    - type: bind
 | 
			
		||||
      source: /etc/localtime
 | 
			
		||||
      target: /etc/localtime
 | 
			
		||||
      read_only: true
 | 
			
		||||
    networks:
 | 
			
		||||
    - frigate
 | 
			
		||||
    ports:
 | 
			
		||||
    - 127.0.0.1:10001:80
 | 
			
		||||
    extra_hosts:
 | 
			
		||||
    - mqtt:192.168.0.6
 | 
			
		||||
#  mqtt:
 | 
			
		||||
#    container_name: mqtt
 | 
			
		||||
#    image: eclipse-mosquitto:latest
 | 
			
		||||
#    command:
 | 
			
		||||
#    - mosquitto
 | 
			
		||||
#    - -c
 | 
			
		||||
#    - /mosquitto-no-auth.conf
 | 
			
		||||
#    restart: unless-stopped
 | 
			
		||||
#    volumes:
 | 
			
		||||
#    - type: bind
 | 
			
		||||
#      source: /etc/localtime
 | 
			
		||||
#      target: /etc/localtime
 | 
			
		||||
#      read_only: true
 | 
			
		||||
#    networks:
 | 
			
		||||
#    - frigate
 | 
			
		||||
#    ports:
 | 
			
		||||
#    - 1883:1883
 | 
			
		||||
#    - 9001:9001
 | 
			
		||||
  mqtt:
 | 
			
		||||
    container_name: mqtt
 | 
			
		||||
    image: eclipse-mosquitto:2.0.18
 | 
			
		||||
    command:
 | 
			
		||||
    - mosquitto
 | 
			
		||||
    - -c
 | 
			
		||||
    - /mosquitto-no-auth.conf
 | 
			
		||||
    restart: unless-stopped
 | 
			
		||||
    volumes:
 | 
			
		||||
    - type: bind
 | 
			
		||||
      source: /etc/localtime
 | 
			
		||||
      target: /etc/localtime
 | 
			
		||||
      read_only: true
 | 
			
		||||
    networks:
 | 
			
		||||
    - frigate
 | 
			
		||||
 | 
			
		||||
#networks:
 | 
			
		||||
#  frigate:
 | 
			
		||||
#    name: frigate
 | 
			
		||||
networks:
 | 
			
		||||
  frigate:
 | 
			
		||||
    name: frigate
 | 
			
		||||
 | 
			
		||||
volumes:
 | 
			
		||||
  config:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,6 @@
 | 
			
		|||
- name: Install Frigate
 | 
			
		||||
  hosts: Barad-dur
 | 
			
		||||
  vars_prompt:
 | 
			
		||||
  - name: mqtt_password
 | 
			
		||||
    prompt: Enter password for MQTT user frigate
 | 
			
		||||
  - name: ipgeolocation_api_key
 | 
			
		||||
    prompt: Enter API key for IPGeolocation
 | 
			
		||||
  - name: garage_rtsp_password
 | 
			
		||||
| 
						 | 
				
			
			@ -118,8 +116,6 @@
 | 
			
		|||
  - name: Insert into Postgres table service
 | 
			
		||||
    vars:
 | 
			
		||||
      frigate_config:
 | 
			
		||||
        mqtt:
 | 
			
		||||
          password: '{{mqtt_password}}'
 | 
			
		||||
        ipgeolocation:
 | 
			
		||||
          api_key: '{{ipgeolocation_api_key}}'
 | 
			
		||||
        rtsp:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,7 +10,8 @@ import paho.mqtt.client as mqtt
 | 
			
		|||
class FrigateEventNotifier:
 | 
			
		||||
    def __init__(self, mqtt_username, mqtt_password, quiet_period=3 * 60):
 | 
			
		||||
        self.mqtt_client = mqtt.Client()
 | 
			
		||||
        self.mqtt_client.username_pw_set(mqtt_username, password=mqtt_password)
 | 
			
		||||
        if mqtt_username is not None and mqtt_password is not None:
 | 
			
		||||
            self.mqtt_client.username_pw_set(mqtt_username, password=mqtt_password)
 | 
			
		||||
        self.mqtt_client.on_connect = self._on_connect
 | 
			
		||||
        self.mqtt_client.on_message = self._on_message
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -114,5 +115,5 @@ class FrigateEventNotifier:
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    frigate_event_notifier = FrigateEventNotifier(os.environ['MQTT_USERNAME'], os.environ['MQTT_PASSWORD'])
 | 
			
		||||
    frigate_event_notifier = FrigateEventNotifier(os.environ.get('MQTT_USERNAME'), os.environ.get('MQTT_PASSWORD'))
 | 
			
		||||
    frigate_event_notifier.start()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,7 +35,6 @@
 | 
			
		|||
 | 
			
		||||
  - name: Docker Compose up Frigate
 | 
			
		||||
    environment:
 | 
			
		||||
      MQTT_PASSWORD: '{{frigate_config.mqtt.password}}'
 | 
			
		||||
      IPGEOLOCATION_API_KEY: '{{frigate_config.ipgeolocation.api_key}}'
 | 
			
		||||
      FRIGATE_GARAGE_RTSP_PASSWORD: '{{frigate_config.rtsp.garage.password}}'
 | 
			
		||||
      FRIGATE_FRONT_DOOR_RTSP_PASSWORD: '{{frigate_config.rtsp.front_door.password}}'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -53,7 +53,11 @@ def reset_all_camera_detection_at_sunset():
 | 
			
		|||
def set_camera_detection(camera: str, value: bool, delay: int = 0) -> None:
 | 
			
		||||
    sleep(delay)
 | 
			
		||||
 | 
			
		||||
    mqtt_publish.single(f'frigate/{camera}/detect/set', 'ON' if value else 'OFF', hostname='mqtt', port=1883, auth={'username': os.environ['MQTT_USERNAME'], 'password': os.environ['MQTT_PASSWORD']})
 | 
			
		||||
    mqtt_auth = {'username': os.environ.get('MQTT_USERNAME'), 'password': os.environ.get('MQTT_PASSWORD')}
 | 
			
		||||
    if not all(mqtt_auth.values()):
 | 
			
		||||
        mqtt_auth = None
 | 
			
		||||
 | 
			
		||||
    mqtt_publish.single(f'frigate/{camera}/detect/set', 'ON' if value else 'OFF', hostname='mqtt', port=1883, auth=mqtt_auth)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@blueprint.route('/camera/<string:camera>/detect', methods=['POST'])
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue