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