A DIY web driven scheduler system for the Raspberry Pi written in Python using lighttpd and pigpio. This is typically used to support a irrigation system with multiple sprikler valves, but you could also use it to control other devices.
(If you are looking for a more turnkey and feature rich solution for your RPi, I highly recommend OpenSprinkler Pi instead.)
- Raspberry Pi (or other dev board capable of running Python and Lighttpd)
- WiFi dongle (if not using RPi v3)
- Power Supply for RPi
- 24V AC Sprinkler Power Supply
- Sprinler Valves
- 5V Relay Board
- Lighttpd must be installed
- Pigpio must be installed
- RPi must be configured to connect to your network
auth.debug = 2
auth.backend = "plain"
auth.backend.plain.userfile = "/etc/.lighttpdpassword"
auth.require = ( "/cgi-bin/" =>
(
"method" => "basic",
"realm" => "Password protected area",
"require" => "user=admin"
)
)
$HTTP["url"] =~ "^/" {
cgi.assign = (".py" => "/usr/bin/python")
}
Change the username from "admin" to whatever you want.
admin:password
Change the password to whatever you want.
Run the following command to enable the cgi mod.
lighty-enable-mod cgi
sudo service lighttpd restart
sudo nano /etc/rc.local
Add ...
pigpiod &
/path to your cgi-bin directory/scheduler.py &
... before the "exit" statement.
Open the scheduler.py script and change the values in station to match the GPIO pins you connected to your relay board.
Add the "www-data" user to the /etc/sudoers file by using visudo. NOTE: This weakens the security of your system in that a knowledgeable person might be able to reboot or shutdown your RPi. You have been warned.
sudo visudo
Add these lines to the bottom of the file.
www-data ALL=/sbin/shutdown
www-data ALL=NOPASSWD:/sbin/shutdown
I am still working on the script to change/add programs. For now you will have to open the schedule.py script and manually edit the job1 function and the scheduler.add_job statement so that the program runs when you want it to. If you want multiple programs you can define another job function (i.e. job2) and add another scheduler.add_job statement to run it as well.
Here is the way the job1 function works:
def job1(): # The name of the job
print("Job 1 running!")
running = True
pi.write(station[0], 0) # Sets the first GPIO pin LOW which activates the associated relay
time.sleep(600) # Wait 10 minutes
pi.write(station[0], 1) # Sets the first GPIO pin HIGH which de-activates the associated relay
time.sleep(1) # Wait for 1 second
Reboot your RPi. Open a web browser and type in the IP address of your RPi. You should see the index.py page.
