Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update display #168

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ options:
```



## Installation

### Automated
Expand Down
74 changes: 34 additions & 40 deletions src/rpi-cpu2mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ def check_all_drive_temps():

def print_measured_values(monitored_values):
remote_version = update.check_git_version_remote(script_dir)
output = """:: rpi-mqtt-monitor
Version: {}
output = """:: rpi-mqtt-monitor :: v {}

:: Device Information
Model Name: {}
Expand All @@ -333,40 +332,41 @@ def print_measured_values(monitored_values):
MAC Address: {}
""".format(config.version, check_model_name(), get_manufacturer(), get_os(), hostname, get_network_ip(), get_mac_address())

if args.service:
output += " Service Sleep Time: {} seconds\n".format(config.service_sleep_time)
output += " Service Sleep Time: {} seconds\n".format(config.service_sleep_time)
if config.update:
output += " Update Check Interval: {} seconds\n".format(config.update_check_interval)
output += """
:: Measured values
CPU Load: {} %
CPU Temp: {} °C
Used Space: {} %
Voltage: {} V
CPU Clock Speed: {} MHz
Swap: {} %
Memory: {} %
Online since: {}
Wifi Signal: {} %
Wifi Signal dBm: {}
RPI5 Fan Speed: {} RPM
RPI Power Status: {}
Update: {}
External Sensors: {}
""".format(monitored_values.get('cpu_load', ''), monitored_values.get('cpu_temp', ''), monitored_values.get('used_space', ''), monitored_values.get('voltage', ''),
monitored_values.get('sys_clock_speed', ''), monitored_values.get('swap', ''), monitored_values.get('memory', ''), monitored_values.get('uptime', ''),
monitored_values.get('wifi_signal', ''), monitored_values.get('wifi_signal_dbm', ''), monitored_values.get('rpi5_fan_speed', ''),
monitored_values.get('rpi_power_status', ''), monitored_values.get('check_git_update(script_dir)', ''), monitored_values.get('ext_sensors', ''))

# Add dynamic measured values with units
measured_values = {
"CPU Load": ("cpu_load", "%"),
"CPU Temp": ("cpu_temp", "°C"),
"Used Space": ("used_space", "%"),
"Voltage": ("voltage", "V"),
"CPU Clock Speed": ("sys_clock_speed", "MHz"),
"Swap": ("swap", "%"),
"Memory": ("memory", "%"),
"Online since": ("uptime", ""),
"Wifi Signal": ("wifi_signal", "%"),
"Wifi Signal dBm": ("wifi_signal_dbm", "dBm"),
"RPI5 Fan Speed": ("rpi5_fan_speed", "RPM"),
"RPI Power Status": ("rpi_power_status", ""),
"Update": ("update", ""),
"External Sensors": ("ext_sensors", "")
}

output += "\n:: Measured values\n"
for label, (key, unit) in measured_values.items():
if key in monitored_values:
output += f" {label}: {monitored_values[key]} {unit}\n"

drive_temps = check_all_drive_temps()
if len(drive_temps) > 0:
for device, temp in drive_temps.items():
output += f"{device.capitalize()} Temp: {temp:.2f}°C\n"
output += f" {device.capitalize()} Temp: {temp:.2f}°C\n"

output += """\n:: Installation directory: \n {}
output += """\n:: Installation directory :: {}

:: Release notes {}:
{}""".format(script_dir, remote_version, get_release_notes(remote_version).strip())
{}""".format(os.path.dirname(script_dir), remote_version, get_release_notes(remote_version))
print(output)


Expand All @@ -387,18 +387,13 @@ def get_release_notes(version):
release_notes = "No release notes available"

lines = extract_text(release_notes).split('\n')

for i in range(len(lines)):
if lines[i].strip() != "":
lines[i] = "* " + lines[i]
lines = [" * "+ line for line in lines if line.strip() != ""]

release_notes = '\n'.join(lines)

if len(release_notes) > 255:
release_notes = release_notes[:250] + " ..."

release_notes = "### What's Changed" + release_notes

return release_notes


Expand Down Expand Up @@ -808,14 +803,13 @@ def parse_arguments():
prog='rpi-mqtt-monitor',
description='Monitor CPU load, temperature, frequency, free space, etc., and publish the data to an MQTT server or Home Assistant API.'
)
parser.add_argument('-H', '--hass_api', action='store_true', help='send readings via Home Assistant API (not via MQTT)', default=False)
parser.add_argument('-d', '--display', action='store_true', help='display values on screen', default=False)
parser.add_argument('-s', '--service', action='store_true', help='run script as a service, sleep interval is configurable in config.py', default=False)
parser.add_argument('-v', '--version', action='store_true', help='display installed version and exit', default=False)
parser.add_argument('-u', '--update', action='store_true', help='update script and config then exit', default=False)
parser.add_argument('-H', '--hass_api', action='store_true', help='send readings via Home Assistant API (not via MQTT)', default=False)
parser.add_argument('-d', '--display', action='store_true', help='display values on screen', default=False)
parser.add_argument('-s', '--service', action='store_true', help='run script as a service, sleep interval is configurable in config.py', default=False)
parser.add_argument('-v', '--version', action='store_true', help='display installed version and exit', default=False)
parser.add_argument('-u', '--update', action='store_true', help='update script and config then exit', default=False)
parser.add_argument('-w', '--hass_wake', action='store_true', help='display Home assistant wake on lan configuration', default=False)


args = parser.parse_args()

if args.update:
Expand Down