-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.html
361 lines (324 loc) · 11 KB
/
client.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<!-- note: the controls development is incomplete (not all of them are functioning) -->
<html>
</head>
<link type="text/css" href="css/dot-luv/jquery-ui-1.10.3.custom.min.css" rel="Stylesheet" />
<style type="text/css">
#map-canvas{
height: 500px;
width: 500px;
border: 3px solid black;
}
</style>
<script type="text/javascript" src="js/socket.io.js"></script>
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.10.3.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.flot.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false" type="text/javascript"></script>
<script>
$(document).ready(function(){
var markersArray = [];
var lineCoordinates = [
new google.maps.LatLng(22.291, 153.027),
new google.maps.LatLng(18.291, 153.027)
];
var map;
var lineSymbol = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
};
var arrowIcon = {
path: google.maps.SymbolPath.BACKWARD_CLOSED_ARROW,//'M 125,5 155,90 245,90 175,145 200,230 125,180 50,230 75,145 5,90 95,90 z',
//google.maps.SymbolPath.CIRCLE
fillColor: "lightgreen",
fillOpacity: 0.8,
scale: 4,
strokeColor: "green",
strokeWeight: 2
};
var line = new google.maps.Polyline({
path: lineCoordinates,
icons: [{
icon: lineSymbol,
offset: '100%'
}],
map: map
});
// if HTML DOM Element that contains the map is found...
if (document.getElementById('map-canvas')){
// Coordinates to center the map
var myLatlng = new google.maps.LatLng(4.28068,101.942139);
// Other options for the map, pretty much selfexplanatory
var mapOptions = {
zoom: 7,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Attach a map to the DOM Element, with the defined settings
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
//addMarker(myLatlng);
}
function addMarker(location) {
marker = new google.maps.Marker({
position: location,
icon: arrowIcon,
map: map,
animation: google.maps.Animation.DROP,
title: "blimb"
});
markersArray.push(marker);
marker.setAnimation(google.maps.Animation.BOUNCE);
}
// Deletes all markers in the array by removing references to them (except first)
function deleteOverlays() {
if (markersArray) {
for (var i=0;i< markersArray.length;i++) { // i in markersArray
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
}
// });
// $(document).ready(function(){
var socket = io.connect('http://localhost:8000');
var servo = function(){
socket.emit('message','A'+$('#servoControl').slider('value'));
}
var fan = function(el){
var let;
var elem=$('#eastControl');
//if checked double =>d
if (el == 'e'){
let = 'E';
elem = $('#eastControl');
}else if (el == 'w'){
let = 'W';
elem = $('#westControl');
}
//socket.emit('message',let+elem.slider('value'));
}
var lat= "";
var lon= "";
var alt= 0.0;
var Tempreture = 0 ;
var Htemp = 0;
var eastFan = 0 ;
var westFan = 0;
var Humidity = 0 ;
var direction = 0;
var ultraDist = 0;
// Initialize Flot data points
var totalPoints = 300;
var res = {val:[]};
var eastVals = {val:[]};
var westVals = {val:[]};
function getInitData(vv) {
// zip the generated y values with the x values
for (var i = 0; i < totalPoints; ++i){
vv.val.push([i, 0]);
}
return vv.val;
}
// Options for Flot plot
var options = {
series: { shadowSize: 0 }, // drawing is faster without shadows
yaxis: { min: 0, max: 300 },
xaxis: { show: false }
};
var fanOpts = {
series: { shadowSize: 0 }, // drawing is faster without shadows
yaxis: { min: 0, max: 150 },
xaxis: { show: false }
};
var plot = $.plot($("#placeholder"), [ getInitData(res) ], options);
var eastGraph = $.plot($("#EastGraph"), [ getInitData(eastVals) ], fanOpts);
var westGraph = $.plot($("#WestGraph"), [ getInitData(westVals) ], fanOpts);
// Update the JQuery UI Progress Bar
$( "#progressbar" ).progressbar({
value: 0
}).progressbar( "option", "max", 300 ).progressbar( "enable" );
$( "#temp" ).progressbar({
value: 0
}).progressbar( "option", "max", 100 ).progressbar( "enable" );
$( "#Htemp" ).progressbar({
value: 0
}).progressbar( "option", "max", 100 ).progressbar( "enable" );
$( "#hum" ).progressbar({
value: 0
}).progressbar( "option", "max", 100 ).progressbar( "enable" );
$( "#udist" ).progressbar({
value: 0
}).progressbar( "option", "max", 400 ).progressbar( "enable" );
$( "#palt" ).progressbar({
value: 0
}).progressbar( "option", "max", 300 ).progressbar( "enable" );
$('#eastControl').slider({
value:0,
min:0,
max:150,
step:5,
change:fan('e'),
orientation: 'vertical'
});
$('#westControl').slider({
value:0,
min:0,
max:150,
step:5,
change:fan('w'),
orientation: 'vertical'
});
$('#servoControl').slider({
value:90,
min:0,
max:180,
step:10,
change:servo,
orientation: 'horizontal'
});
//$( "#progressbar" ).find( ".ui-progressbar-value" ).css({"background": '#55ddaa'});
//var socket = io.connect('http://192.168.1.115:8000');
var currlatlang;
socket.on('connect', function () {
socket.on('message', function (msg) {
// Convert value to integer
//var val = (parseInt(msg));
if(msg[0]=='l'){
lat = msg.substring(1,msg.length-2);
lat = parseFloat(lat.substring(0,2)) + (parseFloat(lat.substring(2))/60.0000);
//if (msg[msg.length-1] == 'S') lat *= -1;
if (lon != "" && lat != "") {
currlatlang = new google.maps.LatLng(parseFloat(lat),parseFloat(lon));
//if(currlatlang != markersArray[markersArray.length-1].getPosition()){
//deleteOverlays();
//addMarker(currlatlang);
if(markersArray.length == 0) addMarker(currlatlang);
else markersArray[markersArray.length-1].setPosition(currlatlang);
map.panTo(currlatlang);
map.setZoom(18);
//}
}
$('#lat').html(lat);
}else if(msg[0]=='o'){
lon = msg.substring(1,msg.length-2);
lon = parseFloat(lon.substring(0,3)) + (parseFloat(lon.substring(3))/60.0000);
//if (msg[msg.length-1] == 'W') lon *= -1;
if (lon != "" && lat != "") {
currlatlang = new google.maps.LatLng(parseFloat(lat),parseFloat(lon));
//if(currlatlang != markersArray[markersArray.length-1].getPosition()){
//deleteOverlays();
//addMarker(currlatlang);
if(markersArray.length == 0) addMarker(currlatlang);
else markersArray[markersArray.length-1].setPosition(currlatlang);
map.panTo(currlatlang);
map.setZoom(18);
//}
}
$('#lon').html(lon);
}else if(msg[0]=='a'){
alt = parseFloat(msg.substring(1));
$('#alt,#alt2').html(alt);
res.val.push([totalPoints, alt]);
res.val.shift();
for (i=0;i<totalPoints;i++) { res.val[i][0] = i; }
plot.setData([ res.val ]);
plot.draw();
$( "#progressbar" ).progressbar( "option", "value", alt );
}else if(msg[0]=='T'){
Tempreture = parseInt(msg.substring(1));
$('#tem').html(Tempreture);
$( "#temp" ).progressbar( "option", "value", Tempreture );
}else if(msg[0]=='H'){
Humidity = parseInt(msg.substring(1));
$('#hu').html(Humidity);
$( "#hum" ).progressbar( "option", "value", Humidity );
}else if(msg[0]=='E'){
eastFan = parseInt(msg.substring(1));
$('#eastFan').html(eastFan);
eastVals.val.push([totalPoints, eastFan]);
eastVals.val.shift();
for (i=0;i<totalPoints;i++) { eastVals.val[i][0] = i; }
eastGraph.setData([ eastVals.val ]);
eastGraph.draw();
}else if(msg[0]=='W'){
westFan = parseInt(msg.substring(1));
$('#westFan').html(westFan);
westVals.val.push([totalPoints, westFan]);
westVals.val.shift();
for (i=0;i<totalPoints;i++) { westVals.val[i][0] = i; }
westGraph.setData([ westVals.val ]);
westGraph.draw();
}else if(msg[0] == 'd'){
direction = parseInt(msg.substring(1));
$('#direction').html(direction+' deg');
}else if(msg[0] == 'M'){
HTemp = parseInt(msg.substring(1));
$('#Htem').html(HTemp);
$( "#Htemp" ).progressbar( "option", "value", HTemp );
}else if(msg[0] == 'F'){
switch(msg[1]){
case 'S':
forcast = 'Sunny';
break;
case 'C':
forcast = 'Cloudy';
break;
case 'R':
forcast = 'Rainy';
}
$('#weather').html('weather: '+forcast);
}else if(msg[0] == 'C'){
ultraDist = parseInt(msg.substring(1));
$('#ud').html(ultraDist);
$( "#udist" ).progressbar( "option", "value", ultraDist );
}else if(msg[0] == 'U'){
Paltitude = parseInt(msg.substring(1));
$('#pa').html(Paltitude);
$( "#palt" ).progressbar( "option", "value", Paltitude );
}
// Put sensor value to the 'sensor_value' span
//$('#sensor_value').html(msg);
// Push new value to Flot Plot
// Update JQuery UI progress bar.
// $( "#progressbar" ).progressbar({
// value: val
// });
});
});
});
</script>
</head>
<body>
<div role="main">
<div style="float:left">
GPS altitude: <span id="alt"></span> M<br/>
<div id="progressbar" style="width:600px;height:50px;"></div><br/>
Pressure altitude: <span id="pa"></span> M<br/>
<div id="palt" style="width:600px;height:50px;"></div><br/>
Altitude Graph:<br/>
<div id="placeholder" style="width:600px;height:300px;"></div><br/>
Tempreture: <span id="tem"></span> C<br/>
<div id="temp" style="width:600px;height:50px;"></div><br/>
H Tempreture: <span id="Htem"></span> C<br/>
<div id="Htemp" style="width:600px;height:50px;"></div><br/>
Humidity: <span id="hu"></span> %<br/>
<div id="hum" style="width:600px;height:50px;"></div><br/>
East Fan Speed : <span id="east"></span>
<div id="EastGraph" style="width:600px;height:300px;"></div>
West Fan Speed : <span id="west"></span>
<div id="WestGraph" style="width:600px;height:300px;"></div>
<div id="weather"></div>
<div id="direction"></div>
Distance from ground: <span id="ud"></span> CM<br/>
<div id="udist" style="width:600px;height:50px;"></div><br/>
</div>
<div style="float:right">
latitude Value : <span id="lat"></span><br/>
longitude Value: <span id="lon"></span><br/>
Altitude Value : <span id="alt2"></span><br/>
<div id="map-canvas"></div>
<div id="servoControl" style="margin:30px 0px;"></div>
<div id="eastControl" style="float:left;margin-left:30px;height:30%;"></div>
<div id="westControl" style="float:left;margin-left:30px;height:30%;"></div>
</div>
</div>
</body>
</html>