Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working example for setting color, brightness and receiving color,
brightness and name
- Loading branch information
1 parent
42ae4e7
commit bd90be5
Showing
7 changed files
with
316 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Florian Pfitzer | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Avea Bulb | ||
|
||
|
||
## Binary Protocol | ||
|
||
Communication with a bulb is done via the service `f815e810456c6761746f4d756e696368` and its characteristic `f815e811456c6761746f4d756e696368`. | ||
The first byte in the protocol is the command, the others are the payload. When sending a command without payload the current value from this command is send back as notification. | ||
|
||
### Available Commands | ||
|
||
* 0x35: Color | ||
* 0x58: User defined name of the bulb | ||
* 0x57: Brightness | ||
|
||
### Color | ||
|
||
The color is defined by these four variables: white, red, green, blue. Each variable has a value between 0 and 4095 (0xfff). | ||
|
||
The byte sequence, which has to be send to bulb can be computed on the following way: | ||
|
||
For example we set the color to `w: 0xaaa, r: 0xbbb, g:0xccc, b:0xddd`, with a fading of `0x111` we send: | ||
|
||
|
||
| `35` | `11 01`| `0a 00`| `aa 8a`| `bb 3b`| `cc 2c`| `dd 1d`| | ||
|----------|-----------|-----------|-----------|-----------|-----------|-----------| | ||
|Color command | fading in LE | unkown | white with 8 as prefix | red with 3 as prefix | green with 2 as prefix | blue with 1 as prefix | | ||
|
||
To compute the color part the following js function is used: | ||
|
||
```javascript | ||
const buffer = new Buffer(8); | ||
buffer.writeUInt16LE(this.white | 0x8000, 0); | ||
buffer.writeUInt16LE(this.red | 0x3000, 2); | ||
buffer.writeUInt16LE(this.green | 0x2000, 4); | ||
buffer.writeUInt16LE(this.blue | 0x1000, 6); | ||
``` | ||
|
||
The color send back through the notification has a different format. For the same values as set above the following bytes are received: | ||
|
||
| `35` | `da 0a` | `5e 1d` | `57 2c` | `4f 3b` | `aa 0a` | `dd 1d` | `cc 2c`| `bb 3b`| | ||
|-------|----------|----------|---------|---------|---------|---------|--------|--------| | ||
| Color command | current white (`0xada`) | current blue (`0xd5e`) | current green (`0xc57`) | current red (`0xb4f`) | target white (`0xaaa`) | target blue (`0xddd`) | target green (`0xccc`) | target red (`0xbbb`) | | ||
|
||
|
||
```javascript | ||
// command code byte already stripped | ||
|
||
// these are the current colors of the lamp. | ||
let white = buffer.readUInt16LE(0); | ||
let blue = buffer.readUInt16LE(2) ^ 0x1000; | ||
let green = buffer.readUInt16LE(4) ^ 0x2000; | ||
let red = buffer.readUInt16LE(6) ^ 0x3000; | ||
|
||
// these are the colors the lamp is fading to. | ||
let whiteTarget = buffer.readUInt16LE(8); | ||
let blueTarget = buffer.readUInt16LE(10) ^ 0x1000; | ||
let greenTarget = buffer.readUInt16LE(12) ^ 0x2000; | ||
let redTarget = buffer.readUInt16LE(14) ^ 0x3000; | ||
``` | ||
|
||
|
||
### Name | ||
|
||
The name is received as a null terminated string. For example: `0x58 0x45 0x6c 0x67 0x61 0x74 0x6f 0x20 0x41 0x76 0x65 0x61 0x00` = Elgato Avea | ||
|
||
### Brightness | ||
|
||
Brightness goes from 0-4095 and is send and received as little endian value. | ||
|
||
e.g. `0x57ff0f` for 4095. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"use strict"; | ||
|
||
class Color { | ||
/** | ||
* each parameter goes from 0-4095 (0xfff) | ||
* | ||
* @param white | ||
* @param red | ||
* @param green | ||
* @param blue | ||
*/ | ||
constructor(white, red, green, blue) { | ||
this.white = white; | ||
this.red = red; | ||
this.green = green; | ||
this.blue = blue; | ||
} | ||
|
||
toString() { | ||
return "{white: " + this.white + ", red: " + this.red + ", green: " + this.green + ", blue: " + this.blue + "}"; | ||
} | ||
|
||
toBuffer() { | ||
let color = new Buffer(8); | ||
color.writeUInt16BE(this.white, 0); | ||
color.writeUInt16BE(this.red, 2); | ||
color.writeUInt16BE(this.green, 4); | ||
color.writeUInt16BE(this.blue, 6); | ||
|
||
const buffer = new Buffer(8); | ||
buffer.writeUInt16LE(this.white | 0x8000, 0); | ||
buffer.writeUInt16LE(this.red | 0x3000, 2); | ||
buffer.writeUInt16LE(this.green | 0x2000, 4); | ||
buffer.writeUInt16LE(this.blue | 0x1000, 6); | ||
|
||
return buffer; | ||
} | ||
|
||
static fromResponse(buffer) { | ||
// these are the current colors of the lamp. | ||
let white = buffer.readUInt16LE(0); | ||
let blue = buffer.readUInt16LE(2) ^ 0x1000; | ||
let green = buffer.readUInt16LE(4) ^ 0x2000; | ||
let red = buffer.readUInt16LE(6) ^ 0x3000; | ||
|
||
// these are the colors the lamp is fading to. | ||
let whiteTarget = buffer.readUInt16LE(8); | ||
let blueTarget = buffer.readUInt16LE(10) ^ 0x1000; | ||
let greenTarget = buffer.readUInt16LE(12) ^ 0x2000; | ||
let redTarget = buffer.readUInt16LE(14) ^ 0x3000; | ||
|
||
return { | ||
current: new Color(white, red, green, blue), | ||
target: new Color(whiteTarget, redTarget, greenTarget, blueTarget) | ||
}; | ||
} | ||
} | ||
module.exports = Color; |
Oops, something went wrong.