From dfa9c9df1c1427729341eadc74cf36ad2ed0317f Mon Sep 17 00:00:00 2001 From: Kevin Coleman Date: Mon, 10 Nov 2014 22:14:28 -0800 Subject: [PATCH 01/12] fixed typo --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 21ec594..4a06563 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,7 @@ TCPConnected.prototype.GetState = function (cb){ xml(b, function (error, result) { // Need to add validation to make sure that Rooms is proper or else result error console.log(result); - if(typeof(results["gip"]) !== 'undefined'){ + if(typeof(result["gip"]) !== 'undefined'){ error = 1; }else{ Rooms = result['gwrcmd']['gdata']['gip']['room']; From 9716a2a5e9fc9003b96c1b2791ce4fd244e47c5e Mon Sep 17 00:00:00 2001 From: Kevin Coleman Date: Mon, 10 Nov 2014 22:15:06 -0800 Subject: [PATCH 02/12] a script to emulate sunrise --- sunrise.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 sunrise.js diff --git a/sunrise.js b/sunrise.js new file mode 100644 index 0000000..8df0a0e --- /dev/null +++ b/sunrise.js @@ -0,0 +1,43 @@ +// requires & definitions +var TCPConnected = require('./index.js'); +Sunrise = new TCPConnected("10.0.1.35"); +var time = new Date(); +var level = 0; + +//user vars +var room = 'Bedroom'; +var fadeDuration = 30; + + + +// script +var updateFadeLevel = function() { + Sunrise.GetState(function(error,system){ + + // report status + Sunrise.GetRoomStateByName(room, function(error,state,level){ + console.log("State: " + state + " at Level: " + level); + }); + + // set bulb brightness + Sunrise.SetRoomLevelByName(room, level); + + // turn the light on if it’s switched off + if(state == 0){ + Sunrise.TurnOnRoomByName(room); + } + + // stop incrementing if they’re all the way on... + if (level >= 100) { + console.log('Lights are all the way on.'); + clearInterval(sunrise); + } else { + // ... or increment light level + level++; + } + + }); +} + +// run the script +var sunrise = setInterval(updateFadeLevel, (fadeDuration * 60)); \ No newline at end of file From b463964c19422b83d09a5631b1ea0a5903ea3e7c Mon Sep 17 00:00:00 2001 From: Kevin Coleman Date: Tue, 11 Nov 2014 00:09:14 -0800 Subject: [PATCH 03/12] updating time interval from testing to live increment --- sunrise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sunrise.js b/sunrise.js index 8df0a0e..61884ef 100644 --- a/sunrise.js +++ b/sunrise.js @@ -40,4 +40,4 @@ var updateFadeLevel = function() { } // run the script -var sunrise = setInterval(updateFadeLevel, (fadeDuration * 60)); \ No newline at end of file +var sunrise = setInterval(updateFadeLevel, (fadeDuration * 600)); \ No newline at end of file From 471a4fa32650b8df711bd169982efeea75ec646b Mon Sep 17 00:00:00 2001 From: Kevin Coleman Date: Sun, 25 Jan 2015 14:20:35 -0800 Subject: [PATCH 04/12] testing because of the TCP firmware update --- sunrise.js | 4 ++-- toggle.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sunrise.js b/sunrise.js index 61884ef..2481d08 100644 --- a/sunrise.js +++ b/sunrise.js @@ -1,6 +1,6 @@ // requires & definitions var TCPConnected = require('./index.js'); -Sunrise = new TCPConnected("10.0.1.35"); +Sunrise = new TCPConnected("10.0.1.3"); var time = new Date(); var level = 0; @@ -40,4 +40,4 @@ var updateFadeLevel = function() { } // run the script -var sunrise = setInterval(updateFadeLevel, (fadeDuration * 600)); \ No newline at end of file +var sunrise = setInterval(updateFadeLevel, (fadeDuration * 600)); diff --git a/toggle.js b/toggle.js index bc8e4ee..38562c9 100644 --- a/toggle.js +++ b/toggle.js @@ -1,9 +1,9 @@ var TCPConnected = require('./index.js'); -Test = new TCPConnected("192.168.1.137"); +Test = new TCPConnected("10.0.1.3"); Test.GetState(function(error,system){ - room = "Bathroom"; + room = "Bedroom"; Test.GetRoomStateByName(room, function(error,state,level){ console.log("State: " + state + " at Level: " + level); }); From 9065581ef058231a008bdf15aa095a050006ac84 Mon Sep 17 00:00:00 2001 From: Kevin Coleman Date: Mon, 26 Jan 2015 08:51:43 -0800 Subject: [PATCH 05/12] uses new TCP auth fix from stockmopar --- .gitignore | 1 + README.md | 8 ++ dimmer.js | 20 ---- index.js | 304 +++++++++++++++++++++++++++++++++---------------- loadtest.js.js | 17 --- package.json | 9 +- sunrise.js | 56 +++++---- toggle.js | 16 --- 8 files changed, 247 insertions(+), 184 deletions(-) delete mode 100644 dimmer.js delete mode 100644 loadtest.js.js delete mode 100644 toggle.js diff --git a/.gitignore b/.gitignore index 38e8316..d8ac884 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ +config.json ################# ## Eclipse diff --git a/README.md b/README.md index e5acd26..8cecdd0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ Connected by TCP Node.js Control ================================= +[![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NKVWX2AJRLDT2) + +Version 0.0.6: + +First release to support the new protocol with the gateway. + This contains an example which will turn off and on the lights in a room based on the name of the room. For more information see: @@ -9,6 +15,8 @@ http://home.stockmopar.com http://home.stockmopar.com/connected-by-tcp-unofficial-api +http://home.stockmopar.com/updated-connected-by-tcp-api/ + You can now install using npm package manager using the following command: ```sh npm install connectedbytcp diff --git a/dimmer.js b/dimmer.js deleted file mode 100644 index 6334718..0000000 --- a/dimmer.js +++ /dev/null @@ -1,20 +0,0 @@ -// This example will set the level for a room and if it was off turn it on. - -var TCPConnected = require('./index.js'); - -Test = new TCPConnected("192.168.1.137"); - -Test.GetState(function(error,system){ - room = "Basement"; - Test.GetRoomStateByName(room, function(error,state,level){ - console.log("State: " + state + " at Level: " + level); - }); - Test.SetRoomLevelByName(room, 50); - if(state == 0){ - Test.TurnOnRoomByName(room); - } - Test.GetRoomHueByName(room, function(error,hue){ - console.log("Hue: " + hue); - }); -}); - diff --git a/index.js b/index.js index 4a06563..8f1f7d5 100644 --- a/index.js +++ b/index.js @@ -1,79 +1,202 @@ var util = require('util'); -var request = require('request'); +var https = require('https'); var xml = require('libxml-to-js'); var EventEmitter = require('events').EventEmitter; +var nconf = require('nconf'); +var uuid = require('node-uuid'); module.exports = TCPConnected; var RequestString = 'cmd=%s&data=%s&fmt=xml'; -var GetStateString = ['RoomGetCarousel11234567890name,control,power,product,class,realtype,status'].join('\n'); -var RoomSendCommand = ['11234567890%s%s'].join('\n'); -var RoomSendLevelCommand = ['11234567890%s%slevel'].join('\n'); +var GetStateString = ['RoomGetCarousel1%sname,control,power,product,class,realtype,status'].join('\n'); + +var RoomSendCommand = ['1%s%s%s'].join('\n'); +var RoomSendLevelCommand = ['1%s%s%slevel'].join('\n'); + +var DeviceSendCommand = ['1%s%s%s'].join('\n'); +var DeviceSendLevelCommand = ['1%s%s%slevel'].join('\n'); + +var LogInCommand = ['1%s%s'].join('\n'); + var Rooms = []; +// needed to keep socket variable in scope +var tcpSocket = this; + function TCPConnected(host) { EventEmitter.call(this); - if (!host) throw new Error("Invalid Parameters to WeMo") + if (!host) throw new Error("Invalid Parameters to TCP Connected") this._host = host; + this._hasToken = 0; }; +TCPConnected.prototype.Init = function(cb){ + this.LoadToken(cb); +} +TCPConnected.prototype.GWEnd = function(){ + tcpSocket.end(); +} +TCPConnected.prototype.GWRequest = function(payload,cb){ + if(!this._hasToken){ + cb(1); + }else{ + var options = { + hostname: this._host, + port: 443, + path: '/gwr/gop.php', + method: 'POST', + headers:{ + 'Content-Type':'text/xml; charset="utf-8"', + 'Content-Length':payload.length + }, + rejectUnauthorized: false, + agent: false + }; -TCPConnected.prototype.GetState = function (cb){ - var payload = util.format(RequestString,'GWRBatch',encodeURIComponent(GetStateString)); - var opts = { - method:"POST", - body:payload, - headers:{ - 'Content-Type':'text/xml; charset="utf-8"', - 'Content-Length':payload.length - }, - uri:'http://'+this._host+'/gwr/gop.php', + tcpSocket = https.request(options, function(res) { + res.on('data', function(data){ + cb(data); + }); + }); + + tcpSocket.write(payload); + } +} +TCPConnected.prototype.SyncGateway = function(cb){ + var myuuid = uuid.v4(); + var username = myuuid; + var password = myuuid; + + var gLogInCommand = util.format(LogInCommand,username,password); + + var payload = util.format(RequestString,'GWRLogin',encodeURIComponent(gLogInCommand)); + var options = { + hostname: this._host, + port: 443, + path: '/gwr/gop.php', + method: 'POST', + headers:{ + 'Content-Type':'text/xml; charset="utf-8"', + 'Content-Length':payload.length + }, + rejectUnauthorized: false, + agent: false }; - request(opts,function(e,r,b) { - console.log(b); - xml(b, function (error, result) { - // Need to add validation to make sure that Rooms is proper or else result error - console.log(result); - if(typeof(result["gip"]) !== 'undefined'){ - error = 1; + tcpSocket = https.request(options, function(res) { + res.on('data', function(data){ + process.stdout.write(data); + if(data == "1404"){ + console.log("Permission Denied: Gateway Not In Sync Mode. Press Button on Gateway to Sync."); + cb(1); }else{ - Rooms = result['gwrcmd']['gdata']['gip']['room']; - if (typeof(Rooms["rid"]) !== 'undefined'){ - Rooms = [ Rooms ]; - } - } - //console.log(Rooms); - if (error) { - return cb(error); - } - try { - var state = result['s:Body']['u:GetBinaryStateResponse'].BinaryState - } catch (err) { - var error = {error:'Unkown Error'} + xml(data,function(error,result){ + if(result['token'] != undefined){ + this._token = result['token']; + nconf.use('file', { file: './config.json' }); + nconf.set('token', this._token); + nconf.save(function (err) { + if (err) { + console.error(err.message); + return; + } + console.log('Configuration saved successfully.'); + }); + cb(0); + } + }); } - cb(error||null,Rooms); }); }); + + tcpSocket.write(payload); +} +TCPConnected.prototype.LoadToken = function(cb){ + nconf.use('file', { file: './config.json' }); + nconf.load(); + if(nconf.get('token') != undefined){ + this._token = nconf.get('token'); + this._hasToken = 1; + cb(0); + }else{ + console.log("No Token Saved. Attempting to Connect With Gateway to Get Token."); + console.log("Button On Gateway Must Be Pressed Prior to This."); + this.SyncGateway(cb); + } +} +TCPConnected.prototype.GetState = function (cb){ + var StateString = util.format(GetStateString,this._token); + var payload = util.format(RequestString,'GWRBatch',encodeURIComponent(StateString)); + + this.GWRequest(payload,function(data){ + //process.stdout.write(data); + if(data == "1401"){ + console.log("Permission Denied: Invalid Token"); + }else{ + xml(data,function(error,result){ + //console.log(result); + if (error) { + cb(1); + return; + }else{ + if(typeof(result["gip"]) !== 'undefined'){ + error = 1; + }else{ + Rooms = result['gwrcmd']['gdata']['gip']['room']; + if (typeof(Rooms["rid"]) !== 'undefined'){ + Rooms = [ Rooms ]; + } + } + cb(error||null,Rooms); + } + }); + } + }); +} +TCPConnected.prototype.TurnOnDevice = function (did, cb){ + + var DeviceCommand = util.format(DeviceSendCommand,this._token,did,1); + var payload = util.format(RequestString,'DeviceSendCommand',encodeURIComponent(DeviceCommand)); + + this.GWRequest(payload,function(data){ + cb(0); + }); +} +TCPConnected.prototype.TurnOffDevice = function (did, cb){ + + var DeviceCommand = util.format(DeviceSendCommand,this._token,did,0); + var payload = util.format(RequestString,'DeviceSendCommand',encodeURIComponent(DeviceCommand)); + + this.GWRequest(payload,function(data){ + cb(0); + }); +} +TCPConnected.prototype.SetDeviceLevel = function (did, level, cb){ + var DeviceLevelCommand = util.format(DeviceSendLevelCommand,this._token,did,level); + var payload = util.format(RequestString,'DeviceSendCommand',encodeURIComponent(DeviceLevelCommand)); + + this.GWRequest(payload,function(data){ + cb(0); + }); } TCPConnected.prototype.GetRoomHueByName = function (name, cb){ - Rooms.forEach(function(room) { + Rooms.forEach(function(room) { if(room["name"] == name){ var color = room["color"]; - + var r = parseInt(color.substr(0,2), 16); // Grab the hex representation of red (chars 1-2) and convert to decimal (base 10). var g = parseInt(color.substr(2,2), 16); var b = parseInt(color.substr(4,2), 16); - + console.log(r + "." + g + "." + b); - + var hue = parseInt(rgb2hsv(r, g, b)["h"] * 182); - + cb(null,hue); } }); } TCPConnected.prototype.GetRoomStateByName = function (name, cb){ - Rooms.forEach(function(room) { + Rooms.forEach(function(room) { if(room["name"] == name){ state = 0; var i = 0; @@ -86,14 +209,14 @@ TCPConnected.prototype.GetRoomStateByName = function (name, cb){ sum = sum + parseInt(devices["level"]); } }else{ - devices.forEach(function(device) { + devices.forEach(function(device) { i = i+1; if(device["state"] != "0"){ state = 1; sum = sum + parseInt(device["level"]); } }); - + } if(i == 0){ sum = 0; @@ -107,78 +230,63 @@ TCPConnected.prototype.GetRoomStateByName = function (name, cb){ } TCPConnected.prototype.GetRIDByName = function (name){ var rid = 0; - //console.log(Rooms); Rooms.forEach(function(room) { - //console.log(room); if(room["name"] == name){ rid = room["rid"]; } }); - //console.log(rid); return rid; } +TCPConnected.prototype.TurnOnRoom = function (rid, cb){ -TCPConnected.prototype.TurnOnRoomByName = function (name){ - rid = this.GetRIDByName(name); - - var RoomCommand = util.format(RoomSendCommand,rid,1); + var RoomCommand = util.format(RoomSendCommand,this._token,rid,1); var payload = util.format(RequestString,'RoomSendCommand',encodeURIComponent(RoomCommand)); - var opts = { - method:"POST", - body:payload, - headers:{ - 'Content-Type':'text/xml; charset="utf-8"', - 'Content-Length':payload.length - }, - uri:'http://'+this._host+'/gwr/gop.php', - }; - - request(opts,function(e,r,b) { - // Request Complete + this.GWRequest(payload,function(data){ + cb(0); }); } -TCPConnected.prototype.TurnOffRoomByName = function (name, cb){ - console.log("Turn Off Room"); +TCPConnected.prototype.TurnOnRoomByName = function (name, cb){ rid = this.GetRIDByName(name); - - var RoomCommand = util.format(RoomSendCommand,rid,0); + + this.TurnOnRoom(rid,cb); +} + +TCPConnected.prototype.TurnOnRoomWithLevelByName = function (name,level, cb){ + var self = this; + rid = this.GetRIDByName(name); + + this.SetRoomLevel(rid,level,function(error){ + self.TurnOnRoom(rid,cb); + }); +} +TCPConnected.prototype.TurnOffRoom = function (rid, cb){ + var RoomCommand = util.format(RoomSendCommand,this._token,rid,0); var payload = util.format(RequestString,'RoomSendCommand',encodeURIComponent(RoomCommand)); - - var opts = { - method:"POST", - body:payload, - headers:{ - 'Content-Type':'text/xml; charset="utf-8"', - 'Content-Length':payload.length - }, - uri:'http://'+this._host+'/gwr/gop.php', - }; - - request(opts,function(e,r,b) { - // Request Complete + + this.GWRequest(payload,function(data){ + cb(0); }); + } -TCPConnected.prototype.SetRoomLevelByName = function (name, level, cb){ - console.log("Set Level of Room"); +TCPConnected.prototype.TurnOffRoomByName = function (name, cb){ rid = this.GetRIDByName(name); - - var RoomLevelCommand = util.format(RoomSendLevelCommand,rid,level); + + this.TurnOffRoom(rid,cb); +} +TCPConnected.prototype.SetRoomLevel = function (rid, level, cb){ + var RoomLevelCommand = util.format(RoomSendLevelCommand,this._token,rid,level); var payload = util.format(RequestString,'RoomSendCommand',encodeURIComponent(RoomLevelCommand)); - - var opts = { - method:"POST", - body:payload, - headers:{ - 'Content-Type':'text/xml; charset="utf-8"', - 'Content-Length':payload.length - }, - uri:'http://'+this._host+'/gwr/gop.php', - }; - - request(opts,function(e,r,b) { - // Request Complete + + this.GWRequest(payload,function(data){ + cb(0); }); + +} +TCPConnected.prototype.SetRoomLevelByName = function (name, level, cb){ + rid = this.GetRIDByName(name); + + this.SetRoomLevel(rid,level,cb); } function rgb2hsv () { @@ -219,4 +327,4 @@ function rgb2hsv () { s: Math.round(s * 100), v: Math.round(v * 100) }; -} \ No newline at end of file +} diff --git a/loadtest.js.js b/loadtest.js.js deleted file mode 100644 index e7f352d..0000000 --- a/loadtest.js.js +++ /dev/null @@ -1,17 +0,0 @@ -var TCPConnected = require('./index.js'); - -Test = new TCPConnected("192.168.1.137"); - - -var fetchState = function() { - console.log("Getting TCP Lights State"); - Test.GetState(function(error,system){ - system.forEach(function(room) { - Test.GetRoomStateByName(room["name"], function(error,state,level){ - console.log(room["name"] + " has state of " + state + " at level " + level); - }); - }); - setTimeout(fetchState,1000); - }); -}; -setTimeout(fetchState,500); \ No newline at end of file diff --git a/package.json b/package.json index 338cc42..65b51cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "connectedbytcp", - "version": "0.0.5", + "version": "0.0.6", "author": { "name": "stockmopar", "email": "git@stockmopar.com" @@ -8,11 +8,12 @@ "main": "connectedbytcp", "dependencies": { "util": "*", - "request": "*", "libxml-to-js": "*", - "events": "*" + "events": "*", + "nconf": "*", + "node-uuid": "*" }, "readmeFilename": "README.md", - "_id": "connectedbytcp@0.0.5", + "_id": "connectedbytcp@0.0.6", "description": "Connected by TCP client" } diff --git a/sunrise.js b/sunrise.js index 2481d08..5480a28 100644 --- a/sunrise.js +++ b/sunrise.js @@ -1,43 +1,41 @@ // requires & definitions var TCPConnected = require('./index.js'); Sunrise = new TCPConnected("10.0.1.3"); -var time = new Date(); -var level = 0; //user vars var room = 'Bedroom'; -var fadeDuration = 30; - - +var fadeDuration = 1; +var step = 4; +var sunrise; // script var updateFadeLevel = function() { Sunrise.GetState(function(error,system){ - - // report status - Sunrise.GetRoomStateByName(room, function(error,state,level){ - console.log("State: " + state + " at Level: " + level); - }); - - // set bulb brightness - Sunrise.SetRoomLevelByName(room, level); - - // turn the light on if it’s switched off - if(state == 0){ - Sunrise.TurnOnRoomByName(room); - } - - // stop incrementing if they’re all the way on... - if (level >= 100) { - console.log('Lights are all the way on.'); - clearInterval(sunrise); - } else { - // ... or increment light level - level++; - } - + Sunrise.GetRoomStateByName(room, function(error,state,level){ + if(state == 0){ + Sunrise.TurnOnRoomWithLevelByName(room, 1, function(){ + sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); + }); + }else{ + if (level >= 100) { + console.log('Lights are all the way on.'); + clearInterval(sunrise); + Sunrise.GWEnd(); + } else { + Sunrise.SetRoomLevelByName(room, Math.min(100,level+step), function(){ + sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); + } ); + } + } + }); }); } // run the script -var sunrise = setInterval(updateFadeLevel, (fadeDuration * 600)); +Sunrise.Init(function(error){ + if(!error){ + sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); + }else{ + console.log("There was an issue initializing the token"); + } +}); diff --git a/toggle.js b/toggle.js deleted file mode 100644 index 38562c9..0000000 --- a/toggle.js +++ /dev/null @@ -1,16 +0,0 @@ -var TCPConnected = require('./index.js'); - -Test = new TCPConnected("10.0.1.3"); - -Test.GetState(function(error,system){ - room = "Bedroom"; - Test.GetRoomStateByName(room, function(error,state,level){ - console.log("State: " + state + " at Level: " + level); - }); - if(state == 1){ - Test.TurnOffRoomByName(room); - }else{ - Test.TurnOnRoomByName(room); - } -}); - From 02919d337df4957358a24ce48de0daae7fd85635 Mon Sep 17 00:00:00 2001 From: kevincoleman Date: Mon, 26 Jan 2015 23:14:14 -0800 Subject: [PATCH 06/12] updated time to longer --- sunrise.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sunrise.js b/sunrise.js index 5480a28..92b3f09 100644 --- a/sunrise.js +++ b/sunrise.js @@ -4,8 +4,8 @@ Sunrise = new TCPConnected("10.0.1.3"); //user vars var room = 'Bedroom'; -var fadeDuration = 1; -var step = 4; +var fadeDuration = 30; +var step = 1; var sunrise; // script @@ -14,7 +14,7 @@ var updateFadeLevel = function() { Sunrise.GetRoomStateByName(room, function(error,state,level){ if(state == 0){ Sunrise.TurnOnRoomWithLevelByName(room, 1, function(){ - sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); + sunrise = setTimeout(updateFadeLevel, (fadeDuration * 600)); }); }else{ if (level >= 100) { @@ -23,7 +23,7 @@ var updateFadeLevel = function() { Sunrise.GWEnd(); } else { Sunrise.SetRoomLevelByName(room, Math.min(100,level+step), function(){ - sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); + sunrise = setTimeout(updateFadeLevel, (fadeDuration * 600)); } ); } } @@ -35,7 +35,7 @@ var updateFadeLevel = function() { Sunrise.Init(function(error){ if(!error){ sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); - }else{ + }else{c console.log("There was an issue initializing the token"); } }); From 2a1eec18d2853563bb27e7c30dbc2a9cf06078dd Mon Sep 17 00:00:00 2001 From: kevincoleman Date: Tue, 27 Jan 2015 16:25:32 -0800 Subject: [PATCH 07/12] returning numbers to functional --- sunrise.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sunrise.js b/sunrise.js index 92b3f09..adbfa77 100644 --- a/sunrise.js +++ b/sunrise.js @@ -14,7 +14,7 @@ var updateFadeLevel = function() { Sunrise.GetRoomStateByName(room, function(error,state,level){ if(state == 0){ Sunrise.TurnOnRoomWithLevelByName(room, 1, function(){ - sunrise = setTimeout(updateFadeLevel, (fadeDuration * 600)); + sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); }); }else{ if (level >= 100) { @@ -23,7 +23,7 @@ var updateFadeLevel = function() { Sunrise.GWEnd(); } else { Sunrise.SetRoomLevelByName(room, Math.min(100,level+step), function(){ - sunrise = setTimeout(updateFadeLevel, (fadeDuration * 600)); + sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); } ); } } @@ -35,7 +35,7 @@ var updateFadeLevel = function() { Sunrise.Init(function(error){ if(!error){ sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); - }else{c + }else{ console.log("There was an issue initializing the token"); } }); From 620b3ac4c6a4d025de0b75cf96a7dda55434558e Mon Sep 17 00:00:00 2001 From: kevincoleman Date: Wed, 28 Jan 2015 13:10:58 -0800 Subject: [PATCH 08/12] changed time multiplier --- sunrise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sunrise.js b/sunrise.js index adbfa77..e060e73 100644 --- a/sunrise.js +++ b/sunrise.js @@ -14,7 +14,7 @@ var updateFadeLevel = function() { Sunrise.GetRoomStateByName(room, function(error,state,level){ if(state == 0){ Sunrise.TurnOnRoomWithLevelByName(room, 1, function(){ - sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); + sunrise = setTimeout(updateFadeLevel, (fadeDuration * 600)); }); }else{ if (level >= 100) { @@ -23,7 +23,7 @@ var updateFadeLevel = function() { Sunrise.GWEnd(); } else { Sunrise.SetRoomLevelByName(room, Math.min(100,level+step), function(){ - sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); + sunrise = setTimeout(updateFadeLevel, (fadeDuration * 600)); } ); } } From c0c067f642595b05ddc9e4a1d6a79b49b6c4b2f6 Mon Sep 17 00:00:00 2001 From: kevincoleman Date: Thu, 29 Jan 2015 00:27:31 -0800 Subject: [PATCH 09/12] testing time increment --- sunrise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sunrise.js b/sunrise.js index e060e73..adbfa77 100644 --- a/sunrise.js +++ b/sunrise.js @@ -14,7 +14,7 @@ var updateFadeLevel = function() { Sunrise.GetRoomStateByName(room, function(error,state,level){ if(state == 0){ Sunrise.TurnOnRoomWithLevelByName(room, 1, function(){ - sunrise = setTimeout(updateFadeLevel, (fadeDuration * 600)); + sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); }); }else{ if (level >= 100) { @@ -23,7 +23,7 @@ var updateFadeLevel = function() { Sunrise.GWEnd(); } else { Sunrise.SetRoomLevelByName(room, Math.min(100,level+step), function(){ - sunrise = setTimeout(updateFadeLevel, (fadeDuration * 600)); + sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); } ); } } From 85ca5af27d811441e47eaf037fa09d1889a8e627 Mon Sep 17 00:00:00 2001 From: kevincoleman Date: Sat, 31 Jan 2015 14:30:25 -0800 Subject: [PATCH 10/12] increasing step interval --- sunrise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sunrise.js b/sunrise.js index adbfa77..c249eef 100644 --- a/sunrise.js +++ b/sunrise.js @@ -5,7 +5,7 @@ Sunrise = new TCPConnected("10.0.1.3"); //user vars var room = 'Bedroom'; var fadeDuration = 30; -var step = 1; +var step = 4; var sunrise; // script From 90da19801a0da4fb45bdf28f78f3d6ba504f74ac Mon Sep 17 00:00:00 2001 From: kevincoleman Date: Mon, 2 Feb 2015 00:07:08 -0800 Subject: [PATCH 11/12] created fadeIncrement to handle math in one place; reduced step to 1% for smoother sunrise; added minutesOfSunrise for easier user input (in minutes) --- sunrise.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) mode change 100644 => 100755 sunrise.js diff --git a/sunrise.js b/sunrise.js old mode 100644 new mode 100755 index c249eef..c01af48 --- a/sunrise.js +++ b/sunrise.js @@ -4,8 +4,9 @@ Sunrise = new TCPConnected("10.0.1.3"); //user vars var room = 'Bedroom'; -var fadeDuration = 30; -var step = 4; +var minutesOfSunrise = 30; // set your duration here, in human minutes. +var fadeIncrement = minutesOfSunrise * 600; +var step = 1; var sunrise; // script @@ -14,7 +15,7 @@ var updateFadeLevel = function() { Sunrise.GetRoomStateByName(room, function(error,state,level){ if(state == 0){ Sunrise.TurnOnRoomWithLevelByName(room, 1, function(){ - sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); + sunrise = setTimeout(updateFadeLevel, (fadeIncrement)); }); }else{ if (level >= 100) { @@ -23,7 +24,7 @@ var updateFadeLevel = function() { Sunrise.GWEnd(); } else { Sunrise.SetRoomLevelByName(room, Math.min(100,level+step), function(){ - sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); + sunrise = setTimeout(updateFadeLevel, (fadeIncrement)); } ); } } @@ -34,7 +35,7 @@ var updateFadeLevel = function() { // run the script Sunrise.Init(function(error){ if(!error){ - sunrise = setTimeout(updateFadeLevel, (fadeDuration * 60)); + sunrise = setTimeout(updateFadeLevel, fadeIncrement); }else{ console.log("There was an issue initializing the token"); } From 578546bd39f3e5986b247ec42f18856f93fcd4a9 Mon Sep 17 00:00:00 2001 From: kevincoleman Date: Fri, 27 Feb 2015 13:20:08 -0800 Subject: [PATCH 12/12] adding toggle.js for testing --- toggle.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 toggle.js diff --git a/toggle.js b/toggle.js new file mode 100644 index 0000000..f9c3b5f --- /dev/null +++ b/toggle.js @@ -0,0 +1,25 @@ +var TCPConnected = require('./index.js'); + +Test = new TCPConnected("10.0.1.3"); + +Test.Init(function(error){ + if(!error){ + Test.GetState(function(error,system){ + room = "Bedroom"; + Test.GetRoomStateByName(room, function(error,state,level){ + console.log("State: " + state + " at Level: " + level); + }); + if(state == 1){ + Test.TurnOffRoomByName(room, function(error){ + Test.GWEnd(); + }); + }else{ + Test.TurnOnRoomByName(room, function(error){ + Test.GWEnd(); + }); + } + }); + }else{ + console.log("There was an issue initializing the token"); + } +});