First of all, I am not a native English speaker, so please forgive any spelling mistakes I may have.
I am trying to integrate HTML and Python to create a GUI that can "speak" to a bus (KNX bus if you are interested).
I have a raspberry pi with an HTML page and some Python scripts, that are the ones that actually talk to the bus. I have managed to run python scripts from HTML with a bit of PHP (I am not particularly proficient in PHP), doing something like this:
if (isset($_POST ['button'])){
exec("sudo pathofpythonscript/pythonscript.py")
}
And it works just fine, when the button it's pressed, the script it's executed. But now, I want to have a script running (since I want python to be reading from the UART from the bus and display that information) and when something in the scripts happens (a condition it's met, for example), I want to be able to talk to the HTML to change a CSS property or anything else, something like this pseudo-code here
//This is just pseudo-code to try to illustrate my question, IT'S NOT working code
//In the python file, a simple toggle function
if bus_event
var != var
//in Html, with javascript
if (var_from_python_script == true){
document.getElementById('button').style.background=red;
}
If someone could tell me just how to make a simple example, with something like a python script that toggles any boolean parameter that enters and returns it, and how to "grab" that return from javascript/HTML to use it,
I think I can work everything else.
Thank you in advance!