0

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?

2
  • You could call have a /config endpoint on the server, which returns the target temperature. the client calls /config on start up and then periodically to check for updates. Commented Nov 29, 2021 at 14:47
  • Can you add code you already have to your question? Commented Nov 29, 2021 at 14:55

2 Answers 2

1

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")
Sign up to request clarification or add additional context in comments.

Comments

0

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.