-
Notifications
You must be signed in to change notification settings - Fork 1
/
web_server.js
74 lines (55 loc) · 1.62 KB
/
web_server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var aurora = require('./aurora.js');
// var lifxAdapter = require('./lifx_adapter.js');
var nodeLifxAdapter = require('./node_lifx_adapter.js');
// var lifx = require('lifx');
var LifxClient = require('node-lifx').Client;
var express = require('express');
var client = new LifxClient();
var lights = [];
client.on('light-new', function(light) {
// Change light state here
console.log(light.id);
// lights[light.id] = light;
// hue 0 360
// Saturation 0 100
// brightness 0 100
// kelvin 2500 900
var hue = Math.round(Math.random() * 360);
var saturation = 100;
var brightness = 100;
var kelvin = 2500;
var duration = 1000;
console.log(hue);
// light.color(hue, saturation, brightness, kelvin, duration);
light.color(0, 100, 50);
});
client.init();
var app = express();
// var lx = lifx.init();
// var lightsAdapter = new lifxAdapter(lx);
var lightsAdapter = new nodeLifxAdapter(client);
var au = new aurora(lightsAdapter);
app.use(express.static('public'));
app.get('/', function (req, res) {
res.sendfile('public/index.html');
});
app.get('/lights/all/on', function (req, res) {
console.log('/lights/all/on');
au.turnOn();
res.send('');
});
app.get('/lights/all/off', function (req, res) {
console.log('/lights/all/off');
au.turnOff();
res.send('');
});
app.get('/test/sunrise', function (req, res) {
console.log('/test/sunrise');
au.sunrise();
res.send('');
});
var server = app.listen(8080, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening on port ', port);
});