Zefes wrote:Can someone please write an easier step by step guide. I tried to read both links you sent me but I can't follow. Do I need to write a cgi or something? I already have a page on the Apache directory, do I have to modify it?
If you are using Apache2 as a web-server on your Pi you could do the following.
1. Enable CGI with the command
sudo a2enmod cgid
2. Copy the following two scripts to /usr/lib/cgi-bin on the Pi
gpio4_on.py
Code: Select all
#!/usr/bin/env python
import pigpio
print("Content-type:text/html\r\n\r\n")
print("<html><head><title>gpio4 on</title></head><body>")
pi=pigpio.pi()
pi.write(4, 1)
pi.stop()
print"</body></html>"
gpio4_off.py
Code: Select all
#!/usr/bin/env python
import pigpio
print("Content-type:text/html\r\n\r\n")
print("<html><head><title>gpio4 on</title></head><body>")
pi=pigpio.pi()
pi.write(4, 0)
pi.stop()
print"</body></html>"
3. Make each script executable
In /usr/lib/cgi-bin
chmod +x gpio4_on.py
chmod +x gpio4_off.py
4. Add the following code to your web-page
Code: Select all
<form action="http://localhost/cgi-bin/gpio4_on.py">
<input type="submit" value="gpio4 On">
</form>
<form action="http://localhost/cgi-bin/gpio4_off.py">
<input type="submit" value="gpio4 Off">
</form>
Or if you want a new page just add a page called cgi.html
Code: Select all
<html><body>
<form action="http://localhost/cgi-bin/gpio4_on.py">
<input type="submit" value="gpio4 On">
</form>
<form action="http://localhost/cgi-bin/gpio4_off.py">
<input type="submit" value="gpio4 Off">
</form>
</body></html>
5. This example uses my
pigpio library and need the pigpio daemon to be running on the Pi.
sudo pigpiod
6. Enter the web-page address in your browser, e.g. localhost/index.html or localhost/cgi.html
You can do similar with any libraries you want to use.
Edited to change hard coded web-server host from paul to localhost.