diff --git a/pialert/conf.py b/pialert/conf.py index e613a7ac..fdb918d3 100644 --- a/pialert/conf.py +++ b/pialert/conf.py @@ -24,10 +24,12 @@ arpscan_devices = [] # for MQTT mqtt_connected_to_broker = False mqtt_sensors = [] +client = None # mqtt client # for notifications changedPorts_json_struc = None + # ACTUAL CONFIGRATION ITEMS set to defaults # General diff --git a/pialert/publishers/mqtt.py b/pialert/publishers/mqtt.py index 8e59d205..b955f22d 100644 --- a/pialert/publishers/mqtt.py +++ b/pialert/publishers/mqtt.py @@ -146,8 +146,9 @@ def mqtt_start(db): if conf.mqtt_connected_to_broker == False: conf.mqtt_connected_to_broker = True - client = mqtt_create_client() + conf.client = mqtt_create_client() + client = conf.client # General stats # Create a generic device for overal stats @@ -175,7 +176,7 @@ def mqtt_start(db): # Specific devices # Get all devices - devices = get_all_devices() + devices = get_all_devices(db) sec_delay = len(devices) * int(conf.MQTT_DELAY_SEC)*5 diff --git a/pialert/publishers/ntfy.py b/pialert/publishers/ntfy.py index 363da466..a9ce2500 100644 --- a/pialert/publishers/ntfy.py +++ b/pialert/publishers/ntfy.py @@ -32,6 +32,12 @@ def send (msg: noti_struc): # add authorization header with hash headers["Authorization"] = "Basic {}".format(basichash) - requests.post("{}/{}".format( conf.NTFY_HOST, conf.NTFY_TOPIC), - data=msg.html, - headers=headers) + try: + requests.post("{}/{}".format( conf.NTFY_HOST, conf.NTFY_TOPIC), + data=msg.html, + headers=headers) + except requests.exceptions.RequestException as e: + mylog('none', ['[NTFY] Error: ', e]) + return -1 + + return 0