Files
frigate/dayglo_detector/test_mqtt.py
T
2024-10-20 15:55:45 +11:00

23 lines
737 B
Python

import os
import paho.mqtt.client as mqtt
# Configuration
MQTT_BROKER = os.environ.get('MQTT_BROKER', '10.59.221.172')
MQTT_PORT = int(os.environ.get('MQTT_PORT', '1883'))
MQTT_USERNAME = os.getenv('MQTT_USERNAME', 'your_username')
MQTT_PASSWORD = os.getenv('MQTT_PASSWORD', 'your_password')
client = mqtt.Client(protocol=mqtt.MQTTv311) # Ensure you are using the correct client version
client.username_pw_set(MQTT_USERNAME, MQTT_PASSWORD) # Set the username and password
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected successfully.")
else:
print(f"Connected with result code {rc}")
client.on_connect = on_connect
client.connect(MQTT_BROKER, MQTT_PORT, 60)
client.loop_forever()