title: Python script to light up a led on Raspberry Pi when webpage is viewed?
body: <p>I'm struggling with what i wrote in the subject. The situation is like this:</p>
  
  <p>I have RPi with a lighttpd on address <code>http://myrpi.com/</code>
  I have another website on address <code>http://othersite.com/</code></p>
  
  <p>In the index of other site (<code>http:\\othersite.com\index.html</code>) i want to embed a python script which serves an empty pixel image from the myrpi.com (<code>&lt;img src="http://myrpi.com/pixel.py"&gt;</code>)</p>
  
  <p>In this script apart from read a png file and printing it's internals back to the requester - I want it to run few shell commands which will light up a led through RPi gpio.</p>
  
  <p>So far I got to this script with the help of others, but it still doesn't work. the serving image part works, the led - doesn't. even though same commands in the command line work fine:</p>
  
  <pre><code>#!/usr/bin/env python
  
  import subprocess
  import time
  import cgi
  import cgitb
  
  
  cgitb.enable()
  
  subprocess.check_call(['/home/pi/scripts/wiringPi/gpio/gpio' ,'write', '7', '1'])
  
  
  print "Content-type: image/jpeg\n"
  
  
  f=open("/var/www/cgi-bin/1.png")
  data=f.read()
  f.close()
  print data
  
  
  time.sleep(0.5)
  
  subprocess.check_call(['/home/pi/scripts/wiringPi/gpio/gpio', 'write', '7', '0'])
  </code></pre>
  
  <p>Though, with the <code>subprocess.check_call</code> I get an exception (with a normal <code>subprocess.call</code> - serves an image but no led): <a href="http://i.imgur.com/wJR17tB.png" rel="nofollow">http://i.imgur.com/wJR17tB.png</a></p>
  
  <p>A bit lost here. Any ideas how this can be done differently? or how to fix this problem?</p>
  
  <p>Thank you!</p>
  
  <p><strong>update:</strong></p>
  
  <p>if i run this in a command line:</p>
  
  <p><code>$ sudo /home/pi/scripts/wiringPi/gpio/gpio write 7 1</code> </p>
  
  <p>it works. without <code>sudo</code> - it says:</p>
  
  <p><code>/home/pi/scripts/wiringPi/gpio/gpio: Must be root to run. Program should be suid root. This is an error.
  </code></p>
  
  <p>if i suid (<code>chmod u+s</code>) gpio then it doesn't work even with sudo.</p>