Skip to content

Christmas tree lights for the Minsky/Steele house.

License

Notifications You must be signed in to change notification settings

mlsteele/xmas-lights

Repository files navigation

Xmas Tree Lights

Christmas tree lights for the Minsky/Steele house.

A Python program that runs on a Raspberry Pi and animates the lights on an APA102 (Dotstar) LED strip.

This README is divided into three sections:

Table of Contents

Raspberry Pi

Raspberry Pi Installation

Enable the raspberry pi's SPI in raspi-config. This will require a reboot.

sudo raspi-config

Clone the repo:

git clone https://github.com/mlsteele/xmas-lights
cd xmas-lights

Install the required dependencies:

sudo apt-get install -y python-pip
pip install -r pi-requirements.txt

Running on the Pi

To run the lights:

python lights.py

To run the lights whenever the Pi boots, use sudo nano /etc/rc.local or another editor to add this line to ``/etc/rc.local`.

Note that this will swallow error messages. If things aren't working, debug it running it from the terminal as above.

sudo python lights.py > /dev/null 2>&1 &

(If you change the /etc/rc.local line to log to a file: beware of filling up your file system, and be aware that continuously writing to an SD card increases the likelihood that it will be corrupted if power to the Pi is cut while the Pi is running.)

Live-Reload

For development, you can set up the Pi to restart the application whenever its sources change.

Do this once:

curl http://entrproject.org/code/entr-3.4.tar.gz | tar xz
cd eradman-entr-* && ./configure && sudo make install

and run the lights thus:

./live-reload.sh

Now when you edit a *.py file, the program will reload.

Development Workstation

If you prefer to edit on a separate development workstation, you can configure it to download files to the Pi when they change on the development workstation. In conjunction with the Live-Reload flow, above, this has the effect that when you save a file from the editor on your workstation, the application on the Pi will shortly re-run with the changes.

Mac OS Installation

Install Homebrew. Then:

brew install ssh-copy-id entr

Linux Installation

apt-get install -y entr

Installation (Mac OS and Linux)

On the development station, download the repo:

git clone https://github.com/mlsteele/xmas-lights
cd xmas-lights

Find your Pi's IP address, and add an entry in your ``.ssh/configon your development workstation. For example, if your Pi's IP address is192.168.0.36`, add the following.

Host xmas-pi
  HostName 192.168.0.36
  User pi

Configure your Pi for passwordless login:

[ -f ~/.ssh/id_rsa.pub] || ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub pi@xmas-pi

Live Reload Development Flow

Run ./live-reload.sh on the Pi. Use the first line below to simply run it:

ssh pi@xmas-pi xmas-lights/live-reload.sh

Or, use this block to create a screen session that will remain running if you lose the connection to the Pi, and that you can attach to again using the same command:

ssh pi@xmas-pi -t screen -dR lights
xmas-lights/live-reload.sh

Run this on the development station:

./live-download.sh

Server

Server Configuration

The server and the Pi communicate using RabbitMQ. Provision a RabbitMQ host, and retrieve its URI. The URI should look something like this: amqp://user:pass@host:10000/vhost.

Edit the RabbitMQ URI into the Raspberry Pi's /etc/environment file, via sudo nano /etc/environment or another editor. Remember to replace the example URI below by your Rabbit's URI.

RABBIT_URL=amqp://user:pass@host:10000/vhost

Local Server Development

Run one of the following: apt-get install -y entr python-pip # Linux brew install entr python # Mac OS

Inside the xmas-lights directory:

pip install -r requirements.txt # once
python webserver.py

Server Deployment

Deploy

The simplest way to deploy the app is to create a Heroku application, add a RabbitMQ add-on, and push this repository to the application.

Automation

To turn the lights on at 7:15 AM and off at 11:30 PM, add these lines to the Pi's crontab:

30 03 * * * /usr/bin/python /home/pi/xmas-lights/publish_message.py off >> /var/log/xmas-lights.log 2> /var/log/xmas-lights.err
15 12 * * * /usr/bin/python /home/pi/xmas-lights/publish_message.py on >> /var/log/xmas-lights.log 2> /var/log/xmas-lights.err

This assumes the Pi is set to UTC and that it's wintertime (DST) on the East Coast.

Credits

apa102.py no longer uses Martin Erzberger's APA-102c LED control lib library, but it was helpful traiing wheels for getting started.

An earlier version used the Adafruit_DotStar_Pi library. Erzberger's library is both pure Python and faster.

About

Christmas tree lights for the Minsky/Steele house.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published