-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.html
136 lines (109 loc) · 3.83 KB
/
Test.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
<!DOCTYPE html>
<html>
<head>
<style>
body {
display: block;
margin: 8px;
}
#content{
width:98%;
margin:auto;
margin-top:20px;
margin-left:auto;
margin-right:auto;
margin-bottom:auto;
border-radius: 15px;
border: 5px solid orange;
padding-bottom: 55px;
}
#Button{
width:auto;
margin:auto;
margin-top:10px;
margin-left:auto;
margin-right:auto;
margin-bottom:10px;
font-size:200%;
color:blue;
border-radius: 13px;
border: 2px solid orange;
transition-duration: 0.4s;
cursor: pointer;
display: flex;
text-align: center;
}
</style>
<title></title>
<meta charset="windows-1252">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="mqttws31.js" type="text/javascript"></script>
<script type="text/javascript">
var client;
var reconnectTimeout;
var host="155.4.118.2";
var port=9001;
var JSONobj;
var jasonfrom;
var messageLATLON;
client = new Paho.MQTT.Client(host, port, "");
// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
// connect the client
client.connect({onSuccess:onConnect});
// called when the client connects
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
console.log("onConnect");
client.subscribe("PO");
/*
message = new Paho.MQTT.Message("Hello ET1544 Students");
message.destinationName = "PJ";
client.send(message);
*/
}
// 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);
if(message.payloadString!="ONOFF"){
try{
jsonobj=JSON.parse(message.payloadString);
messageLATLON="http://maps.google.com/maps?q="+String(jsonobj.Latitude)+","+String(jsonobj.Longitude)+"&z=12&output=embed";
console.log(messageLATLON);
document.getElementById("Pos").src=messageLATLON;
jasonfrom =Object.keys(jsonobj).length;
//onsole.log(evt.data);
}catch(err){
console.log(err);
}
}
document.getElementById("Button").onclick = function() {SendOnOFF()};
function SendOnOFF(){
client.subscribe("PO");
message = new Paho.MQTT.Message("ONOFF");
message.destinationName = "PO";
client.send(message);
}
}
</script>
</head>
<body id="Body">
<div class="mapouter">
<div class="gmap_canvas">
<iframe id ="Pos" width="1000" height="1000" height="450" width="600"></iframe>
<a href="https://embedgooglemap.net/maps/40"></a><br>
<style>.mapouter{position:relative;text-align:right;height:1000px;width:1000px;}</style>
<a href="https://www.embedgooglemap.net">embedgooglemap.net</a>
<style>.gmap_canvas {overflow:hidden;background:none!important;height:1000px;width:1000px;}</style>
</div>
</div>
<button id="Button">Turn ON/OFF</button>
</body>
</html>