1

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?

ozhe
  • 23
  • 4
  • 1
    Perhaps your solution can be found in this question: http://stackoverflow.com/questions/1598231/how-to-run-php-exec-as-root – Rob M. Dec 12 '13 at 23:33
  • why not run "master" python script with subprocesses and communicate with php via sockets? – akaRem Jan 30 '14 at 20:37

0 Answers0