Skip to content

Commit

Permalink
Merge branch 'gh-pages'
Browse files Browse the repository at this point in the history
  • Loading branch information
ArndBrugman committed Dec 13, 2015
2 parents 5359877 + 66fad60 commit ddc0069
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 129 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
upnp.html
/Docs/fonts
npm-debug.log

hueNode/huepiBridgeCache.json
Binary file added IP-ID-UsernameFlow.pptx
Binary file not shown.
61 changes: 34 additions & 27 deletions hueMediate/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<body>
<script type='text/javascript' >
var MyHue = new huepi();
MyHue.Username = '085efe879ee3ed83c04efc28a0da03d3';
// OBSOLETE! May not be set externally, comes from bridge when whitelisting! MyHue.Username = '085efe879ee3ed83c04efc28a0da03d3';
var HeartbeatInterval;
var HueImage = new Image();
HueImage.src = 'images/HUE.png';
Expand Down Expand Up @@ -143,9 +143,9 @@

function onResume() {
window.onresize();
ConnectMyHue();
ConnectToHueBridge();
HeartbeatInterval = setInterval(StatusHeartbeat, 2500);
StatusHeartbeat(); // Execute Immediate Too!
//StatusHeartbeat(); // Execute Immediate Too!
}

function onPause() {
Expand All @@ -162,35 +162,41 @@
$('#brightnessslider').val(MyHue.Lights[2].state.bri); // Get brightness of 2nd light for now...
$('#brightnessslider').slider('refresh');
DemoBehaviour();
}, function BridgetHeartbeatGetFailed() {
}, function BridgeGetDataFailed() {
$('#HUEStatus').text('StatusHeartbeat BridgeGet Failed');
onPause();
onResume();
setTimeout(function() {
onPause();
onResume();
}, 100);
});
}

