--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I'm using the message topic as an MQTT style 'address' for the light bulb. The last path component is the lamp number, or a '0' or '+' meaning 'all' or 'group' according to the device's semantics. The message payload is the command. 'On' and 'off' do what you would expect, with 1 and 0 synonymous (strings or numbers). There's also a 'toggle' (on/off) command as some devices work like that. For dimming commands, I accept 'dim', 'brightness' or 'Level' with a number from 0 to 1, or a value from 0% to 100%, or 'dim+' or 'dim-' for devices that work that way. I allow 'mood' commands 1 to 5 for LightwaveRF devices. All the commands are interpreted by matching RE's so it's pretty liberal at what it accepts, and case insensitive.
If anyone had any spare time they could lend me, it would help ;-) Seriously, testing effort will be much appreciated. Watch this space!
Max
/**
Filename: commands.js
AppLamp.nl led light API: wifi box byte commands
© AppLamp.nl: you can share,modify and use this code (commercially) as long as you
keep the referer "AppLamp.nl led light API" in the file header.
RESPECT AT LEAST 50 MS BETWEEN EACH SEND COMMAND TO PREVENT PACKAGE LOSS
The functions in this file will return the appropriate hex commands as 3 byte array
to send to an UDP-socket towards WIFI BOX-IP:8899 (see wifibox.js)
Example Usage in Node JS:
var cmd = require('commands.js');
example turn on all white bulbs on:
cmd.white.allOn();
set the hue of a color bulb to yellow
cmd.rgbw.hue(128);
**/
var ColorRgbwCmd = function(){};
var WhiteCmd = function(){};
var ColorRgbCmd = function(){};
//makes the rgb/rgbw/white variables globally available in NodeJS
// for ex. use: commands.rgbw.hue(64);
module.exports = { rgb: new ColorRgbCmd()
,rgbw: new ColorRgbwCmd()
,white: new WhiteCmd() };
/*RGBW BULBS AND CONTROLLERS, 4-CHANNEL/ZONE MODELS */
/* Switch ON() your light or make it ACTIVE
* use function parameter `zone` with value '0' to target ALL zones,
* value '1' for zone 1, value '2' for zone 2,... to 4
* You can also use this command to link your bulbs
* Prepend this command once for the appropriate zone to activate the zone
* before using hue() / brightness() / whiteMode() / effectModeNext()
*/
ColorRgbwCmd.prototype.on = function(zone)
{ return [[0x42,0x45,0x47,0x49,0x4B][zone],0x00,0x55] };
/* use function parameter `zone` with value '0' to target ALL zones,
* value '1' for zone 1, value '2' for zone 2,... to 4 */
ColorRgbwCmd.prototype.off = function(zone)
{ return [[0x41,0x46,0x48,0x4A,0x4C][zone],0x00,0x55] };
/* Shortcut to ON(0) */
ColorRgbwCmd.prototype.allOn = function(){ this.on(0) };
ColorRgbwCmd.prototype.allOff = function(){ this.off(0) };
/* Hue range 0-255 [targets last ON() activated bulb(s)] */
ColorRgbwCmd.prototype.hue = function(decimal)
{
var hex = decimal.toString(16);
hex = (hex.length < 2) ? '0x0'+hex : '0x'+hex;
return [0x40,hex,0x55];
}
/* Switch to white mode [targets last ON() activated bulb(s)] */
ColorRgbwCmd.prototype.whiteMode = function(){ return [0xC2,00,0x55] };
/* Brightness range 1-100 [targets last ON() activated bulb(s)]*/
ColorRgbwCmd.prototype.brightness = function(percent)
{ brightnessIndex = Math.max( 0,(Math.ceil(percent/100*19))-1 ); //19 steps
return [ 0x4E
,[ 0x02,0x03,0x04,0x05,0x08,0x09
,0x0A,0x0B,0x0D,0x0E,0x0F,0x10,0x11
,0x12,0x13,0x14,0x15,0x17,0x18,0x19][brightnessIndex]
, 0x55
];
};
/* Effect mode next [targets last ON() activated bulb(s)] */
ColorRgbwCmd.prototype.effectModeNext = function(){ return [0x4D,0x00,0x55] };
ColorRgbwCmd.prototype.effectSpeedUp = function(){ return [0x44,0x00,0x55] };
ColorRgbwCmd.prototype.effectSpeedDown= function(){ return [0x44,0x00,0x55] };
/* DUAL WHITE BULBS & CONTROLLERS */
/* Switch ON() your light or make it ACTIVE
* use function parameter `zone` with value '0' to target ALL zones,
* value '1' for zone 1, value '2' for zone 2,... to 4
* You can also use this command to link your bulbs
* Prepend this command once for the appropriate zone to activate the zone
* before using brightUp() / brightDown() / warmer() / cooler() */
WhiteCmd.prototype.on = function(zone){ return [[0x45, 0x38,0x3D,0x37,0x32][zone],0x00,0x55]; };
/* Switch OFF zone with value '0' to target ALL zones,
* , value '1' for zone 1, value '2' for zone 2,... to 4 */
WhiteCmd.prototype.off = function(zone)
{ return [[0x39, 0x3B,0x33,0x3A,0x36][zone],0x00,0x55]; };
/* Switch zone to Night Light Mode with value '0' to target ALL zones,
* , value '1' for zone 1, value '2' for zone 2,... to 4 */
WhiteCmd.prototype.nightMode = function(zone)
{ return [[0xB9, 0x3B,0x33,0x3A,0x36][index],0x00,0x55]; };
WhiteCmd.prototype.allOn = function(){ return [0x45,0x00,0x55] };
WhiteCmd.prototype.allOff = function(){ return [0x39,0x00,0x55] };
WhiteCmd.prototype.brightUp = function(){ return [0x3c,0x00,0x55] };
WhiteCmd.prototype.brightDown = function(){ return [0x34,0x00,0x55] };
WhiteCmd.prototype.warmer = function(){ return [0x3E,0x00,0x55] };
WhiteCmd.prototype.cooler = function(){ return [0x3F,0x00,0x55] };
/* RGB BULBS & CONTROLLERS, PREVIOUS GNERATION SINGLE CHANNEL/ZONE*/
ColorRgbCmd.prototype.off = function(){ return [0x21,0x00,0x55] };
ColorRgbCmd.prototype.on = function(){ return [0x22,0x00,0x55] };
ColorRgbCmd.prototype.hue = function(decimal)
{
var hex = decimal.toString(16);
hex = (hex.length < 2) ? '0x0'+hex : '0x'+hex;
return [0x20,hex,0x55];
};
ColorRgbCmd.prototype.brightUp = function(){ return [0x23,0x00,0x55] };
ColorRgbCmd.prototype.brightDown = function(){ return [0x24,0x00,0x55] };
ColorRgbCmd.prototype.speedUp = function(){ return [0x25,0x00,0x55] };
ColorRgbCmd.prototype.speedDown = function(){ return [0x26,0x00,0x55] };
ColorRgbCmd.prototype.effectSpeedUp = function(){ return [0x27,0x00,0x55] };
ColorRgbCmd.prototype.effectSpeedDown = function(){ return [0x28,0x00,0x55] };
/**
Filename: wifibox.js
//AppLamp.nl Wifi LED light API: wifi box UDP socket, command sender
© AppLamp.nl: you can share,modify and use this code (commercially) as long as you
keep the referer "AppLamp.nl led light API" in the file header.
Usage in Node JS:
//load this wifi box class
var WifiBoxModule = require('wifibox.js');
var cmd = require('commands.js');
//create instance with wifi box ip and port
var box = new WifiBoxModule("192.168.1.255", 8899);
//send a command ( see commands.js )
box.command(cmd.rgbw.hue(180));
box.command(cmd.white.allOn());
TIP: You don't need to know the exact IP of your Wifi Box.
If you know your DHCP IP range, just replace the last digit to .255
That way you wil perform a UDP multicast and the wifi box will receive it.
So for example your network range is 192.168.1.1 to 192.18.1.254,
then use 192.18.1.255 to perform a multicast.
**/
var http = require('http');
var dgram = require('dgram');
var WifiBox = function (ip, port) {
this.client = dgram.createSocket('udp4');
const default_ip = '192.168.1.255';
const default_port = 8899;
this.ip = (ip != undefined && ip.length > 6) ? ip : default_ip;
this.port = (port != undefined && port > 0) ? port : default_port;
};
WifiBox.prototype.command = function (threeByteArray) {
var buffer = new Buffer(threeByteArray);
this.client.send(buffer
, 0
, buffer.length
, this.port
, this.ip
, function (err, bytes) {
if (err) {
console.log("udp error:" + err);
throw err;
} else {
console.log('bytes send: ' + [threeByteArray[0], threeByteArray[1], threeByteArray[2]])
}
}
);
}
WifiBox.prototype.toString = function () {
return 'WifiBox: { ip:' + this.ip + ':' + this.port + '}';
};
module.exports = WifiBox;At the end of the day however, the 'Wink Hub" is still just another commercial gadget in an already crowded marketplace of incompatible "smart things". So I think this ever growing list of "cloud enabled smart appliance hubs" only confirms the original thesis of this thread, that a platform like NodeRED can be used to simplify the connections between devices that might use diverse communication protocols to control them. In other words, a light bulb is still a light bulb. Whether or not the light (or color) is controlled from a Zigbee, Bluetooth or RF24 gateway needs to be less relevant if the IOT is ever going be more relevant.
--
http://nodered.org
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/NSS5ooJ23H8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
to turn all RGBW COLOR LimitlessLED Smart lights to ON then send the TCP/IP UDP packet of: 0x42 0x00 0x55