diff --git a/omv_backup.py b/omv_backup.py index 5599453..88adb89 100755 --- a/omv_backup.py +++ b/omv_backup.py @@ -19,54 +19,6 @@ import paramiko import shutil import paho.mqtt.client as mqtt #import numpy as np -logging.info(f"Start OMV Backup") -BROKER = 'mqtt.home.lan' # e.g., 'mqtt.example.com' -PORT = 1883 # Typically 8883 for secure MQTT -TOPIC = 'sectorq/backups/start' -USERNAME = 'jaydee' -PASSWORD = 'jaydee1' -USE_TLS = False # Set to False if not using TLS - -# Define actions based on payload -def handle_payload(payload): - payload = payload.lower() - if payload == 'turn_on_light': - logging.info("💡 Turning on the light...") - elif payload == 'turn_off_light': - logging.info("💡 Turning off the light...") - elif payload == 'play_music': - logging.info("🎵 Playing music...") - else: - logging.error(f"⚠️ Unknown command: {payload}") - -# Callback when connected -def on_connect(client, userdata, flags, rc): - if rc == 0: - logging.info("✅ Connected securely to broker") - client.subscribe(TOPIC) - logging.info(f"📡 Subscribed to topic: {TOPIC}") - else: - logging.error(f"❌ Connection failed with code {rc}") - -# Callback when a message is received -def on_message(client, userdata, msg): - payload = msg.payload.decode() - logging.info(f"📨 Received message: {payload} on topic: {msg.topic}") - handle_payload(payload) - -# MQTT client setup -client = mqtt.Client() -client.username_pw_set(USERNAME, PASSWORD) -client.on_connect = on_connect -client.on_message = on_message - -# Use TLS for encrypted connection -if USE_TLS: - client.tls_set() # You can customize this with certs if needed - -# Connect and loop forever -client.connect(BROKER, PORT, keepalive=60) -client.loop_forever() @@ -182,6 +134,60 @@ except: client = mqtt_client.Client() client.username_pw_set(mqtt_username, mqtt_password) +logging.info(f"Start OMV Backup") +BROKER = 'mqtt.home.lan' # e.g., 'mqtt.example.com' +PORT = 1883 # Typically 8883 for secure MQTT +TOPIC = 'sectorq/backups/start' +USERNAME = 'jaydee' +PASSWORD = 'jaydee1' +USE_TLS = False # Set to False if not using TLS + +# Define actions based on payload +def handle_payload(payload): + payload = payload.lower() + if payload == 'turn_on_light': + logging.info("💡 Turning on the light...") + elif payload == 'turn_off_light': + logging.info("💡 Turning off the light...") + elif payload == 'play_music': + logging.info("🎵 Playing music...") + else: + logging.error(f"⚠️ Unknown command: {payload}") + +# Callback when connected +def on_connect(client, userdata, flags, rc): + if rc == 0: + logging.info("✅ Connected securely to broker") + client.subscribe(TOPIC) + logging.info(f"📡 Subscribed to topic: {TOPIC}") + else: + logging.error(f"❌ Connection failed with code {rc}") + +# Callback when a message is received +def on_message(client, userdata, msg): + payload = msg.payload.decode() + logging.info(f"📨 Received message: {payload} on topic: {msg.topic}") + handle_payload(payload) + +# MQTT client setup +client = mqtt.Client() +client.username_pw_set(USERNAME, PASSWORD) +client.on_connect = on_connect +client.on_message = on_message + +# Use TLS for encrypted connection +if USE_TLS: + client.tls_set() # You can customize this with certs if needed + +# Connect and loop forever +client.connect(BROKER, PORT, keepalive=60) +client.loop_forever() + + + + + + backups = { "nas": {