Skip to content

Commit

Permalink
FEATURE: color painting
Browse files Browse the repository at this point in the history
  • Loading branch information
linkineo committed Dec 6, 2018
1 parent 6ffeaa7 commit 7183b4f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ This software is not endorsed in any way by the Twinkly team and is to be used a
2. Change the IP of the device to yours in the IP variable of xmas.js (line 3)
3. Execute node xmas.js

This shall turn your lights on.
To turn them off, modify line 191 to xmas(OFF).
This shall turn your lights on and paint them red :-)
To turn them off, modify line 235 to xmas(OFF).
To paint them in any color of your choosing, modify line 240 and set the RGB values accordingly.

### What it does
At the moment, you can turn ON and OFF your lights over HTTP. This shall provide an easy interfacing with your home automation system.
At the moment, you can turn ON and OFF your lights over HTTP, and paint all LEDs in a given color.
This shall provide an easy interfacing with your home automation system.

### Prerequisites

- Any twinkly LED set
- Knowing the IP address of your device

### Next
- LED Discovery: easy to implement, using UDP port 5555 and sending a frame with "DISCOVER" as payload.
- Movie download (needed ? Streaming in RT shall be enough)


1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"color": "^3.1.0",
"request": "^2.88.0"
}
}
55 changes: 52 additions & 3 deletions xmas.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
var request = require("request");
const request = require("request");
const dgram = require('dgram');
const Color = require('color');

var IP = "192.168.0.62"; // ADD YOUR OWN LAMP IP HERE
var CHALLENGE = {'challenge':'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\a'}; // This challenge will do all the time.
var XAUTHTOKEN = "";
var UDP_PORT_RT=7777;
var RT_BUFFER = Buffer.alloc(1+9+175*3,0);
var UDP_RT_HEADER = 0x02;
UDP_RT_HEADER[0] = UDP_RT_HEADER;
var PRODUCT_NAME="Twinkly";
var OFF = {"mode":"off"};
var ON = {"mode": "movie","code": 1000};
var RT = {"mode":"rt"};
var LAMP_STATUS = {
UNREACHABLE: 0,
DETECTED :1,
Expand Down Expand Up @@ -172,6 +179,40 @@ var connect = function(callback){
}


var paint_single_color = function(color_value)
{
var udp_token = Buffer.from(XAUTHTOKEN,"base64");
udp_token.copy(RT_BUFFER,1,0,udp_token.length);

var color_buffer=Buffer.alloc(3);
color_buffer[0] = color_value.red();
color_buffer[1] = color_value.green();
color_buffer[2] = color_value.blue();
RT_BUFFER.fill(color_buffer,10,RT_BUFFER.length);

var client = dgram.createSocket('udp4');
client.send(RT_BUFFER, UDP_PORT_RT, IP, (err) => {
client.close();
});

}


var xmas_paint = function(color_value)
{
connect(function(status) {
if(status == LAMP_STATUS.AUTHENTICATE_OK)
{
action(RT, function(status){
if(status == LAMP_STATUS.ACTION_SUCCESS)
{
paint_single_color(color_value);
}
})
}
})
}

var xmas = function(mode)
{
connect(function(status) {
Expand All @@ -188,7 +229,15 @@ var xmas = function(mode)
}

//TURN THE LAMPS ON
xmas(ON);
// xmas(OFF) to turn the lamps OFF...
//xmas(ON);

//TURN THE LAMPS OFF
//xmas(OFF);

//TURN ON AND PAINT A COLOR (The LEDs will automatically revert to their normal ON mode (movie) after a few seconds)
xmas_paint(Color("red"));
//TURN ON AND PAINT ANY RGB COLOR
//xmas_paint(Color.rgb(118,36,242));



0 comments on commit 7183b4f

Please sign in to comment.