Editing Holiday lights
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
We put up some holiday lights in the Mission Street windows. (We call them Holiday Lights both as an ecumenical gesture of goodwill as well as to annoy the "War on Christmas" wingnuts.) | |||
Naturally, you can control them on the web using the bare-bones interface at URL: http://lights.netisland.net:8080/ | |||
This is served by a pure Python webserver running on a Fit-PC Ubuntu micro-PC. | |||
Basic info: | Basic info: | ||
<nowiki> | |||
/home/lights/server/filelooop.py | |||
/home/lights/ | This is the script that runs forever, and does the Actual | ||
Work of switching the lights on and off. It reads the | |||
file /home/lights/sequence, which defines the light | |||
sequence, and then uses the RelayControl class to | |||
communicate with the external relay bank. | |||
/home/lights/sequence | |||
The file read by filelooop.py that defines the light | |||
sequence currently active. The first line of this file | |||
defines how long (in milliseconds) we should sleep before | |||
advancing to the next state. The rest of the file is a | |||
list of states to iterate through. For example: | |||
1000 | |||
10000000 | |||
01000000 | |||
00100000 | |||
00010000 | |||
00001000 | |||
00000100 | |||
00000010 | |||
00000001 | |||
We sleep for 1 second (1000 milliseconds) between states. | |||
In the first state, the first light is on, and the rest | |||
are off. In the second state, the second light is on, and | |||
the rest are off. In the third state, the third light is | |||
on, and the rest are off. etc. | |||
(There's code in place in filelooop.py to also support | |||
state lines in the syntax of "<state> <delay>", to sleep | |||
for an amount of time different than the "global delay", | |||
but I haven't actually tested this behavior yet.) | |||
the | |||
/home/lights/*.seq | |||
A list of pre-programed sequences. | A list of pre-programed sequences. | ||
/home/lights/server/webserver.py | |||
A full webserver/framework implementation, currently | A full webserver/framework implementation, currently | ||
configured to listen on port 8080. When you request "/", | configured to listen on port 8080. When you request "/", | ||
it returns a list of hyperlinks to each of the *.seq files | it returns a list of hyperlinks to each of the *.seq files | ||
in lights's home directory. If you click on one of those | in lights's home directory. If you click on one of those | ||
links, it copies the contents from the *.seq file to | links, it copies the contents from the *.seq file to | ||
/home/lights/sequence, so filelooop.py will start | /home/lights/sequence, so filelooop.py will start | ||
processing it instead of whatever it was previously | processing it instead of whatever it was previously | ||
processing. | processing. | ||
/home/lights/set.html | |||
When you use webserver.py to request a *.seq file, it | When you use webserver.py to request a *.seq file, it | ||
returns the contents of /home/lights/set.html to the | |||
probably also have a meta refresh to redirect the user | browser. Right now, this file contains just | ||
back to / (the directory listing) after a few seconds, | "<h1>Thanks!</h1>". We should make it look pretty, and | ||
or something. | probably also have a meta refresh to redirect the user | ||
back to / (the directory listing) after a few seconds, | |||
or something. | |||
If we want to get fancy, we should also look into using | |||
one of the python templating libraries, so we can have a | |||
static index.html page independent of the code, and then | |||
make that index.html file look pretty, too. We just need | |||
to find out how to interpolate a list of files to display | |||
in he the directory listing. | |||
</nowiki> | |||