====== Application ====== I wanted to have a web application through which I can access my sockets through a computer or iPad. The following components make this possible: * Apache web server with PHP5, see [[deb720:apache|Apache2 Web Server]] * Cron * The SQLite3 library, consisting of PHP files only, and myLiteAdmin.php to administer the database * Some custom PHP code * A daemon written in C++ utilizing the wiringPi and RCSwitch libraries, see [[rpi:gpio|Access to GPIO]] ===== Custom PHP code ===== ===== SQLite3 library ===== ===== Daemon ===== First, develop and trouble shoot the daemon binary. ==== Check the daemon ==== Start the daemon, then find it's process id (pid): $ ps -ax | grep Find all open files: # lsof -p ==== Create the init script ==== On Debian systems, copy the skeleton file and modify to your needs. This is quite simple and straight forward. # cp /etc/init.d/skeleton ~/scripts/ # vim ==== Install the daemon ==== Copy the binary file: # cp ~/binaries/ /usr/sbin Copy the script: # cp ~/scripts/ /etc/init.d Add the daemon to the different run-levels: # update-rc.d defaults Remove the daemon from the different run-levels: # update-rc.d -f remove See [[https://wiki.debian.org/Daemon|Daemon]] and [[https://wiki.debian.org/LSBInitScripts|LSBInitScripts]] for more details. ===== Cron ===== Run crontab -e and enter the following lines: */5 * * * * wget http://localhost/path/to/web/code/state-machine.php * 14 * * * wget http://localhost/path/to/web/code/randomize.php The first line will run the state machine every 5 minutes. The second line will randomize your on / off pattern every day at 14:00.