idoodler
idoodler

Reputation: 3545

How to execute system commands with a button press on a HTML file?

I have a website on my local server and I like to execute system commands on my local server with a button press in the html file that is displayed. Is there a way to either execute system commands like gpio write 0 1 or to run python scripts? And how can I get the output of a system command as a string, like /opt/vc/bin/vcgencmd measure_temp| egrep "[0-9.]{4,}" -o output e.g. 44.4?

Thanks

David

Upvotes: 1

Views: 404

Answers (1)

korylprince
korylprince

Reputation: 3009

You will have to a webserver with some kind of server-side script. There's lots of ways you can do this. If you know PHP, that may be easiest. If you want to use python check out uwsgi.

Here is a pretty simple project I wrote with uwsgi that might help you get started if you go that route. I found a lot of the examples didn't help a lot, so you might have some luck with that code.

Edit: Actually, uwsgi on the pi is a pretty old version, and it does some weird things on ARM if you try to compile it.

I created a proof of concept for you here using gunicorn instead. Just follow the instructions under the Installing section.

Upvotes: 1

Related Questions