Browse Source

Working on JS, added test.html for local use.

Thomas Buck 8 years ago
parent
commit
2d72356640
4 changed files with 148 additions and 48 deletions
  1. 70
    38
      client-script.js
  2. 3
    3
      static.h
  3. 15
    7
      template.html
  4. 60
    0
      test.html

+ 70
- 38
client-script.js View File

10
 // in return.                                   Thomas Buck & Christian Högerle
10
 // in return.                                   Thomas Buck & Christian Högerle
11
 // ----------------------------------------------------------------------------
11
 // ----------------------------------------------------------------------------
12
 
12
 
13
-var arrSensor = Array();
13
+var arrSensor = Array(); // Data received from Websockets
14
 
14
 
15
+// Text Strings. Change these to translate.
15
 textAvailableSensors = "Available Sensors";
16
 textAvailableSensors = "Available Sensors";
16
 textButtonNext = "Continue";
17
 textButtonNext = "Continue";
17
 homeTabName = "Home";
18
 homeTabName = "Home";
23
 temperatureHeading = "Temperature";
24
 temperatureHeading = "Temperature";
24
 humidityHeading = "Humidity";
25
 humidityHeading = "Humidity";
25
 
26
 
26
-$(document).ready(function() {
27
-    $('#main-part').append(`
28
-        <div class="row" id="contentDiv">
29
-            <div class="col-md-5 col-lg-5">
30
-                <div class="panel panel-primary">
31
-                    <div class="panel-heading" id="listSensorsHeading">
32
-                        ` + textAvailableSensors + ` (0/0)
33
-                    </div>
34
-                    <div class="panel-body">
35
-                        <ul class="list-group" id="listSensors"></ul>
36
-                        <div id="alertDiv"></div>
37
-                        <button class="btn btn-primary" disabled="" id="btnSubmit">
38
-                            ` + textButtonNext + `
39
-                        </button>
40
-                    </div>
41
-                </div>
42
-            </div>
43
-        </div>`);
27
+// Colors
28
+singleChartTempColor = "#337ab7";
29
+singleChartHumidColor = "#337ab7";
30
+preDefinedColors = Array(
31
+    "#337ab7", "#ff0000", "#00ff00"
32
+);
33
+
34
+// Get current client-time for the graph X-axis labels
35
+var actTime = new Date();
36
+actTime = actTime.getHours() + ":" + (actTime.getMinutes() < 10 ? '0':'') + actTime.getMinutes();
44
 
37
 
45
-    // Get current client-time for the graph X-axis labels
46
-    var actTime = new Date();
47
-    actTime = actTime.getHours() + ":" + (actTime.getMinutes() < 10 ? '0':'') + actTime.getMinutes();
38
+// Draw initial view when the page has been loaded
39
+$(document).ready(initialView);
40
+
41
+function initialView() {
42
+    $('#contentDiv').empty();
43
+    $('#contentDiv').append(`<div class="col-sm-12 col-md-12 col-lg-12">
44
+        <div class="panel panel-primary">
45
+            <div class="panel-heading" id="listSensorsHeading">
46
+                ` + textAvailableSensors + ` (0/0)
47
+            </div>
48
+            <div class="panel-body">
49
+                <ul class="list-group" id="listSensors"></ul>
50
+                <div id="alertDiv"></div>
51
+                <button class="btn btn-primary" disabled="" id="btnSubmit">
52
+                    ` + textButtonNext + `
53
+                </button>
54
+            </div>
55
+        </div>
56
+    </div>`);
48
 
57
 
49
     $('#listSensorsHeading').empty();
58
     $('#listSensorsHeading').empty();
50
     $('#listSensorsHeading').html(textAvailableSensors + " (0/" + clients.length + ")");
59
     $('#listSensorsHeading').html(textAvailableSensors + " (0/" + clients.length + ")");
58
     // Button to continue to graph view
67
     // Button to continue to graph view
59
     $("#btnSubmit").click(function(event) {
68
     $("#btnSubmit").click(function(event) {
60
         $('#contentDiv').empty();
69
         $('#contentDiv').empty();
61
-        generateView(arrSensor, actTime);
70
+        generateView(arrSensor);
62
     });
71
     });
63
-});
72
+}
64
 
