2

P am trying to implement a button that will run a Python script forward.py (move my robot forward) using Lighttpd web server/PHP 7.0.

The Python script works perfectly when executed in the terminal window however when I try to run it from the click of the button it does not work.

Here is my basic HTML code to execute the .py script:

<html><body>
<h1> Development of Internet controlled robot </h1>
<input type="button" name="forwardbutton" value=" Move forward "onClick="<? exec(' python /var/www/html/forward.py'); ?>">
</body></html>

I have changed the owner of the forward.py script to be www-data however this has made no difference.

I am quite new to working with Raspberry Pis.

halfer
  • 19,824
  • 17
  • 99
  • 186
user_1
  • 45
  • 1
  • 3
  • 8
  • 2
    Have you considered setting up a small flask server to handle all of the control of the robot, and then your web page can just make requests to that? You could host both on a raspberry pi. – user3483203 Dec 19 '17 at 20:23

1 Answers1

3

I am not sure you can open php tags inside onClick event. You should call javascript function maybe and use ajax (to avoid refresh) to call the php page which will have the exec(python program) function.

take a look here Execute PHP function with onClick

AndyB
  • 76
  • 5
  • I would try something along these lines. Basically post back to the page that will execute the python. Though these seems like it would be a lot easier with django or flask, but i'm not a PHP pro. – SuperStew Dec 19 '17 at 20:25