-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
182 lines (167 loc) · 6.74 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html lang="en">
<head>
<title> Smart Oil Lamp </title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="custom.css">
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js" type="text/javascript"></script>
<script>
$(function(){
client = new Paho.MQTT.Client("wss://iot.eclipse.org:443/ws", String(Math.random()));
console.log( "document loaded" );
// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
// connect the client
client.connect({onSuccess:onConnect});
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
console.log("onConnect");
message = new Paho.MQTT.Message("S");
message.destinationName = "lampin359";
client.send(message);
client.subscribe("lampout359");
}
// called when the client loses its connection
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("onConnectionLost:"+responseObject.errorMessage);
}
}
// called when a message arrives
function onMessageArrived(message) {
console.log("onMessageArrived:"+message.payloadString);
//alert(message.payloadString);
if (message.payloadString.split(" ")[0] == "R"){
$('#loading').fadeOut('1000');
$('#cntr').fadeIn('1000');
console.log("message from the lamp:"+message.payloadString);
if (message.payloadString.split(" ")[1] == "1"){
document.getElementById("L1").disabled = true;
}
if (message.payloadString.split(" ")[2] == "1"){
document.getElementById("L2").disabled = true;
}
if (message.payloadString.split(" ")[3] == "1"){
document.getElementById("L3").disabled = true;
}
if (message.payloadString.split(" ")[4] == "1"){
document.getElementById("L4").disabled = true;
}
if (message.payloadString.split(" ")[5] == "1"){
document.getElementById("L5").disabled = true;
}
}
if (message.payloadString == "1ok"){
console.log("message from the lamp:"+message.payloadString);
document.getElementById("L1").disabled = true;
}
if (message.payloadString == "2ok"){
console.log("message from the lamp:"+message.payloadString);
document.getElementById("L2").disabled = true;
}
if (message.payloadString == "3ok"){
console.log("message from the lamp:"+message.payloadString);
document.getElementById("L3").disabled = true;
}
if (message.payloadString == "4ok"){
console.log("message from the lamp:"+message.payloadString);
document.getElementById("L4").disabled = true;
}
if (message.payloadString == "5ok"){
console.log("message from the lamp:"+message.payloadString);
document.getElementById("L5").disabled = true;
}
}
$('#L1').click(function() {
// Once a connection has been made, make a subscription and send a message.
console.log("Button1Press");
$('.thankyou').fadeIn('500');
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
message = new Paho.MQTT.Message("1");
message.destinationName = "lampin359";
client.send(message);
});
$('#L2').click(function() {
// Once a connection has been made, make a subscription and send a message.
console.log("ButtonPress2");
$('.thankyou').fadeIn('500');
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
message = new Paho.MQTT.Message("2");
message.destinationName = "lampin359";
client.send(message);
});
$('#L3').click(function() {
// Once a connection has been made, make a subscription and send a message.
console.log("ButtonPress3");
$('.thankyou').fadeIn('500');
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
message = new Paho.MQTT.Message("3");
message.destinationName = "lampin359";
client.send(message);
});
$('#L4').click(function() {
// Once a connection has been made, make a subscription and send a message.
console.log("ButtonPress4");
$('.thankyou').fadeIn('500');
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
message = new Paho.MQTT.Message("4");
message.destinationName = "lampin359";
client.send(message);
});
$('#L5').click(function() {
// Once a connection has been made, make a subscription and send a message.
console.log("ButtonPress5");
$('.thankyou').fadeIn('500');
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
message = new Paho.MQTT.Message("5");
message.destinationName = "lampin359";
client.send(message);
});
});
</script>
</head>
<body>
<div id="player">
<audio autoplay hidden>
<source src="bgmusic.mp3" type="audio/mpeg" >
</audio>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<center>
<div id="cntr" style="display: none;">
<h1 style="color:white;" ><b> Smart Oil Lamp </b></h1>
<br>
<p style="color:white;" > Please click a button to light the oil lamp </p>
<br>
<button id="L1" class="btn btn-warning"> Lamp 1 </button>
<button id="L2" class="btn btn-warning"> Lamp 2 </button>
<button id="L3" class="btn btn-warning"> Lamp 3 </button>
<button id="L4" class="btn btn-warning"> Lamp 4 </button>
<button id="L5" class="btn btn-warning"> Lamp 5 </button>
</div>
<h1 class="display-2 thankyou" style="color:white; font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol'; font-weight: lighter; display: none;" > Thank you..!</h1>
<div id="loading">
<ul class="bokeh">
<li></li>
<li></li>
<li></li>
</ul>
<h1 class="display-2" style="color:white; font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol'; font-weight: lighter;" > Please wait until the lamp is switched on...</h1>
</div>
</center>
</body>
</html>