-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
86 lines (64 loc) · 2.88 KB
/
index.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
75
76
77
78
79
80
81
82
83
<html>
<head>
<!-- located in /public folder, made accessible by server.js : style sheet + jQuery for client-side -->
<link type="text/css" rel="stylesheet" href="css/stylesheet.css" />
<script src="js/jquery.min.js"></script>
<!-- javascript for updating client browser after Pi sends msg & jQuery for posting to Pi open command -->
<script>
var host = location.origin.replace(/^http/, 'ws')
var ws = new WebSocket(host);
//after Pi sends message to server, server sends notification to browser (updates html with when notification was sent + updates Pi pic)
ws.onmessage = function (event) {
// Refresh image by tagging new time
d = new Date();
$("#timestamp").text( "Last visit on: " + event.data );
$("#securityimage").attr('src', 'http://136.152.38.74:5000/visitor.jpg?' + d.getTime() );
};
// get browser input and post to Pi
jQuery(function($){
// Owner wants to open door -- button pressed
$( "#opendoor" ).click(function() {
var data = {"open_door":"1"};
// AJAX does not like cross domain; need to add to server permission
// See http://stackoverflow.com/questions/18310394/no-access-control-allow-origin-node-apache-port-issue
$.ajax({
url: "http://136.152.38.74:5000/", // Pi IP
type: 'POST',
contentType:'application/json', // JSON data structure
data: JSON.stringify(data),
dataType:'json'
});
console.log("Door should open!");
});
// Owner wants to open door -- button pressed
$( "#closedoor" ).click(function() {
var data = {"open_door":"0"};
$.ajax({
url: "http://136.152.38.74:5000/", // Pi IP
type: 'POST',
contentType:'application/json', // JSON data structure
data: JSON.stringify(data),
dataType:'json'
});
console.log("Door should close!");
});
});
</script>
</head>
<body>
<!-- Initially, no visitors + default photo -->
<div align="center">
<br><br>
<img id="securityimage" class="rounded-image" src="http://136.152.38.74:5000/visitor.jpg" height="400" width="600">
<br><br>
<div id="timestamp" class="notification-text">No new visitors recently!</div>
<br>
<!-- Buttons for locking/unlocking door (Kodama head turns left/right_-->
<div class="notification-text">Kodama Head Direction</div>
<br>
<div class="round-button"><div class="round-button-circle"><a href="#" class="round-button" id='opendoor'>Left</a></div></div>
<br>
<div class="round-button"><div class="round-button-circle"><a href="#" class="round-button" id='closedoor'>Right</a></div></div>
</div>
</body>
</html>