73
 
65
 function webSocket(wsUri, wsPort, count, clientsCount) {
74
 function webSocket(wsUri, wsPort, count, clientsCount) {
66
     websocket = new WebSocket("ws://" + wsUri + ":" + wsPort + "/");
75
     websocket = new WebSocket("ws://" + wsUri + ":" + wsPort + "/");
102
     };
111
     };
103
 }
112
 }
104
 
113
 
105
-function generateView(arrSensor, actTime) {
106
-    $('#contentDiv').append(`<div class="col-md-12 col-lg-12">
114
+function generateView(arrSensor) {
115
+    $('#contentDiv').append(`<div class="col-sm-12 col-md-12 col-lg-12">
107
                                 <div class="panel panel-primary">
116
                                 <div class="panel panel-primary">
108
                                     <ul class="nav nav-pills">
117
                                     <ul class="nav nav-pills">
109
                                         <li class="active"><a class="navtab" data-toggle="tab" href="#home">` + homeTabName + `</a></li>
118
                                         <li class="active"><a class="navtab" data-toggle="tab" href="#home">` + homeTabName + `</a></li>
120
     });
129
     });
121
 
130
 
122
     // flag for combined plot -> true
131
     // flag for combined plot -> true
123
-    generateGraph(true, arrSensor, actTime);
132
+    generateGraph(true, arrSensor);
124
 
133
 
125
     $(".navtab").click(function(event) {
134
     $(".navtab").click(function(event) {
126
         $('#contentPanel').empty();
135
         $('#contentPanel').empty();
127
         if(event.target.text == homeTabName) {
136
         if(event.target.text == homeTabName) {
128
             // flag for combined plot -> true
137
             // flag for combined plot -> true
129
-            generateGraph(true, arrSensor, actTime);
138
+            generateGraph(true, arrSensor);
130
         } else {
139
         } else {
131
-            generateGraph(false, arrSensor[(event.target.text.split(" ")[1] - 1)], actTime);
140
+            generateGraph(false, arrSensor[(event.target.text.split(" ")[1] - 1)]);
132
         }
141
         }
133
     });
142
     });
134
 }
143
 }
135
 
144
 
