-
Notifications
You must be signed in to change notification settings - Fork 3
/
philipshue.htm
37 lines (27 loc) · 997 Bytes
/
philipshue.htm
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
<html>
<body>
<head><meta name="viewport" content="width=device-width, initial-scale=1.0"></head>
<header><button id="scanBtn" class="btn-scan">Scan</button></header>
<main style="display: none;"><pre id="output"></pre></main>
<button id="shot">change light</button>
<input type="number" value="1" min=0>
<script>
var bridge="http://localhost:8000/api/newdeveloper" //edit here
bridge=prompt("change bridge adress", bridge)||bridge
var state=true //bd={on:true}
var but=document.querySelector('#shot')
but.onclick=function(){
var path="lights/"+document.querySelector('input').value+"/state"
state=!state
bd={on:state}
var xhr = new XMLHttpRequest();
xhr.open("PUT", bridge+"/"+path)
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function() {console.log(xhr.responseText);}
xhr.onerror = function(e) {console.log(e.type)} //
xhr.send(JSON.stringify(bd))
}
</script>
<script src="webapp.bundle.js"></script>
</body>
</html>