Interact with python script running infinitive loo

2019-09-02 20:33发布

问题:

I have a python script on my raspberry-pi continuously (every 5 seconds) running a loop to control the temperature of a pot with some electronics through GPIO.

I monitor temperature on a web page by having the python script write the temperature to a text file witch I request from java script and HTTP on a web page.

I would like to pass a parameter to the python script to make changes to the controlling, like change the target temperature.

What would be the better way to do this?

I'm working on a solution, where the python script is looking for parameters in a text file and then have a second python script write changes to this file. This second python script would be run by a http request from the web page.

Is this a way to go? Or am I missing a more direct way to do this.

This must be done many time before and described on the web, but I find nothing. Maybe I don't have the right terms to describe the problem.

Any hints is appreciated. Best regards Kresten

回答1:

You have to write somewhere your configuration for looping script. So file or database are possible choices but I would say that a formatted file (ini, yaml, …) is the way to go if you have a little number of parameters.



回答2:

not sure about raspberry-pi but I see these solutions:

  • os signal (doc here

  • socket see Python socket server/client programming