1
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(18, GPIO.OUT)
print "<h1> line 4 </h1>"

The above does not print line 4 in client's browser

  • All the python GPIO statements are in seperate lines – Akshay Aggarwal Apr 9 '15 at 18:24
  • What makes you think that the script is being executed? – joan Apr 9 '15 at 19:15
1

You don't say which webserver you are using, but in general they don't run CGI scripts with root privileges, meaning the script will fail when it tries to access the GPIOs.

You could check the server error logs to confirm this.

0

I've placed the following script in /usr/lib/cgi-bin with the name joan.html (made executable with chmod +x) on a Pi2 called paul.

#!/usr/bin/env python

import pigpio

print"""
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
   <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
   <title>pigpio cgi</title>
</head>
<body>
"""

pi=pigpio.pi()
pi.set_PWM_frequency(4, 0)
pi.set_PWM_dutycycle(4,128)
print("<h2>gpio 4 frequency={}</h2>".format(pi.get_PWM_frequency(4)))
pi.stop()

print"""
</body>
</html>
"""

I'm using apache2 on the Pi with cgi enabled with the command

sudo a2enmod cgid

The pigpio daemon has been started on the pi with the command

sudo pigpiod

Entering the following command on a networked browser runs the script.

http://paul/cgi-bin/joan.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.