@@ -34,17 +34,89 @@ L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
34
34
var breadCrumbLine = L . polyline ( [ ] ) . addTo ( map ) ;
35
35
var locationCircle = L . circle ( [ 0 , 0 ] ) . addTo ( map ) ;
36
36
37
+
38
+ // Create charts
39
+ const temperatureData = {
40
+ labels : [ ] ,
41
+ datasets : [
42
+ {
43
+ label : 'Internal Temp' ,
44
+ data : [ ] ,
45
+ borderColor : 'rgba(54, 162, 235, 1)' ,
46
+ backgroundColor : 'rgba(54, 162, 235, 0.2)' ,
47
+ yAxisID : 'y' ,
48
+ } ,
49
+ {
50
+ label : 'External Temp' ,
51
+ data : [ ] ,
52
+ borderColor : 'rgba(0, 99, 182, 1)' ,
53
+ backgroundColor : 'rgba(0, 99, 182, 0.2)' ,
54
+ yAxisID : 'y' ,
55
+ } ,
56
+ {
57
+ label : 'Humidity' ,
58
+ data : [ ] ,
59
+ borderColor : 'rgba(255, 99, 132, 1)' ,
60
+ backgroundColor : 'rgba(255, 99, 132, 0.2)' ,
61
+ yAxisID : 'y1' ,
62
+ }
63
+ ]
64
+ } ;
65
+
66
+ const temperatureConfig = {
67
+ type : 'line' ,
68
+ data : temperatureData ,
69
+ options : {
70
+ responsive : true ,
71
+ interaction : {
72
+ mode : 'index' ,
73
+ intersect : false ,
74
+ } ,
75
+ stacked : false ,
76
+ plugins : {
77
+ title : {
78
+ display : true ,
79
+ text : 'Temperature & humidity'
80
+ }
81
+ } ,
82
+ scales : {
83
+ y : {
84
+ type : 'linear' ,
85
+ display : true ,
86
+ position : 'left' ,
87
+ title : {
88
+ display :true ,
89
+ text : 'Temperature (deg)'
90
+ }
91
+ } ,
92
+ y1 : {
93
+ type : 'linear' ,
94
+ display : true ,
95
+ position : 'right' ,
96
+ title : {
97
+ display :true ,
98
+ text : 'Relative humidity (%)'
99
+ } ,
100
+
101
+ // grid line settings
102
+ grid : {
103
+ drawOnChartArea : false , // only want the grid lines for one axis to show up
104
+ } ,
105
+ } ,
106
+ }
107
+ } ,
108
+ } ;
109
+
110
+ const temperatureChart = new Chart ( 'temperatureChart' , temperatureConfig ) ;
111
+
37
112
function locationSuccess ( position ) {
38
113
const c = position . coords ;
39
114
locationText . textContent = `lat/long:${ c . latitude } /${ c . longitude } speed:${ c . speed } heading:${ c . heading } altitude:${ c . altitude } accuracy:${ c . accuracy } altaccuracy:${ c . altitudeAccuracy } timestamp:${ position . timestamp } ` ;
40
115
const latlng = [ c . latitude , c . longitude ] ;
41
116
if ( npositions == 0 ) {
42
- console . log ( "Flying to" , zoomLevel , latlng ) ;
43
117
//map.flyTo(latlng, Number(zoomLevel), {animate:true}); // Flying takes too long and stops when the next location comes in
44
118
map . setView ( latlng , zoomLevel ) ;
45
-
46
119
} else {
47
- console . log ( "Panning to" , latlng ) ;
48
120
map . panTo ( latlng ) ;
49
121
}
50
122
breadCrumbLine . addLatLng ( latlng ) ;
@@ -111,6 +183,7 @@ function onConnectionLost(responseObject) {
111
183
}
112
184
113
185
// called when a message arrives
186
+ let nmsg = 0 ;
114
187
function onMessageArrived ( message ) {
115
188
console . log ( "onMessageArrived:" , message . payloadString ) ;
116
189
console . log ( message )
@@ -122,4 +195,14 @@ function onMessageArrived(message) {
122
195
let out = document . getElementById ( "lastmessage" ) ;
123
196
out . textContent = message . payloadString ;
124
197
198
+ let data = JSON . parse ( message . payloadString ) ;
199
+
200
+ temperatureConfig . data . labels . push ( nmsg ) ;
201
+ temperatureConfig . data . datasets [ 0 ] . data . push ( data . internal_temp ) ;
202
+ temperatureConfig . data . datasets [ 1 ] . data . push ( data . external_temp ) ;
203
+ temperatureConfig . data . datasets [ 2 ] . data . push ( data . relative_humidity ) ;
204
+ temperatureChart . update ( ) ;
205
+
206
+ nmsg += 1 ;
207
+
125
208
}
0 commit comments