Friday, January 9, 2015

Toggle a GPIO LED on Raspberry Pi Through the Web

Going to try the CGI thing.

First order of biz is to ensure "mod_cgi" is part of server.modules in /etc/lighttpd/lighttpd.conf

This one seems pretty authoritative : http://raspberrypi.stackexchange.com/questions/1346/how-to-get-python-to-work-with-lighttpd

Add to the .conf :
$HTTP["url"] =~ "^/cgi-bin/" {
        cgi.assign = ( ".py" => "/usr/bin/python" )
}
And restart lighttpd with sudo service lighttpd force-reload.

Then, documentation is so crappy on RPIO and RPi.GPIO - horrible, I want to know what the port can be other than GPIO.OUT. I try all kinds of searches, finally ask where easy_install puts files and get some luck there (/usr/local/lib). So, there, the python3.2 is nothing - why all this confusion? Why can't the authors maintain some decent documentation?

GPIO_FUNCTIONS = {0: "OUTPUT", 1: "INPUT", 4: "ALT0", 7: "-"}

Is what I find in /usr/local/lib/python2.7/dist-packages/RPIO-0.10.0-py2.7-linux-armv6l.egg/RPIO/_RPIO.py
*ds!

Now, what is the default for a port? Ans : 1 - input - good to know - so, it's not a good idea to change that to an OUT arbitrarily if you don't know what you're doing..

Now, that being done, the CGI thing isn't working for running a python script in /var/www/cgi-bin. Seems like that thing doesn't run as root - which is needed to access GPIO. So, what can we do?

My workaround seems to be on the right lines - I was thinking of running a daemon that would look for requests to toggle the pin 17. Others online suggest the use of pigpio which doesn't require root, but, then you're again having to run the pigpio daemon, so it's the same concept.. Hmm... Why such crappiness?

No comments:

Post a Comment