On 21/01/2021 12:39, Terry Coles wrote:
Hi,
I'm building a Web page to allow users to monitor key status information on
one of the Pis at WMT. I also want to create a page where users can press a
button to carry out certain tasks, such as Start or Stop some music playing or
select a new Playlist. The Player is written in Python. Altogether, there are
around 10 or more control functions that I want to invoke.
I have the monitoring page working reasonably well using a suitable html
template and a Flask route which populates the status values on the rendered
page. However, the control side is making me think a bit. I've found quite a
lot of tutorials and text book examples that use forms and a 'Submit' button,
but so far nothing quite like what I want.
What I need is for the user to be presented with set of buttons that, when
pressed, cause a bit of Python code to be executed that communicates with the
Player program. On receipt of the message, the Player program will trigger a
set of functions to carry out the requested action. The communication side is
sorted; all I need is an example or a link to a suitable tutorial that
illustrates the Flask code that I need to make it happen and if necessary, the
associated template.
Here is a bit of pseudo code to illustrate what I'm trying to do:
@app.route('/control')
def control():
Add a Button called "Stop the Music"
ON click run:
socket.write("Stop the Music")
Add another button...
etc.
Can anyone help?
Sending you separately an article form LXformat that shows how to do this. I
did this for my remote control car, with the R-Pi configured as an access point
and Flask Web server, and the HTML Calling Python to set GPIO pins to drive the
motors.
Peter M.
--
Next meeting: Online, Jitsi, Tuesday, 2021-02-02 20:00
Check to whom you are replying
Meetings, mailing list, IRC, ... http://dorset.lug.org.uk
New thread, don't hijack: mailto:dorset@mailman.lug.org.uk