Skip to content

Commit

Permalink
Updated README and history
Browse files Browse the repository at this point in the history
  • Loading branch information
mwittig committed May 13, 2016
1 parent b960543 commit a31e14c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 11 deletions.
11 changes: 10 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@
* Bug fix: Fixed array value checks of MilightController
* Bug fix: Close discovery socket on error
* Improved error handling
* Improved test coverage
* Improved test coverage
* 20160513, V0.0.9
* Bug fix: Brightness level never reached maximum brightness for RGBW
* Bug fix: With `commandRepeat > 1` stacked commands were sent in wrong order
* Bug fix: Broadcast mode wasn't set automatically with a network-specific
broadcast ip address
* Added `rgbw.brightness2()` which maps brightness 0-100 to 22 levels
* Added support for using 2-byte command sequences
* Changed default command delay and repeat values
* Updated examples
82 changes: 72 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A node module to control Milight LED bulbs and OEM equivalents such as Rocket LE

## Introduction

Milight uses a very primitive three-byte-sequence one-way communication protocol where each command must be sent in a
Milight uses a very primitive one-way communication protocol where each command must be sent in a
single UDP packet. It is just fire & forget similar to simple RF protocols for garage door openers and such.
Compared to other Milight libraries, I am using a more aggressive timing for the delay between sending UDP command
packets (```delayBetweenCommands``` property).
Expand All @@ -22,7 +22,37 @@ Milight uses a very primitive three-byte-sequence one-way communication protocol
Wifi network there is another lossy communications channel between the Milight Controller and the bulbs. My strategy
against loss is to repeat each command. By default it will be send three times (```commandRepeat``` property).

## What's new: Bridge Discovery
## What's new

### Brightness

I noticed the `rgbw.brightness()` command never reached the maximum brightness level of the bulb and it turned out to be
yet another bug in the `commands` file. I also found an article suggesting the RGBW bulbs support 22 brightness levels
instead of 20, however, the two additional levels did not change the brightness for me (tested with 6W bulbs). Maybe
this is different with 9W bulbs. For this reason, I have added `rgbw.brightness2()` which maps brightness 0-100 to
22 levels.

Another interesting observation is the RGBW bulbs keep brightness levels for color mode and white mode, individually.
Thus, you may notice a change in brightness if you switch to white mode, for example. So, if your application only
maintains a single brightness control you need to make sure to send the commands in the right order!

### Rendering RGB colors

For RGBW bulbs the command `rgbw.rgb255` is provided to map RGB values to Milight. However, the
color space of Milight is limited, as it is not possible to control color saturation and there are only 20
brightness levels. Thus, the results may be disappointing when compared to other LED lightning technologies.
Effectively, Milight is unable to display different shades of grey.

### 2-byte Command Sequences

Recently, I found out that Milight bridge version 3 and higher can also handle 2-byte command sequences instead of
3-byte command sequence. Basically, the last byte of the 3-byte command sequence, call it stop byte, can be omitted.
It is said the 2-byte command sequences provide better performance. This may be true for the Milight RF protocol,
but I don't think it has an significant impact on the IP communication between the application and the bridge. To use
the 2-byte command sequences you can simply use `commands2` instead of `commands`. Mixing 2-byte and 3-byte sequences
is also supported.

### Bridge Discovery

The new bridge discovery function can be used to discover the IP and MAC addresses of Milight v4 Wifi bridges found
on the local network. The following options can be provided to the discovery function.
Expand All @@ -40,30 +70,62 @@ An array of results is returned. Each result contains the following properties:

See also example code provided in the `examples` directory of the package.

var Milight = require('../src/index').MilightController;
var commands = require('../src/index').commands;
var Milight = require('node-milight-promise').MilightController;
var commands = require('node-milight-promise').commands2;

// Important Notes:
// Instead of providing the global broadcast address which is the default, you should provide the IP address
// of the Milight Controller for unicast mode. Don't use the global broadcast address on Windows as this may give
// unexpected results. On Windows, global broadcast packets will only be routed via the first network adapter. If
// you want to use a broadcast address though, use a network-specific address, e.g. for `192.168.0.1/24` use
// `192.168.0.255`.

var light = new Milight({
ip: "255.255.255.255",
delayBetweenCommands: 50,
delayBetweenCommands: 75,
commandRepeat: 2
}),
zone = 1;

light.sendCommands(commands.rgbw.on(zone), commands.rgbw.brightness(100), commands.rgbw.whiteMode(zone));
light.sendCommands(commands.rgbw.on(zone), commands.rgbw.whiteMode(zone), commands.rgbw.brightness(100));
light.pause(1000);

for (var x = 100; x >= 0; x -= 5) {
light.sendCommands(commands.rgbw.brightness(x));
light.sendCommands(commands.rgbw.off(zone));
light.pause(1000);

// Setting Hue
light.sendCommands(commands.rgbw.on(zone));
for (var x = 0; x < 256; x += 5) {
light.sendCommands(commands.rgbw.hue(x));
if (x === 0) {
commands.rgbw.brightness(100)
}
light.pause(100);
}
light.pause(1000);

light.sendCommands(commands.rgbw.off(zone));
light.pause(1000);

// Back to white mode
light.sendCommands(commands.rgbw.on(zone), commands.rgbw.whiteMode(zone));
light.pause(1000);


// Setting Brightness
light.sendCommands(commands.rgbw.on(zone));
for (var x = 100; x >= 0; x -= 5) {
light.sendCommands(commands.rgbw.brightness(x));
light.pause(100);
}
light.pause(1000);

light.sendCommands(commands.rgbw.off(zone));
light.close();
light.pause(1000);

light.close().then(function () {
console.log("All command have been executed - closing Milight");
});
console.log("Invocation of asynchronous Milight commands done");

## Usage example for Discovery

Expand Down

0 comments on commit a31e14c

Please sign in to comment.