added support for command line arguments and the first one -d to display measured values in cli
This commit is contained in:
22
README.md
22
README.md
@@ -61,7 +61,7 @@ It will also help you configure the host and credentials for the mqtt server in
|
||||
|
||||
### Manual
|
||||
|
||||
If you don't like the automated installation here are manuall installation instructions:
|
||||
If you don't like the automated installation here are manuall installation instructions (missing the creation of virtual environment).
|
||||
|
||||
1. Install pip if you don't have it:
|
||||
|
||||
@@ -131,10 +131,26 @@ The group message looks like this:
|
||||
Run Raspberry Pi MQTT Monitor (you might need to update the path in the command below, depending on where you installled it)
|
||||
|
||||
```bash
|
||||
/usr/bin/python3 /home/pi/rpi-mqtt-monitor/rpi-cpu2mqtt.py
|
||||
/usr/bin/python3 /home/pi/rpi-mqtt-monitor/rpi-cpu2mqtt.py -d
|
||||
```
|
||||
|
||||
Once you run Raspberry Pi MQTT monitor there will be no output if it run OK, but you should get 8 or more messages via the configured MQTT server (the messages count depends on your configuration).
|
||||
Once you run Raspberry Pi MQTT monitor you should see something like this:
|
||||
|
||||
```
|
||||
Hostname: ubuntu-pc
|
||||
CPU Load: 30.8
|
||||
CPU Temp: 66
|
||||
Used Space: 11
|
||||
Voltage: False
|
||||
CPU Clock Speed: False
|
||||
Swap: False
|
||||
Memory: 65
|
||||
Uptime: 0
|
||||
Wifi Signal: False
|
||||
Wifi Signal dBm: False
|
||||
RPI5 Fan Speed: False
|
||||
Git Update: on
|
||||
```
|
||||
|
||||
## Schedule Raspberry Pi MQTT Monitor execution
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import paho.mqtt.client as paho
|
||||
import json
|
||||
import config
|
||||
import os
|
||||
|
||||
import argparse
|
||||
|
||||
# get device host name - used in mqtt topic
|
||||
hostname = socket.gethostname()
|
||||
@@ -358,6 +358,13 @@ def bulk_publish_to_mqtt(cpu_load=0, cpu_temp=0, used_space=0, voltage=0, sys_cl
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# parse arguments
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-d', action='store_true', help='Display values on screen', default=False)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
|
||||
# set all monitored values to False in case they are turned off in the config
|
||||
cpu_load = cpu_temp = used_space = voltage = sys_clock_speed = swap = memory = uptime_days = wifi_signal = wifi_signal_dbm = rpi5_fan_speed = git_update = False
|
||||
|
||||
@@ -393,6 +400,22 @@ if __name__ == '__main__':
|
||||
if config.git_update:
|
||||
git_update = check_git_update()
|
||||
|
||||
if args.d:
|
||||
print("Hostname: " + hostname)
|
||||
print("CPU Load: " + str(cpu_load))
|
||||
print("CPU Temp: " + str(cpu_temp))
|
||||
print("Used Space: " + str(used_space))
|
||||
print("Voltage: " + str(voltage))
|
||||
print("CPU Clock Speed: " + str(sys_clock_speed))
|
||||
print("Swap: " + str(swap))
|
||||
print("Memory: " + str(memory))
|
||||
print("Uptime: " + str(uptime_days))
|
||||
print("Wifi Signal: " + str(wifi_signal))
|
||||
print("Wifi Signal dBm: " + str(wifi_signal_dbm))
|
||||
print("RPI5 Fan Speed: " + str(rpi5_fan_speed))
|
||||
print("Git Update: " + str(git_update))
|
||||
|
||||
|
||||
# Publish messages to MQTT
|
||||
if hasattr(config, 'group_messages') and config.group_messages:
|
||||
bulk_publish_to_mqtt(cpu_load, cpu_temp, used_space, voltage, sys_clock_speed, swap, memory, uptime_days, wifi_signal, wifi_signal_dbm, rpi5_fan_speed, git_update)
|
||||
|
||||
Reference in New Issue
Block a user