I'm building a webpage to control my raspberry pi. It uses php to call python script and let the script running in background.
I found the php call can run python script successfully without raspberry GPIO imported. I try to output a txt in the python script and I found it after the call. However, when I imported GPIO functions, I cannot get any txt after the call. It seems that the script doesn't execute at all.
Here is the php call
exec ("python py_test.py &");
Here is the python script
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 60)
p.start(50)
f = open('test.txt', 'a')
f.write('test')
f.close()
I think it might be the permission problem since I need "sudo" to run the python script in terminal.
The error code when I directly run "python py_test.py" in terminal
Traceback (most recent call last):
File "py_test.py", line 6, in <module>
GPIO.setup(12, GPIO.OUT)
RuntimeError: No access to /dev/mem. Try running as root!
But how can I make the webpage to have the permission to execute GPIO?