136
-function generateGraph(flag, sensor, actTime) {
145
+function generateGraph(flag, sensor) {
137
     $('#contentPanel').append(`<div class="row">
146
     $('#contentPanel').append(`<div class="row">
138
                                 <div class="col-sm-12 col-md-12 col-lg-6">
147
                                 <div class="col-sm-12 col-md-12 col-lg-6">
139
-                                    <canvas id="temperaturChart"></canvas>
148
+                                    <div id="temperatureDiv" class="embed-responsive embed-responsive-4by3">
149
+                                        <canvas id="temperatureChart"></canvas>
150
+                                    </div>
140
                                 </div>
151
                                 </div>
141
                                 <div class="col-sm-12 col-md-12 col-lg-6">
152
                                 <div class="col-sm-12 col-md-12 col-lg-6">
142
-                                    <canvas id="humidityChart"></canvas>
153
+                                    <div id="humidityDiv" class="embed-responsive embed-responsive-4by3">
154
+                                        <canvas id="humidityChart"></canvas>
155
+                                    </div>
143
                                 </div>
156
                                 </div>
144
                             </div>`);
157
                             </div>`);
145
     if (flag) {
158
     if (flag) {
176
             tmpDataTemperature.push(tmp.currentTemp);
189
             tmpDataTemperature.push(tmp.currentTemp);
177
             tmpDataHumidity.push(tmp.currentHum);
190
             tmpDataHumidity.push(tmp.currentHum);
178
 
191
 
179
-            var lineColor = getRandomColor();
192
+            var lineColor = getColor(index);
180
             dataTemperature.push({label: sensorTabName + " " + tmp.id, data: tmpDataTemperature, fill: false,
193
             dataTemperature.push({label: sensorTabName + " " + tmp.id, data: tmpDataTemperature, fill: false,
181
                 borderWidth: 3, borderColor : lineColor,});
194
                 borderWidth: 3, borderColor : lineColor,});
182
             dataHumidity.push({label: sensorTabName + " " + tmp.id, data: tmpDataHumidity, fill: false,
195
             dataHumidity.push({label: sensorTabName + " " + tmp.id, data: tmpDataHumidity, fill: false,
205
         tmpDataHumidity.push(sensor.currentHum);
218
         tmpDataHumidity.push(sensor.currentHum);
206
 
219
 
207
         var dataTemperature = [{label: temperatureLabel, data: tmpDataTemperature,
220
         var dataTemperature = [{label: temperatureLabel, data: tmpDataTemperature,
208
-                                fill: false, borderWidth: 3, borderColor: '#337ab7',}];
221
+                                fill: false, borderWidth: 3, borderColor: singleChartTempColor,}];
209
         var dataHumidity = [{label: humidityLabel, data: tmpDataHumidity,
222
         var dataHumidity = [{label: humidityLabel, data: tmpDataHumidity,
210
-                                fill: false, borderWidth: 3, borderColor: '#337ab7',}];
223
+                                fill: false, borderWidth: 3, borderColor: singleChartHumidColor,}];
211
     }
224
     }
212
 
225
 
213
-    var tempCtx = $('#temperaturChart');
226
+    var tempCtx = $('#temperatureChart');
214
     var humCtx = $('#humidityChart');
227
     var humCtx = $('#humidityChart');
215
 
228
 
229
+    //tempCtx.attr('width', $('#temperatureDiv').width());
230
+    //tempCtx.attr('height', $('#temperatureDiv').height());
231
+    //humCtx.attr('width', $('#humidityDiv').width());
232
+    //humCtx.attr('height', $('#humidityDiv').height());
233
+
216
     var tempChart = new Chart(tempCtx, {
234
     var tempChart = new Chart(tempCtx, {
217
         type: 'line',
235
         type: 'line',
218
         data: {
236
         data: {
223
             title: {
241
             title: {
224
                 display: true,
242
                 display: true,
225
                 text: temperatureHeading
243
                 text: temperatureHeading
226
-            }
244
+            },
245
+            responsive: true,
246
+            maintainAspectRatio: true,
247
+            scaleOverride: true
227
         }
248
         }
228
     });
249
     });
229
 
250
 
237
             title: {
258
             title: {
238
                 display: true,
259
                 display: true,
239
                 text: humidityHeading
260
                 text: humidityHeading
240
-            }
261
+            },
262
+            responsive: true,
263
+            maintainAspectRatio: true,
264
+            scaleOverride: true
241
         }
265
         }
242
     });
266
     });
243
 }
267
 }
247
     return ((this%n)+n)%n;
271
     return ((this%n)+n)%n;
248
 }
272
 }
249
 
273
 
