Lightswitch is a set up that allows you to control your house lights with just a raspberry pi zero! All the set up files are in this repository. simply follow the instructions below.
This set up was made on a raspberry pi zero running raspbian jessie lite, while it may work on other distros, it has not been tested.
You will need to run the following command to install all the required programs.
sudo apt-get install python nginx php5 php5-cli php5-fpm libssh2-1-dev libssh2-php
Once everything is installed, edit your nginx
configuration to allow php. I would recommend you keep a backup of the initial configuration just in case. run the following commands.
cd /etc/nginx/
sudo rm ./sites-enabled/default
sudo cp ./sites-available/default ./sites-available/www
sudo ln -s /etc/nginx/sites-available/www /etc/nginx/sites-enabled/www
sudo nano ./sites-enabled/www
Add index.php
where instructed in the file and remove the necessary comments from the php configuration. The final result should look something like this
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Now cd
to where the website is stored (/var/www/html/
)
Place your website in this folder, you can use the one provided in the repo.
Place the lightswitch
file in /usr/local/bin/
.
Thats it, your new wireless light switch should work
It would be a good idea to create another user and have nginx and php run through that user for security reasons. Atleast the default password for the pi should be changed