0

I have test.py file, and it contains GPIO module commands:

#!/usr/bin/python
import RPi.GPIO as G
import time
G.setmode(G.BCM) 
G.setup(18, G.OUT)
G.output(18, True)
time.sleep(3)
G.output(18, False)
G.cleanup()

I want to call this python script for execution when I press button on my web page. My index.html contains javascript to call .py for execution:

<html>
<head>
<script type="text/javascript">
function func()
{
 document.location="cgi-bin/test.py";
}
</script>
</head>
<body>
 <div style="text-align:center">
 <h1>Raspberry Pi GPIO</h1>
 <form>
 <input type="button" value="call .py" onclick="func()">
 </form>
 </div>
</body>
</html>

Looks like problems are permissions, so when I click on the button, apache2 retrieves code 500 - Internal error. Execution of test.py from bash with sudo command works fine.

Is there any way to set these permissions, so the apache2 can successfully call python script that contains GPIO commands? Thanks

asked Sep 18, 2015 at 7:58
1

2 Answers 2

0

Yes, there are numerous ways. If you google I'm sure you will find them.

However I don't think it'll be a worthwhile effort - if you wait a week or so there should be an update to the RPi.GPIO module to allow its use without requiring root privileges.

There are other Python modules.

My pigpio Python does not require Python to be run as root (it sends requests to a daemon which has the needed privileges).

#!/usr/bin/env python
import time
import pigpio # abyz.me.uk/rpi/pigpio/python.html
LED=18
pi = pigpio.pi() # Connect to local Pi.
pi.set_mode(LED, pigpio.OUTPUT)
for i in range(10):
 pi.write(LED, 1)
 time.sleep(0.2)
 pi.write(LED, 0)
 time.sleep(0.2)
pi.stop() # Disconnect from local Pi.
Ghanima
16k17 gold badges66 silver badges127 bronze badges
answered Sep 18, 2015 at 10:05
0
0

You need to give everyone the right to execute

sudo chmod 750 /path/to/cgi-bin/test.py
answered Jan 4, 2017 at 6:53
1
  • This command does not give everyone the right to execute. Only to group members and the owner. Commented Jan 4, 2017 at 7:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.