This commit is contained in:
Hristo Jelev
2020-05-06 21:52:02 +03:00
parent 1ac8f32f9d
commit d6a971a6b4
3 changed files with 15 additions and 4 deletions

View File

@@ -45,11 +45,12 @@ Copy ```/src/rpi-cpu2mqtt.py``` and ```/src/config.py.example``` to a folder of
Populate the variables for MQTT host, user, password and main topic in ```config.py```. Populate the variables for MQTT host, user, password and main topic in ```config.py```.
You can also choose what messages are send and what is the delay between them. You can also choose what messages are send and what is the delay (sleep_time is only used for multiple messages) between them.
If you are sending a grouped message and you want to delay the execution of the script you need to use the ```random_delay``` variable which is set to 30 by default.
This is the default configuration: This is the default configuration:
``` ```
random_delay = randrange(30)
group_messages = True group_messages = True
sleep_time = 0.5 sleep_time = 0.5
cpu_load = True cpu_load = True

View File

@@ -1,5 +1,7 @@
from random import randrange
# MQTT server configuration # MQTT server configuration
mqtt_host = "192.168.0.13" mqtt_host = "ip address or host"
mqtt_user = "user" mqtt_user = "user"
mqtt_password = "password" mqtt_password = "password"
mqtt_port = "1883" mqtt_port = "1883"
@@ -7,9 +9,14 @@ mqtt_topic_prefix = "rpi-MQTT-monitor"
# Messages configuration # Messages configuration
# If this is send to True the script will send just one message containing all values # If this is set to True the script will send just one message containing all values
group_messages = True group_messages = True
# Random delay in seconds before measuring the values
# - this is used for de-synchronizing message if you run this script on many hosts, set this to 0 for no delay.
# - if you want a fix delay you can remove the randarnge function and just set the needed delay.
random_delay = randrange(30)
# This is the time between sending the indivudual messages # This is the time between sending the indivudual messages
sleep_time = 0.5 sleep_time = 0.5
cpu_load = True cpu_load = True

View File

@@ -112,6 +112,9 @@ if __name__ == '__main__':
# set all monitored values to False in case they are turned off in the config # 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 = False cpu_load = cpu_temp = used_space = voltage = sys_clock_speed = swap = memory = False
# delay the execution of the script
time.sleep(config.random_delay)
# collect the monitored values # collect the monitored values
if config.cpu_load: if config.cpu_load:
cpu_load = check_cpu_load() cpu_load = check_cpu_load()