Merge branch 'master' into noSleep
This commit is contained in:
@@ -150,7 +150,7 @@ def check_git_update(script_dir):
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Error updating git repository:", e.output)
|
||||
|
||||
if any(s in git_update for s in ('Your branch is up to date', 'Your branch is up-to-date')):
|
||||
if any(s in git_update for s in ('Your branch is up to date', 'Your branch is up-to-date', 'Votre branche est à jour')):
|
||||
git_update = 'off'
|
||||
else:
|
||||
git_update = 'on'
|
||||
@@ -300,14 +300,30 @@ def config_json(what_config):
|
||||
return json.dumps(data)
|
||||
|
||||
|
||||
def on_log(client, userdata, level, buf):
|
||||
if level == paho.MQTT_LOG_ERR:
|
||||
print("MQTT error: ", buf)
|
||||
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
if rc != 0:
|
||||
print("Error: Unable to connect to MQTT broker, return code:", rc)
|
||||
|
||||
|
||||
def publish_to_mqtt(cpu_load=0, cpu_temp=0, used_space=0, voltage=0, sys_clock_speed=0, swap=0, memory=0,
|
||||
uptime_days=0, wifi_signal=0, wifi_signal_dbm=0, rpi5_fan_speed=0, git_update=False):
|
||||
# connect to mqtt server
|
||||
client = paho.Client(client_id="rpi-mqtt-monitor-" + hostname)
|
||||
client.username_pw_set(config.mqtt_user, config.mqtt_password)
|
||||
client.connect(config.mqtt_host, int(config.mqtt_port))
|
||||
client.loop_start()
|
||||
client.on_log = on_log
|
||||
client.on_connect = on_connect
|
||||
|
||||
try:
|
||||
client.connect(config.mqtt_host, int(config.mqtt_port))
|
||||
except Exception as e:
|
||||
print("Error connecting to MQTT broker:", e)
|
||||
return
|
||||
|
||||
client.loop_start()
|
||||
# publish monitored values to MQTT
|
||||
if config.cpu_load:
|
||||
if config.discovery_messages:
|
||||
@@ -382,10 +398,16 @@ def bulk_publish_to_mqtt(cpu_load=0, cpu_temp=0, used_space=0, voltage=0, sys_cl
|
||||
values = cpu_load, cpu_temp, used_space, voltage, int(sys_clock_speed), swap, memory, uptime_days, wifi_signal, wifi_signal_dbm, rpi5_fan_speed, git_update
|
||||
values = str(values)[1:-1]
|
||||
|
||||
# connect to mqtt server
|
||||
client = paho.Client(client_id="rpi-mqtt-monitor-" + hostname)
|
||||
client.username_pw_set(config.mqtt_user, config.mqtt_password)
|
||||
client.connect(config.mqtt_host, int(config.mqtt_port))
|
||||
client.on_log = on_log
|
||||
client.on_connect = on_connect
|
||||
|
||||
try:
|
||||
client.connect(config.mqtt_host, int(config.mqtt_port))
|
||||
except Exception as e:
|
||||
print("Error connecting to MQTT broker:", e)
|
||||
return
|
||||
|
||||
# publish monitored values to MQTT
|
||||
client.publish(config.mqtt_topic_prefix + "/" + hostname, values, qos=config.qos, retain=config.retain)
|
||||
|
||||
Reference in New Issue
Block a user