diff --git a/README.md b/README.md index a7ffd07..94d8595 100644 --- a/README.md +++ b/README.md @@ -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```. -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: ``` +random_delay = randrange(30) group_messages = True sleep_time = 0.5 cpu_load = True diff --git a/src/config.py.example b/src/config.py.example index 10f0649..2d4a7c0 100644 --- a/src/config.py.example +++ b/src/config.py.example @@ -1,5 +1,7 @@ +from random import randrange + # MQTT server configuration -mqtt_host = "192.168.0.13" +mqtt_host = "ip address or host" mqtt_user = "user" mqtt_password = "password" mqtt_port = "1883" @@ -7,9 +9,14 @@ mqtt_topic_prefix = "rpi-MQTT-monitor" # 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 +# 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 sleep_time = 0.5 cpu_load = True diff --git a/src/rpi-cpu2mqtt.py b/src/rpi-cpu2mqtt.py index 6427b25..533c41f 100644 --- a/src/rpi-cpu2mqtt.py +++ b/src/rpi-cpu2mqtt.py @@ -112,6 +112,9 @@ if __name__ == '__main__': # 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 + # delay the execution of the script + time.sleep(config.random_delay) + # collect the monitored values if config.cpu_load: cpu_load = check_cpu_load()