Created
March 23, 2014 09:41
-
-
Save nulltask/9720821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Receiver = require('osc-receiver'); | |
var receiver = new Receiver(); | |
var request = require('request'); | |
receiver.bind(7400); | |
var entryPoint = { | |
'1': [ | |
'http://192.168.1.55/api/2d97dc9dc077ee74b888591c60a503/lights/1/state', | |
'http://192.168.1.133/api/e763d4c233b358f2a21b92411d51d27/lights/1/state', | |
'http://192.168.1.146/api/2f864eba2d6e46f71034dc2635e28413/lights/1/state', | |
'http://192.168.1.156/api/69999532ac25aaf5b7304b31a33627/lights/1/state', | |
// 'http://192.168.1.210/api/2974c2335e9458fb80bd2b2484507/lights/1/state' | |
], | |
'2': [ | |
'http://192.168.1.55/api/2d97dc9dc077ee74b888591c60a503/lights/2/state', | |
'http://192.168.1.133/api/e763d4c233b358f2a21b92411d51d27/lights/2/state', | |
'http://192.168.1.146/api/2f864eba2d6e46f71034dc2635e28413/lights/2/state', | |
'http://192.168.1.156/api/69999532ac25aaf5b7304b31a33627/lights/2/state', | |
// 'http://192.168.1.210/api/2974c2335e9458fb80bd2b2484507/lights/2/state' | |
], | |
'3': [ | |
'http://192.168.1.55/api/2d97dc9dc077ee74b888591c60a503/lights/3/state', | |
'http://192.168.1.133/api/e763d4c233b358f2a21b92411d51d27/lights/3/state', | |
'http://192.168.1.146/api/2f864eba2d6e46f71034dc2635e28413/lights/3/state', | |
'http://192.168.1.156/api/69999532ac25aaf5b7304b31a33627/lights/3/state', | |
// 'http://192.168.1.210/api/2974c2335e9458fb80bd2b2484507/lights/3/state' | |
], | |
'4': [ | |
// 'http://192.168.1.55/api/2d97dc9dc077ee74b888591c60a503/lights/4/state', | |
// 'http://192.168.1.133/api/e763d4c233b358f2a21b92411d51d27/lights/4/state', | |
// 'http://192.168.1.146/api/2f864eba2d6e46f71034dc2635e28413/lights/4/state', | |
// 'http://192.168.1.156/api/69999532ac25aaf5b7304b31a33627/lights/4/state', | |
'http://192.168.1.210/api/2974c2335e9458fb80bd2b2484507/lights/4/state' | |
], | |
'5': [ | |
// 'http://192.168.1.55/api/2d97dc9dc077ee74b888591c60a503/lights/5/state', | |
// 'http://192.168.1.133/api/e763d4c233b358f2a21b92411d51d27/lights/5/state', | |
// 'http://192.168.1.146/api/2f864eba2d6e46f71034dc2635e28413/lights/5/state', | |
// 'http://192.168.1.156/api/69999532ac25aaf5b7304b31a33627/lights/5/state', | |
'http://192.168.1.210/api/2974c2335e9458fb80bd2b2484507/lights/5/state' | |
], | |
'6': [ | |
// 'http://192.168.1.55/api/2d97dc9dc077ee74b888591c60a503/lights/6/state', | |
// 'http://192.168.1.133/api/e763d4c233b358f2a21b92411d51d27/lights/6/state', | |
// 'http://192.168.1.146/api/2f864eba2d6e46f71034dc2635e28413/lights/6/state', | |
// 'http://192.168.1.156/api/69999532ac25aaf5b7304b31a33627/lights/6/state', | |
'http://192.168.1.210/api/2974c2335e9458fb80bd2b2484507/lights/6/state' | |
] | |
}; | |
// 192.168.1.55 : 2d97dc9dc077ee74b888591c60a503 | |
// 192.168.1.133 : e763d4c233b358f2a21b92411d51d27 | |
// 192.168.1.146 : 2f864eba2d6e46f71034dc2635e28413 | |
// 192.168.1.156 : 69999532ac25aaf5b7304b31a33627 | |
// 192.168.1.210 : 2974c2335e9458fb80bd2b2484507 | |
var ttime = 0; | |
var bri; | |
receiver.on('message', function(path) { | |
var msg = path.split('/'); | |
var args = Array.prototype.slice.call(arguments, 1); | |
var id = msg.shift(); | |
var id = msg.shift(); | |
var urls = entryPoint[id]; | |
console.log(id, urls, msg[0]); | |
switch (msg[0]) { | |
case 'on': | |
console.log(id, 'on', args); | |
urls.forEach(function(url) { | |
request.put(url, { json: { on: true, transitiontime: ttime } }); | |
}); | |
break; | |
case 'off': | |
console.log(id, 'off', args); | |
urls.forEach(function(url) { | |
request.put(url, { json: { on: false, transitiontime: ttime } }); | |
}); | |
break; | |
case 'hue': | |
console.log(id, 'hue', args); | |
urls.forEach(function(url) { | |
request.put(url, { json: { hue: args[0], transitiontime: args[1] || ttime } }); | |
}); | |
break; | |
case 'bri': | |
console.log('---', id, 'bri', args); | |
if (bri != args[0]) { | |
bri = args[0]; | |
urls.forEach(function(url) { | |
request.put(url, { json: { bri: args[0], transitiontime: args[1] || ttime } }); | |
}); | |
} | |
break; | |
case 'sat': | |
console.log(id, 'sat', args); | |
urls.forEach(function(url) { | |
request.put(url, { json: { sat: args[0], transitiontime: args[1] || ttime } }); | |
}); | |
break; | |
case 'xy': | |
console.log(id, 'xy', args); | |
urls.forEach(function(url) { | |
request.put(url, { json: { x: args[0], y: args[1], transitiontime: args[2] || ttime }}); | |
}); | |
break; | |
case 'ct': | |
console.log(id, 'ct', args); | |
urls.forEach(function(url) { | |
request.put(url, { json: { ct: args[0], transitiontime: ttime } }); | |
}); | |
break; | |
case 'alert': | |
console.log(id, 'alert', args); | |
urls.forEach(function(url) { | |
request.put(url, { json: { alert: args[0], transitiontime: ttime } }); | |
}); | |
break; | |
case 'effect': | |
console.log(id, 'effect', args); | |
urls.forEach(function(url) { | |
request.put(url, { json: { effect: args[0], transitiontime: ttime } }); | |
}) | |
break; | |
case 'transitiontime': | |
console.log('---', id, 'bri', args); | |
if (ttime != args[0]) { | |
console.log(id, 'bri', args); | |
ttime = args[0]; | |
urls.forEach(function(url) { | |
request.put(url, { json: { transitiontime: ttime } }); | |
}); | |
} | |
break; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment