-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
217 lines (171 loc) · 6.86 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Palette for Ranges</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="js/mqttws31.js" type="text/javascript"></script>
<link href="css/styles.css" rel="stylesheet" />
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/knockout-3.0.0.js"></script>
<script src="js/globalize.min.js"></script>
<script src="js/dx.chartjs.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script>
</head>
<script type="text/javascript">
var map;
var marker;
function initialize() {
var myLatlng = new google.maps.LatLng(-34.397, 150.644)
// Google Maps initialization
var mapOptions = {
center: myLatlng,
zoom: 12
};
map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
}
function changeMarkerPosition(marker,lat,lng) {
var latlng = new google.maps.LatLng(lat,lng);
marker.setPosition(latlng);
map.panTo(latlng);
}
google.maps.event.addDomListener(window, 'load', initialize);
var client = new Messaging.Client('broker.mqttdashboard.com', 8000, 'myclientid2234');
client.onMessageArrived = function (message) {
console.log(message.destinationName + ' | ' + message.payloadString);
var rpm = message.payloadString.split("|")[0];
var speed = message.payloadString.split("|")[1];
var lat = message.payloadString.split("|")[2];
var lng = message.payloadString.split("|")[3];
$('#chartContainer').dxCircularGauge('instance').value(rpm);
$('#chartContainer2').dxCircularGauge('instance').value(speed);
changeMarkerPosition(marker,lat, lng);
};
var mqttOptions = {
timeout: 3,
onSuccess: function () {
console.log("Connected");
client.subscribe('testGaugeTopic/#', {qos: 2});
},
onFailure: function (message) {
alert("Connection failed: " + message.errorMessage);
}
};
function init() {
client.connect(mqttOptions);
$(function () {
$('#chartContainer').dxCircularGauge({
scale: {
startValue: 0,
endValue: 6000,
majorTick: {
tickInterval: 1000
}
},
rangeContainer: {
palette: 'pastel',
ranges: [
{ startValue: 0, endValue: 2000 },
{ startValue: 2000, endValue: 4000 },
{ startValue: 4000, endValue: 6000 },
]
},
title: {
text: 'RPM',
font: { size: 20 }
},
value: 2345
});
$('#chartContainer2').dxCircularGauge({
scale: {
startValue: 0,
endValue: 280,
majorTick: {
color: '#1A1100',
tickInterval: 30
},
minorTick: {
color: '#1A1100',
visible: true,
tickInterval: 10
}
},
rangeContainer: {
backgroundColor: 'none'
},
title: {
text: 'Speed (in km/u)',
font: { size: 20 }
},
value: 90
});
$('#chartContainer3').dxLinearGauge({
geometry: { orientation: 'vertical' },
scale: {
startValue: 0,
endValue: 100,
majorTick: {
customTickValues: [0, 10, 25, 50, 75, 85, 100],
showCalculatedTicks: false
}
},
title: {
text: 'Fuel (in %)',
font: { size: 20 }
},
value: 35
});
});
}
</script>
</head>
<body onload="init();">
<a href="https://github.com/ddewaele/mqtt-dashboard-gauge"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://camo.githubusercontent.com/82b228a3648bf44fc1163ef44c62fcc60081495e/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png"></a>
<div class="line"/>
<div class="title">
<h1>MQTT Demo</h1> <h2>Simple Gauge</h2>
</div>
<div class="content">
<p>
<b>Step 1 : </b>Fill in your own broker or use the one from the kind people at broker.mqttdashboard.com. (but be gentle...)
</p>
<pre>
var client = new Messaging.Client('broker.mqttdashboard.com', 8000, 'myclientid1234');
</pre>
<p>
<b>Step 2 : </b>Have the javascript client subscribe to a topic.
</p>
<pre>
client.subscribe('testGaugeTopic/#', {qos: 2});
</pre>
<p>
<b>Step 3 : </b>Start sending messages by copying this into your shell...
</p>
<pre>
for i in {1..100}
do
mosquitto_pub -h broker.mqttdashboard.com -t testGaugeTopic/liveData --qos 2 -m "$(((RANDOM%6500)+1))|$(((RANDOM%120)+1))|40.69847032728747|-73.9514422416687";
done
</pre>
<p>Or <a href="trip-playback.sh">download this shell script</a> for some dummy data</p>
<div class="pane">
<table>
<tr><td>
<div id="chartContainer" class="case-container" style="float:left; width: 100%; height: 240px;"></div>
</td><td>
<div id="chartContainer2" class="case-container" style="float:right; width: 100%; height: 240px;"></div>
</td><td>
<div id="chartContainer3" class="case-container" style="float:right; width: 100%; height: 240px;"></div>
</td></tr>
</table>
<div id="map-canvas"/>
</div>
</div>
</body>
</html>