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:
print "Content-Type: text/html\n\n"
import cgitb; cgitb.enable() # Optional; for debugging only
import RPi.GPIO as gpio
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
s = pinState
pin = pins[int(p)]
This is output of cgitb:
/usr/lib/cgi-bin/main.py in ()
14 s = pinState
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.