I have been searching, and still can't find an answer that will work. I've tried the chmod, chown, visudo, wrapper script -> main script options, and I still cannot manipulate the GPIO pins from a webpage to python script. Basically I'm sending a GET request with a pin number and pin state (on/off) name/value pairing. I'm using the cgi python module to extract the values, then set up and change the state of a gpio pin.
Nothing wrong with the script since it works from a terminal with sudo. I also have cgitb enabled and it clearly shows the (apparently very common) /dev/mem permissions error. I have given apache and www-data and pi god-mode in the sudoers list with nopasswd, chmod'd /dev/mem..and just about every other suggestion I can find. Still no joy!
This is my cgi script:
#!/usr/bin/python
print "Content-Type: text/html\n\n"
import cgi
import cgitb; cgitb.enable() # Optional; for debugging only
import RPi.GPIO as gpio
gpio.setwarnings(False)
pins = [00,2,3,4] //ignore item 1, my button numbering starts at 1, so 0 is never referenced
arguments = cgi.FieldStorage()
pinNum = arguments.getlist("pnum")
pinState = arguments.getlist("pstate")
p = pinNum[0]
s = pinState[0]
gpio.setmode(gpio.BCM)
pin = pins[int(p)]
gpio.setup(int(pin), gpio.OUT)
gpio.output(int(pin), int(s))
This is output of cgitb:
/usr/lib/cgi-bin/main.py in ()
14 s = pinState[0]
15 gpio.setmode(gpio.BCM)
16 pin = pins[int(p)]
=> 17 gpio.setup(int(pin), gpio.OUT)
18 gpio.output(int(pin), int(s))
gpio = , gpio.setup = , builtin int = , pin = 2, gpio.OUT = 0
: No access to /dev/mem. Try running as root!
args = ('No access to /dev/mem. Try running as root!',)
message = 'No access to /dev/mem. Try running as root!'
BTW...Raspian Wheezy (May '15), updated and upgraded, Current RPi.GPIO version = 0.5.12a2, Python 2.7.3
So..any pointers would be greatly appreciated. Cheers.