Node.js microservice used to serve as a clean RESTful remote interface to Milight lights
- Git clone this repository.
$ yarn install
- Copy
keys.json.example
tokeys.json
and populate with your own desired client keys. $ yarn start
(oryarn dev
for development use)
The service authenticates clients using a client key sent via the X-Client-Key
HTTP header. Every request must contain this header. If this header is missing, or its value is empty, the service returns 401.
When a request arrives, the service checks whether the provided client key is included in the permitted array of client keys (based on keys.json
). If it is not, the service returns 403.
You can change the port the service listens on, by specifing it in the PORT
environment variable when starting the service. For example:
$ PORT=8000 yarn start
The default port is 3000.
The service, by default, starts to look for the Milight lamps at 255.255.255.255:8899
. You can override this easily using the LIGHTS_ADDRESS
and LIGHTS_PORT
environment variables. For example:
$ LIGHTS_ADDRESS=192.168.0.121 LIGHTS_PORT=8888 yarn start
The service uses the node-milight
to abstract away actual hardware communication, but, should the need arise to, this can be easily swapped with another implementation. See lib/lights.js
source for details.
After starting the service, you can send HTTP POST requests to the root URL. The request body must contain at least one valid commmand. See Commands section below, to get more details on how commands work.
This section lists possible commands for the service.
Turn the lights on:
{
"power": "on"
}
Turn the lights off:
{
"power": "off"
}
{
"color": "#fff"
}
{
"color": "#f0f0f0"
}
{
"color": "red"
}
Dim the lights to 50% brightness.
{
"dim": 50
}
If everything went well, the service will return status 200, and this body:
{
"error": false
}
If there was an error, the service will return the corresponding status code (4xx for client error, 500 for server error), and a body describing the actual error with a message:
{
"error": "Invalid client key sent"
}
MIT © Máté Farkas