// Check Cached Bridge IP
// Discover Bridge via Portal
// Check if UserName is Whitelisted (via HEUPI.BridgeGetData)
// if Not->Try to Create User
function ConnectMyHue() {
function ConnectToHueBridge() {
if (!localStorage.MyHueBridgeIP) { // No Cached BridgeIP?
$('#HUEStatus').text('Trying to Discover HUE Bridge via HUE Portal');
MyHue.PortalDiscoverLocalBridges().then(function GetBridgeConfig() {
MyHue.PortalDiscoverLocalBridges().then(function BridgesDiscovered() {
$('#HUEBridgeIP').text('Bridge IP: ' + MyHue.BridgeIP);
MyHue.BridgeGetData().then(function EnsureWhitelisting() {
if (!MyHue.BridgeUsernameWhitelisted) {
$('#HUEStatus').text('Please press connect button on the Hue Bridge');
MyHue.BridgeCreateUser().then(function ReReadBridgeConfiguration() {
MyHue.BridgeGetConfig().then(function BridgeConfigReceived() {
$('#HUEBridgeName').text('Bridge Name: ' +MyHue.BridgeName);
MyHue.BridgeGetData().then(function BridgeDataReceived() {
localStorage.MyHueBridgeIP = MyHue.BridgeIP; // Cache BridgeIP
$('#HUEStatus').text('Connected');
}, function UnableToRetreiveBridgeData() {
$('#HUEStatus').text('Please press connect button on the hue Bridge');
MyHue.BridgeCreateUser().then(function BridegeUserCreated() {
localStorage.MyHueBridgeIP = MyHue.BridgeIP; // Cache BridgeIP
$('#HUEStatus').text('Connected');
return;
}, function UnableToCreateUseronBridge() {
$('#HUEStatus').text('Unable to Create User on Bridge');
return ConnectMyHue();
$('#HUEStatus').text('.Please press connect button on the hue Bridge.');
return;
});
} else {
localStorage.MyHueBridgeIP = MyHue.BridgeIP; // Cache BridgeIP
}
}, function UnableToRetreiveBridgeConfiguration() {
});
}, function UnableToRetreiveBridgeConfig() {
$('#HUEStatus').text('Unable to Retreive Bridge Configuration');
return;
});
Expand All @@ -199,20 +205,21 @@
return;
});
} else {
$('#HUEStatus').text('Using Cached Bridge IP');
MyHue.BridgeIP = localStorage.MyHueBridgeIP;
$('#HUEBridgeIP').text('Cached Bridge IP: ' + MyHue.BridgeIP);
$('#HUEStatus').text('Using Cached Bridge IP');
MyHue.BridgeGetData().then(function CheckWhitelisting() {
if (MyHue.BridgeUsernameWhitelisted) {
return;
} else {
MyHue.BridgeGetConfig().then(function CachedBridgeConfigReceived() {
$('#HUEBridgeName').text('Bridge Name: ' +MyHue.BridgeName);
MyHue.BridgeGetData().then(function CachedBridgeDataReceived() {
$('#HUEStatus').text('Connected');
}, function UnableToRetreiveCachedBridgeData() {
delete localStorage.MyHueBridgeIP; // not Whitelisted anymore
$('#HUEStatus').text('Not found anymore');
$('#HUEStatus').text('Unable to Retreive Cached Bridge Data');
return;
}
}, function ErrorGettingCachedBridgeData() {
});
}, function UnableToRetreiveCachedBridgeConfig() {
delete localStorage.MyHueBridgeIP; // not found anymore
return;
$('#HUEStatus').text('Unable to Retreive Cached Bridge Configuration');
});
}
}
Expand Down
52 changes: 27 additions & 25 deletions hueNode/hueNode.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
var huepi = require('../huepi');

var MyHue = new huepi();
MyHue.Username = '085efe879ee3ed83c04efc28a0da03d3';
// OBSOLETE! May not be set externally, comes from bridge when whitelisting! MyHue.Username = '085efe879ee3ed83c04efc28a0da03d3';
var HeartbeatInterval;

ConnectMyHue();

function ConnectMyHue() {

console.log('Bridge IP: Trying to Discover hue Bridge via hue Portal');
MyHue.PortalDiscoverLocalBridges().then(function GetBridgeConfig() {
MyHue.BridgeGetData().then(function EnsureWhitelisting() {
console.log('hue Bridge IP: ' + MyHue.BridgeIP);
if (!MyHue.BridgeUsernameWhitelisted) {
console.log('Please press connect button on the hue Bridge');
MyHue.BridgeCreateUser().then(function ReReadBridgeConfiguration() {
return ConnectMyHue();
console.log('Discovering hue Bridge via hue Portal');
MyHue.PortalDiscoverLocalBridges().then(function BridgesDiscovered() {
console.log('Bridge IP: ' + MyHue.BridgeIP);
MyHue.BridgeGetConfig().then(function BridgeConfigReceived() {
console.log('Bridge ID: ' + MyHue.BridgeID);
console.log('Bridge Name: ' + MyHue.BridgeName);
MyHue.BridgeGetData().then(function BridgeDataReceived() {
console.log('Bridge Username: ' + MyHue.Username);
StartHeartbeat();
}, function UnableToRetreiveBridgeData() {
console.log('Please press connect button on the Bridge');
MyHue.BridgeCreateUser().then(function BridegeUserCreated() {
console.log('Bridge Username Created: ' + MyHue.Username);
StartHeartbeat();
}, function UnableToCreateUseronBridge() {
console.log('Unable to Create User on hue Bridge');
console.log('.Please press connect button on the Bridge.');
setTimeout(ConnectMyHue, 1000);
});
} else {
StartHeartbeat();
}
});
}, function UnableToRetreiveBridgeConfiguration() {
console.log('Unable to Retreive hue Bridge Configuration');
return ConnectMyHue();
console.log('Unable to Retreive Bridge Configuration');
setTimeout(ConnectMyHue, 1000);
});
}, function UnableToDiscoverLocalBridgesViaPortal() {
console.log('Unable to find Local hue Bridge via hue Portal');
return ConnectMyHue();
console.log('Unable to find Local Bridge via hue Portal');
setTimeout(ConnectMyHue, 3000);
});
}

function StartHeartbeat() {

console.log('hue Bridge Name: ' + MyHue.BridgeName);
console.log('Found hue Bridge and Whitelisted');
//MyHue.GroupOn(0);
//MyHue.GroupEffectNone(0);
HeartbeatInterval = setInterval(StatusHeartbeat, 1000);
StatusHeartbeat(); // Execute Immediate Too!
MyHue.GroupAlertSelect(0);
HeartbeatInterval = setInterval(StatusHeartbeat, 2500);
//StatusHeartbeat(); // Execute Immediate Too!
}

function StatusHeartbeat() {
Expand All @@ -65,14 +67,14 @@ function StatusHeartbeat() {
}

function onLightSwitchOn(LightNr) {
console.log('LightSwitch ' +LightNr+ ' On -' +MyHue.Lights[LightNr].name);
console.log('LightSwitch ' +LightNr+ ' On - ' +MyHue.Lights[LightNr].name);
MyHue.GroupOn(0);
MyHue.GroupSetCT(0, 467);
MyHue.GroupSetBrightness(0, 144);
}

function onLightSwitchOff(LightNr) {
console.log('LightSwitch ' +LightNr+ ' Off -' +MyHue.Lights[LightNr].name);
console.log('LightSwitch ' +LightNr+ ' Off - ' +MyHue.Lights[LightNr].name);
MyHue.GroupOff(0);
}

Loading

0 comments on commit ddc0069

Please sign in to comment.