This is an abstraction between your pc and the lights controller hardware. Try to write your code targeting an abstract webapi. We have an r-pi in R1 controlling real lights. When you come to R1 place, you only need to change the webpapi url, and the r-pi will do the magic.
Here is an example of how lights work with our web service.
virtualenv controllerEnv
source <controllerEnv path>/bin/activate
pip install -r requirements.txt
./run_dev.sh
, by default it will run on localhost:8000
http://localhost:8000
http://localhost:8000/dashboard/<session_name>
http://localhost:8000/help
Here you can find a piece of python code which uses this emulator to create a lights show (similar to the one that we tested live in R1) with the Travis CI data. To access the emulator view, go to this address.
All room sessions are public, if for some reason, you see a strange behavior in your code trying to command the lights, please check the session
name in your data, because probably there is a collision with another colleague of yours. If you have any question about this, please do not hesitate to open an issue on the hackathon repo.
To specify host Ip and Port you must set them as environment variables like:
export APP_PORT=9000
export APP_HOST=0.0.0.0
export APP_DEBUG=True
python src/server.py
To switch between web application lights simulator and real pi controller you must set an environment variable export LIGHT_CONTROLLER=simulator
or export LIGHT_CONTROLLER=controller
We process two REST endpoints with POST method data:
setcolor
illuminates one light based on id for an specific session. Json schema:
{"required": ["id", "color", "session"],
"properties": {
"id": { "type": "string" },
"session": {"type": "string"},
"color": { "type": "array", "items": { "type": "number", "minimum": 0,
"maximum": 255} },
}
setbulk
illuminates lights collection based on id for an specific session. Json schema:
{
"required": ["set", "session"],
"properties": {
"session": {
"type": "string"
},
"set": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"color": {
"type": "array",
"items": {
"type": "number",
"minimum": 0,
"maximum": 255
}
}
}
}
}
}
}
blackout
Reset lights state to a complete black:
{
"required": ["set", "session"],
"properties": {
"session": {
"type": "string"
}
}
}
Simulator app works recieving and processing sent API commands through a websocket channel. Each simulator web app runs in an specific session_name, for example, http://localhost:8000/dashboard/test
will process and draw all sent messages with test
as session id. Opened sessions are shown in the home page of the simulator (http://localhost:8000/
). Clicking a session name will show the session view.
http://localhost:8000/setcolor
with data {"id": "1", "color": [100, 200, 50], "session": "test"}
http://localhost:8000/dashboard/test
) you will see command logs and drawing simulation