-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.html
74 lines (67 loc) · 1.46 KB
/
admin.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PICALA for Admin</title>
</head>
<body>
<h1>PICALA for Admin</h1>
<script src="jquery-1.11.1.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
//====== ユーザ毎の設定項目 ======
var ip = "192.168.3.15"; //hueブリッジのIPアドレス
var user = "newdeveloper"; //hue APIのユーザ名
var interval = 5000; //hueの点灯時間[msec]
//=============================
var socket = io();
var num = 1;
var url = "";
var timer1,timer2,timer3;
var timers = [timer1,timer2,timer3];
socket.on('type', function(type){
url = "http://"+ip+"/api/"+user+"/lights/"+num+"/state";
turnOn(url,type);
turnOff(url,num);
num = num + 1;
if (num == 4) {num = 1};
console.log(num);
});
function putHue(url,data){
$.ajax({
type: "PUT",
url: url,
data: data,
dataType: "json"
});
}
function turnOn(u,t){
switch(t) {
case "hee":
hue = 10000;
break;
case "great":
hue = 65535;
break;
case "www":
hue = 25500;
break;
case "question":
hue = 47000;
break;
default:
break;
}
d ={"on":true,"sat":255,"bri":255,"hue":hue};
putHue(u,JSON.stringify(d));
}
function turnOff(u,i){
if (timers[i-1] !== null){
clearTimeout(timers[i-1]);
}
d ={"on":true,"sat":0,"bri":0,"hue":0};
timers[i-1] = setTimeout(putHue,interval,u,JSON.stringify(d));
}
</script>
</body>
</html>