diff --git a/front/css/pialert.css b/front/css/pialert.css index 8cfd885f..746f0537 100755 --- a/front/css/pialert.css +++ b/front/css/pialert.css @@ -1055,6 +1055,11 @@ input[readonly] { } +.pia-top-left-logo +{ + height:50px; +} + /* ----------------------------------------------------------------------------- Donations ----------------------------------------------------------------------------- */ diff --git a/front/js/pialert_common.js b/front/js/pialert_common.js index d3251a33..2a6f2188 100755 --- a/front/js/pialert_common.js +++ b/front/js/pialert_common.js @@ -757,18 +757,7 @@ function getGuid() { // UI // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- -// Generate work-in-progress icons -function workInProgress() { - if($(".work-in-progress").html().trim() == "") - { - $(".work-in-progress").append(` - - 🦺 - - `) - } -} // ----------------------------------------------------------------------------- // Loading Spinner overlay @@ -876,7 +865,6 @@ function executeOnce() { cacheSettings(); cacheStrings(); initDeviceListAll_JSON(); - workInProgress(); // Set the flag in sessionStorage to indicate that the code has been executed and save time when last time the page for initialized sessionStorage.setItem(sessionStorageKey, "true"); diff --git a/front/php/templates/header.php b/front/php/templates/header.php index 893fdf63..a4e4ef56 100755 --- a/front/php/templates/header.php +++ b/front/php/templates/header.php @@ -111,7 +111,7 @@ if ($ENABLED_DARKMODE === True) { -
onLoad="show_pia_servertime();" > + onLoad="show_pia_servertime();" >
+
- Pi.Alert
+ Pi.Alert
+
+
+
@@ -183,7 +188,7 @@ if ($ENABLED_DARKMODE === True) {
= lang('About_Title');?> - = lang('About_Design');?> Raspberry Pi + = lang('About_Design');?> Docker
@@ -208,12 +213,6 @@ if ($ENABLED_DARKMODE === True) {
-
- 0 - Low quality to 2 - High quality. The higher the quality the longer the delay."
+ "string" : "Quality of service setting for MQTT message sending. The higher the quality the longer the delay. 0 - Low quality to 2 - High quality."
},
{
"language_code": "es_es",
"string" : "Configuración de calidad de servicio para el envÃo de mensajes MQTT. 0: baja calidad a 2: alta calidad. Cuanto mayor sea la calidad, mayor será el retraso."
}]
},
+ {
+ "function": "VERSION",
+ "type": "integer.select",
+ "default_value": 1,
+ "options": [ 1, 2 ],
+ "localized": ["name", "description"],
+ "name" : [{
+ "language_code": "en_us",
+ "string" : "Version"
+ }],
+ "description": [{
+ "language_code": "en_us",
+ "string" : "Paho MQTT API version. Depends on the MQTT version supported by the MQTT broker. Usually set to 1."
+ }]
+ },
{
"function": "DELAY_SEC",
"type": "integer",
diff --git a/front/plugins/_publisher_mqtt/mqtt.py b/front/plugins/_publisher_mqtt/mqtt.py
index e3c58da2..39a81ed6 100755
--- a/front/plugins/_publisher_mqtt/mqtt.py
+++ b/front/plugins/_publisher_mqtt/mqtt.py
@@ -39,7 +39,6 @@ plugin_objects = Plugin_Objects(RESULT_FILE)
md5_hash = hashlib.md5()
pluginName = 'MQTT'
-module_name = pluginName
# globals
@@ -53,7 +52,7 @@ def main():
# Check if basic config settings supplied
if check_config() == False:
- mylog('none', [f'[{pluginName}] âš ERROR: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
+ mylog('verbose', [f'[{pluginName}] âš ERROR: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
return
# Create a database connection
@@ -72,7 +71,7 @@ def main():
#-------------------------------------------------------------------------------
def check_config():
if get_setting_value('MQTT_BROKER') == '' or get_setting_value('MQTT_PORT') == '' or get_setting_value('MQTT_USER') == '' or get_setting_value('MQTT_PASSWORD') == '':
- mylog('none', ['[Check Config] âš ERROR: MQTT service not set up correctly. Check your pialert.conf MQTT_* variables.'])
+ mylog('verbose', ['[Check Config] âš ERROR: MQTT service not set up correctly. Check your pialert.conf MQTT_* variables.'])
return False
else:
return True
@@ -135,23 +134,38 @@ class sensor_config:
def publish_mqtt(mqtt_client, topic, message):
status = 1
-
+ message = json.dumps(message).replace("'",'"')
+ qos = get_setting_value('MQTT_QOS')
mylog('verbose', [f"[{pluginName}] Sending MQTT topic: {topic}"])
mylog('verbose', [f"[{pluginName}] Sending MQTT message: {message}"])
+ # mylog('verbose', [f"[{pluginName}] get_setting_value('MQTT_QOS'): {qos}"])
+
+ if mqtt_connected_to_broker == False:
+
+ mylog('verbose', [f"[{pluginName}] âš ERROR: Not connected to broker, aborting."])
+
+ return False
while status != 0:
+
+ # mylog('verbose', [f"[{pluginName}] mqtt_client.publish "])
+ # mylog('verbose', [f"[{pluginName}] mqtt_client.is_connected(): {mqtt_client.is_connected()} "])
+
result = mqtt_client.publish(
topic=topic,
payload=message,
- qos=get_setting_value('MQTT_QOS'),
+ qos=qos,
retain=True,
)
status = result[0]
+ # mylog('verbose', [f"[{pluginName}] status: {status}"])
+ # mylog('verbose', [f"[{pluginName}] result: {result}"])
+
if status != 0:
- mylog('minimal', [f"[{pluginName}] Waiting to reconnect to MQTT broker"])
+ mylog('verbose', [f"[{pluginName}] Waiting to reconnect to MQTT broker"])
time.sleep(0.1)
return True
@@ -179,7 +193,7 @@ def create_sensor(mqtt_client, deviceId, deviceName, sensorType, sensorName, ico
# save if new
if new_sensor_config.isNew:
- mylog('minimal', [f"[{pluginName}] Publishing sensor number {len(mqtt_sensors)}"])
+ mylog('verbose', [f"[{pluginName}] Publishing sensor number {len(mqtt_sensors)}"])
publish_sensor(mqtt_client, new_sensor_config)
@@ -190,19 +204,19 @@ def publish_sensor(mqtt_client, sensorConfig):
global mqtt_sensors
- message = '{ \
- "name":"'+sensorConfig.sensorName+'", \
- "state_topic":"system-sensors/'+sensorConfig.sensorType+'/'+sensorConfig.deviceId+'/state", \
- "value_template":"{{value_json.'+sensorConfig.sensorName+'}}", \
- "unique_id":"'+sensorConfig.deviceId+'_sensor_'+sensorConfig.sensorName+'", \
- "device": \
- { \
- "identifiers": ["'+sensorConfig.deviceId+'_sensor"], \
- "manufacturer": "PiAlert", \
- "name":"'+sensorConfig.deviceName+'" \
- }, \
- "icon":"mdi:'+sensorConfig.icon+'" \
- }'
+ message = {
+ "name" : sensorConfig.sensorName,
+ "state_topic" : "system-sensors/"+sensorConfig.sensorType+'/'+sensorConfig.deviceId+"/state",
+ "value_template" : "{{value_json."+sensorConfig.sensorName+"}}",
+ "unique_id" : sensorConfig.deviceId+'_sensor_'+sensorConfig.sensorName,
+ "device":
+ {
+ "identifiers" : [sensorConfig.deviceId+"_sensor"],
+ "manufacturer" : "PiAlert",
+ "name" : sensorConfig.deviceName
+ },
+ "icon":"mdi:'+sensorConfig.icon+'"
+ }
topic='homeassistant/'+sensorConfig.sensorType+'/'+sensorConfig.deviceId+'/'+sensorConfig.sensorName+'/config'
@@ -232,13 +246,18 @@ def mqtt_create_client():
mylog('verbose', [f"[{pluginName}] Connected to broker"])
mqtt_connected_to_broker = True # Signal connection
else:
- mylog('none', [f"[{pluginName}] Connection failed, reason_code: {reason_code}"])
+ mylog('verbose', [f"[{pluginName}] Connection failed, reason_code: {reason_code}"])
mqtt_connected_to_broker = False
global mqtt_client
- mqtt_client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
+ if get_setting_value('MQTT_VERSION') == 1:
+ mqtt_client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)
+ else:
+ mqtt_client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
+
+
mqtt_client.username_pw_set(get_setting_value('MQTT_USER'), get_setting_value('MQTT_PASSWORD'))
mqtt_client.on_connect = on_connect
mqtt_client.on_disconnect = on_disconnect
@@ -266,19 +285,16 @@ def mqtt_start(db):
# Get the data
row = get_device_stats(db)
- columns = ["online","down","all","archived","new","unknown"]
-
- payload = ""
-
- # Update the values
- for column in columns:
- payload += '"'+column+'": ' + str(row[column]) +','
-
# Publish (wrap into {} and remove last ',' from above)
publish_mqtt(mqtt_client, "system-sensors/sensor/pialert/state",
- '{ \
- '+ payload[:-1] +'\
- }'
+ {
+ "online": row[0],
+ "down": row[1],
+ "all": row[2],
+ "archived": row[3],
+ "new": row[4],
+ "unknown": row[5]
+ }
)
# Generate device-specific MQTT messages if enabled
@@ -291,11 +307,11 @@ def mqtt_start(db):
sec_delay = len(devices) * int(get_setting_value('MQTT_DELAY_SEC'))*5
- mylog('minimal', [f"[{pluginName}] Estimated delay: ", (sec_delay), 's ', '(', round(sec_delay/60,1) , 'min)' ])
+ mylog('verbose', [f"[{pluginName}] Estimated delay: ", (sec_delay), 's ', '(', round(sec_delay/60,1) , 'min)' ])
+ # debug_index = 0
for device in devices:
-
# Create devices in Home Assistant - send config messages
deviceId = 'mac_' + device["dev_MAC"].replace(" ", "").replace(":", "_").lower()
@@ -310,18 +326,18 @@ def mqtt_start(db):
# update device sensors in home assistant
publish_mqtt(mqtt_client, 'system-sensors/sensor/'+deviceId+'/state',
- '{ \
- "last_ip": "' + device["dev_LastIP"] +'", \
- "is_new": "' + str(device["dev_NewDevice"]) +'", \
- "vendor": "' + sanitize_string(device["dev_Vendor"]) +'", \
- "mac_address": "' + str(device["dev_MAC"]) +'" \
- }'
+ {
+ "last_ip": device["dev_LastIP"],
+ "is_new": str(device["dev_NewDevice"]),
+ "vendor": sanitize_string(device["dev_Vendor"]),
+ "mac_address": str(device["dev_MAC"])
+ }
)
publish_mqtt(mqtt_client, 'system-sensors/binary_sensor/'+deviceId+'/state',
- '{ \
- "is_present": "' + to_binary_sensor(str(device["dev_PresentLastScan"])) +'"\
- }'
+ {
+ "is_present": to_binary_sensor(str(device["dev_PresentLastScan"]))
+ }
)
# delete device / topic
diff --git a/front/settings.php b/front/settings.php
index fe85d575..e9cb6e9c 100755
--- a/front/settings.php
+++ b/front/settings.php
@@ -98,35 +98,35 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {