I am currently building a raspberry pi project to monitor the surrounding temperature and buzz if it’s too high. The program is simple it reads the config (temp to buzz at) from a file and it uses it for the infinite while loop. I was thinking of making a separate program for a flask server to act as a GUI and the user can change the config value. I thought of making a endpoint e.g. /update so I can send the new data to it and the flask server will write it into the config file.
The problem is that I am unsure how can I make the program that is reading the temperature and in the infinite loop take in the new config value. I was thinking of simply using code and restart the program so that it can re-read the config file with the new value and run again but I am unsure if there is a better solution. Any ideas?
CodePudding user response:
You can use functions
#file1
def buzz(config, temp):
#code
#file2 (gui)
from file1 import buzz
while True:
buzz("input from gui", "read temperature from raspberry pi")
CodePudding user response:
You could get the warning temperature from the server on startup, then do it periodically within your loop, e.g.:
update_frequency = 10000
warning_temp = get_config_from_server()
last_update_time = now()
while(true):
if check_temperature() > warning_temp:
alarm()
if now()-last_update_time > update_frequency:
warning_temp = get_config_from_server()
last_update_time = now()