274
+function getColor(index) {
275
+    if (index < preDefinedColors.length) {
276
+        return preDefinedColors[index];
277
+    } else {
278
+        return getRandomColor();
279
+    }
280
+}
281
+
250
 function getRandomColor() {
282
 function getRandomColor() {
251
     var letters = '0123456789ABCDEF'.split('');
283
     var letters = '0123456789ABCDEF'.split('');
252
     var color = '#';
284
     var color = '#';

+ 3
- 3
static.h
File diff suppressed because it is too large
View File


+ 15
- 7
template.html View File

19
             crossorigin="anonymous"
19
             crossorigin="anonymous"
20
             defer>
20
             defer>
21
         </script>
21
         </script>
22
-        <script src="view.js" defer>
23
-        </script>
24
         <link rel="stylesheet"
22
         <link rel="stylesheet"
25
             href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
23
             href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
26
             integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
24
             integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
27
             crossorigin="anonymous">
25
             crossorigin="anonymous">
28
         <link rel="stylesheet" href="style.css" type="text/css">
26
         <link rel="stylesheet" href="style.css" type="text/css">
27
+        <script src="view.js" defer>
28
+        </script>
29
         <link rel="icon" href="favicon.ico" type="image/x-icon">
29
         <link rel="icon" href="favicon.ico" type="image/x-icon">
30
     </head>
30
     </head>
31
     <body>
31
     <body>
33
             /* %% INSERT_CLIENT_LIST_HERE %% */
33
             /* %% INSERT_CLIENT_LIST_HERE %% */
34
         </script>
34
         </script>
35
 
35
 
36
-        <div id="main-part" class="container-fluid">
36
+        <div id="main-part" class="container">
37
             <div class="page-header">
37
             <div class="page-header">
38
-                <h2>ESP-Weather</h2>
38
+                <h2>ESP-Weather <small>v2</small></h2>
39
             </div>
39
             </div>
40
         </div>
40
         </div>
41
         <div class="footer">
41
         <div class="footer">
42
-            <div class="container-fluid">
43
-                <p class="text-muted">
44
-                    &copy; Copyright 2016 by Christian H&ouml;gerle und Thomas Buck
42
+            <div class="container">
43
+                <p class="text-muted text-center">
44
+                    &copy; Copyright 2016 by Christian H&ouml;gerle and Thomas Buck
45
+                    <br>
46
+                    <small>
47
+                        <small>
48
+                            <a href="https://github.com/xythobuz/ESP-Weather">
49
+                                ESP-Weather is free software!
50
+                            </a>
51
+                        </small>
52
+                    </small>
45
                 </p>
53
                 </p>
46
             </div>
54
             </div>
47
         </div>
55
         </div>

+ 60
- 0
test.html View File

1
+<!DOCTYPE html>
2
+<html lang="en">
3
+    <head>
4
+        <meta charset="utf-8">
5
+        <meta name="viewport" content="width=device-width, initial-scale=1">
6
+        <title>ESP-Weather</title>
7
+        <script src="https://code.jquery.com/jquery-3.1.1.min.js"
8
+                integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
9
+                crossorigin="anonymous"
10
+                defer>
11
+        </script>
12
+        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
13
+            integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
14
+            crossorigin="anonymous"
15
+            defer>
16
+        </script>
17
+        <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.bundle.min.js"
18
+            integrity="sha256-RASNMNlmRtIreeznffYMDUxBXcMRjijEaaGF/gxT6vw="
19
+            crossorigin="anonymous"
20
+            defer>
21
+        </script>
22
+        <link rel="stylesheet"
23
+            href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
24
+            integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
25
+            crossorigin="anonymous">
26
+        <link rel="stylesheet" href="client-style.css" type="text/css">
27
+        <script src="client-script.js" defer>
28
+        </script>
29
+        <link rel="icon" href="favicon.ico" type="image/x-icon">
30
+    </head>
31
+    <body>
32
+        <script type="text/javascript">
33
+            var clients = Array('192.168.0.173');
34
+        </script>
35
+
36
+        <div id="main-part" class="container">
37
+            <div class="page-header">
38
+                <h2>ESP-Weather <small>v2</small></h2>
39
+            </div>
40
+            <div class="row" id="contentDiv">
41
+            </div>
42
+        </div>
43
+        <div class="footer">
44
+            <div class="container">
45
+                <p class="text-muted text-center">
46
+                    &copy; Copyright 2016 by Christian H&ouml;gerle and Thomas Buck
47
+                    <br>
48
+                    <small>
49
+                        <small>
50
+                            <a href="https://github.com/xythobuz/ESP-Weather">
51
+                                ESP-Weather is free software!
52
+                            </a>
53
+                        </small>
54
+                    </small>
55
+                </p>
56
+            </div>
57
+        </div>
58
+    </body>
59
+</html>
60
+

Loading…
Cancel
Save