# skyglow Python program written for the ecoLux project in the ecoTron to periodically set light-intensities of the LED's in the ecoUnits. <ul> <li>Parses a file containing the time and light intensities (mlx) for the moon</li> <li>Converts the lightintensities to a DMX-Value (0-255)</li> <li>Sets the moon-LED and 3-lightpollution LED's for each ecounit</li> <li>logs the time and value</li> </ul> This was tested and run on a Raspberry Pi connected via DMX to the LED's in the ecounits. OLA (Open Light Architecture Framework) is used to write to the DMX-Bus. ##Usage## ```console skyglow.py ``` will look for a file called **moon** in its directory, to extract the intensities of the moon for the current time. Alternatively you can also pass a file as an argument. ```console skyglow.py /path/to/moon/file ``` If everything worked, a line should be added to skyglow.log: ``` #date moon[mlx] moon[dmx] lightpollution[mlx] 2020-07-21 15:00:00 0.05 11 [15, 54, 4, 19, 0, 1, 5, 0, 40, 12, 123, 123] ``` The indices of the list containing the lightpollution valus refer to the number of the ecounits. ##Setup## ###Building OLA### In order to get a recent version with python support we need to build OLA. See [this](https://www.openlighting.org/ola/tutorials/ola-on-raspberry-pi/) and [this](https://www.openlighting.org/ola/linuxinstall/#Debian_Ubuntu) for details. Install libraries (Python 2.x): ```console sudo apt-get install libcppunit-dev libcppunit-1.15-0 uuid-dev pkg-config libncurses5-dev libtool autoconf automake g++ libmicrohttpd-dev libmicrohttpd12 protobuf-compiler libprotobuf-lite17 python-protobuf libprotobuf-dev libprotoc-dev zlib1g-dev bison flex make libftdi-dev libftdi1 libusb-1.0-0-dev liblo-dev libavahi-client-dev python-numpy ``` Clone repository: ```console git clone https://github.com/OpenLightingProject/ola.git ola cd ola ``` Configure for python: ```console autoreconf -i configure --enable-python-libs ``` Build ```console make -j4 #run on 4 jobs (use nproc to check number cores) make -j4 check sudo make install sudo ldconfig ``` Run the daemon: ```console olad ``` ###new moonfile### If you acquire a new moonfile, make sure to replace all occurrences of **24:00** to **00:00**. Otherwise python will throw an error. ```console sed -i 's/24:00/00:00/g' moonfile ``` ###cron### Set up a cronjob to check for new values every minute. Run ``` crontab -e ``` and insert ``` PATH=/usr/bin:/path/to/directory/containing/skyglow/ * * * * * skyglow.py ``` Check the `skyglow.log` to see if it gets updated every minute. ``` watch -n1 tail skyglow.log ```