瀏覽代碼

Translated JS

Thomas Buck 8 年之前
父節點
當前提交
15edcadc35
共有 3 個文件被更改,包括 44 次插入29 次删除
  1. 4
    0
      .gitignore
  2. 39
    28
      client-script.js
  3. 1
    1
      static.h

+ 4
- 0
.gitignore 查看文件

@@ -1 +1,5 @@
1 1
 .DS_Store
2
+Icon

3
+
4
+.fseventsd
5
+.VolumeIcon.icns

+ 39
- 28
client-script.js 查看文件

@@ -14,6 +14,14 @@ var arrSensor = Array();
14 14
 
15 15
 textAvailableSensors = "Available Sensors";
16 16
 textButtonNext = "Continue";
17
+homeTabName = "Home";
18
+sensorTabName = "Sensor";
19
+errorMessage = "Couldn't read sensor with IP: ";
20
+errorTitle = "Error: ";
21
+temperatureLabel = 'Temperature [C]';
22
+humidityLabel = 'Humidity [%RH]';
23
+temperatureHeading = "Temperature";
24
+humidityHeading = "Humidity";
17 25
 
18 26
 $(document).ready(function() {
19 27
     $('#main-part').append(`
@@ -34,20 +42,20 @@ $(document).ready(function() {
34 42
             </div>
35 43
         </div>`);
36 44
 
37
-    // aktuelle Uhrzeit fuer die Graphen ermitteln
45
+    // Get current client-time for the graph X-axis labels
38 46
     var actTime = new Date();
39 47
     actTime = actTime.getHours() + ":" + (actTime.getMinutes() < 10 ? '0':'') + actTime.getMinutes();
40 48
 
41 49
     $('#listSensorsHeading').empty();
42 50
     $('#listSensorsHeading').html(textAvailableSensors + " (0/" + clients.length + ")");
43 51
 
44
-    // Alle clients im Array iterieren und Websocket abfragen
52
+    // Iterate all given client IPs and get their data using Websocket
45 53
     var count = [0];
46 54
     jQuery.each(clients, function(index, client) {
47 55
         webSocket(client, "2391", count, clients.length);
48 56
     });
49 57
 
50
-    // Submit-Button fuer die Formulareingabe
58
+    // Button to continue to graph view
51 59
     $("#btnSubmit").click(function(event) {
52 60
         $('#contentDiv').empty();
53 61
         generateView(arrSensor, actTime);
@@ -61,7 +69,7 @@ function webSocket(wsUri, wsPort, count, clientsCount) {
61 69
     websocket.onmessage = function(evt) {
62 70
         var jsonData = jQuery.parseJSON(evt.data);
63 71
         count[0]++;
64
-        var sensor = {id: count[0], ip: wsUri, actualTemp: jsonData['T'], actualHum: jsonData['H']};
72
+        var sensor = {id: count[0], ip: wsUri, currentTemp: jsonData['T'], currentHum: jsonData['H']};
65 73
         var arrEEPROM = Array();
66 74
         jQuery.each(jsonData['EEPROM'], function(index, data) {
67 75
             arrEEPROM.push(data);
@@ -72,22 +80,23 @@ function webSocket(wsUri, wsPort, count, clientsCount) {
72 80
         $('#listSensors').append('<li class="list-group-item">' +
73 81
                                     ' Sensor ' + sensor.id +
74 82
                                     ' | IP: ' + sensor.ip +
75
-                                    ' | aktuelle Temperatur: ' + sensor.actualTemp +
76
-                                    ' | aktuelle Luftfeuchtigkeit: ' + sensor.actualHum +
83
+                                    ' | Temperature: ' + sensor.currentTemp +
84
+                                    ' | Humidity: ' + sensor.currentHum +
77 85
                                 '</li>');
78 86
 
79
-        // Alle Sensoren erfolgreich abgefragt
87
+        // Enable continue buttons when all modules have been reached
80 88
         if(count[0] == clientsCount) {
81 89
             $('#btnSubmit').prop("disabled", false);
82 90
         }
83 91
     };
84 92
     websocket.onerror = function(evt) {
85 93
         if($('#websocketError').length ) {
86
-            $('.alert-danger').append('Sensor mit der IP:' + wsUri + ' konnte nicht abgefragt werden! <br>');
94
+            $('.alert-danger').append(errorMessage + wsUri + '<br>');
87 95
         } else {
88 96
             $('#alertDiv').append('<div class="alert alert-danger" id="websocketError">' +
89
-                                    '<strong>Fehler:</strong><br>Sensor mit der IP:' + wsUri + ' konnte nicht abgefragt werden! <br>' +
90
-                              '</div>');
97
+                                    '<strong>' + errorTitle
98
+                                    + '</strong><br>' + errorMessage
99
+                                    + wsUri + '<br></div>');
91 100
         }
92 101
         console.log(evt.data);
93 102
     };
@@ -97,7 +106,7 @@ function generateView(arrSensor, actTime) {
97 106
     $('#contentDiv').append(`<div class="col-md-12 col-lg-12">
98 107
                                 <div class="panel panel-primary">
99 108
                                     <ul class="nav nav-pills">
100
-                                        <li class="active"><a class="navtab" data-toggle="tab" href="#home">Home</a></li>
109
+                                        <li class="active"><a class="navtab" data-toggle="tab" href="#home">` + homeTabName + `</a></li>
101 110
                                     </ul>
102 111
                                     <div class="panel-body">
103 112
                                         <div id="contentPanel">
@@ -107,16 +116,16 @@ function generateView(arrSensor, actTime) {
107 116
                             </div>`);
108 117
 
109 118
     jQuery.each(arrSensor, function(index, sensor) {
110
-        $('.nav-pills').append('<li><a class="navtab" data-toggle="tab" href="#' + sensor.id + '">Sensor ' + sensor.id + '</a></li>');
119
+        $('.nav-pills').append('<li><a class="navtab" data-toggle="tab" href="#' + sensor.id + '">' + sensorTabName + ' ' + sensor.id + '</a></li>');
111 120
     });
112 121
 
113
-    // Flag fuer gemeinsamer Graph -> true
122
+    // flag for combined plot -> true
114 123
     generateGraph(true, arrSensor, actTime);
115 124
 
116 125
     $(".navtab").click(function(event) {
117 126
         $('#contentPanel').empty();
118
-        if(event.target.text == "Home") {
119
-            // Flag fuer gemeinsamer Graph -> true
127
+        if(event.target.text == homeTabName) {
128
+            // flag for combined plot -> true
120 129
             generateGraph(true, arrSensor, actTime);
121 130
         } else {
122 131
             generateGraph(false, arrSensor[(event.target.text.split(" ")[1] - 1)], actTime);
@@ -133,7 +142,8 @@ function generateGraph(flag, sensor, actTime) {
133 142
                                     <canvas id="humidityChart"></canvas>
134 143
                                 </div>
135 144
                             </div>`);
136
-    if(flag) { // ein Graph für alle Sensoren
145
+    if (flag) {
146
+        // one plot for all sensors
137 147
         var length = 0;
138 148
         jQuery.each(sensor, function(index, tmp) {
139 149
             if(length < tmp.arrEEPROM.length) {
@@ -155,7 +165,7 @@ function generateGraph(flag, sensor, actTime) {
155 165
         var tmpDataTemperature = Array();
156 166
         var tmpDataHumidity = Array();
157 167
         jQuery.each(sensor, function(index, tmp) {
158
-            for(var i = 0; i < (length - tmp.arrEEPROM.length); i++) {
168
+            for (var i = 0; i < (length - tmp.arrEEPROM.length); i++) {
159 169
                 tmpDataTemperature.push([]);
160 170
                 tmpDataHumidity.push([]);
161 171
             }
@@ -163,19 +173,20 @@ function generateGraph(flag, sensor, actTime) {
163 173
                 tmpDataTemperature.push(value['T']);
164 174
                 tmpDataHumidity.push(value['H']);
165 175
             });
166
-            tmpDataTemperature.push(tmp.actualTemp);
167
-            tmpDataHumidity.push(tmp.actualHum);
176
+            tmpDataTemperature.push(tmp.currentTemp);
177
+            tmpDataHumidity.push(tmp.currentHum);
168 178
 
169 179
             var lineColor = getRandomColor();
170
-            dataTemperature.push({label: "Sensor " + tmp.id, data: tmpDataTemperature, fill: false,
180
+            dataTemperature.push({label: sensorTabName + " " + tmp.id, data: tmpDataTemperature, fill: false,
171 181
                 borderWidth: 3, borderColor : lineColor,});
172
-            dataHumidity.push({label: "Sensor " + tmp.id, data: tmpDataHumidity, fill: false,
182
+            dataHumidity.push({label: sensorTabName + " " + tmp.id, data: tmpDataHumidity, fill: false,
173 183
                 borderWidth: 3, borderColor : lineColor,});
174 184
 
175 185
             tmpDataTemperature = [];
176 186
             tmpDataHumidity = [];
177 187
         });
178
-    } else { // Graph für einzelnen Sensor
188
+    } else {
189
+        // plot for one sensor
179 190
         var labels = Array();
180 191
 
181 192
         var tmpDataTemperature = Array();
@@ -190,12 +201,12 @@ function generateGraph(flag, sensor, actTime) {
190 201
         });
191 202
 
192 203
         labels.push(actTime);
193
-        tmpDataTemperature.push(sensor.actualTemp);
194
-        tmpDataHumidity.push(sensor.actualHum);
204
+        tmpDataTemperature.push(sensor.currentTemp);
205
+        tmpDataHumidity.push(sensor.currentHum);
195 206
 
196
-        var dataTemperature = [{label: 'Temperatur [C]', data: tmpDataTemperature,
207
+        var dataTemperature = [{label: temperatureLabel, data: tmpDataTemperature,
197 208
                                 fill: false, borderWidth: 3, borderColor: '#337ab7',}];
198
-        var dataHumidity = [{label: 'Luftfeuchtigkeit [%RH]', data: tmpDataHumidity,
209
+        var dataHumidity = [{label: humidityLabel, data: tmpDataHumidity,
199 210
                                 fill: false, borderWidth: 3, borderColor: '#337ab7',}];
200 211
     }
201 212
 
@@ -211,7 +222,7 @@ function generateGraph(flag, sensor, actTime) {
211 222
         options: {
212 223
             title: {
213 224
                 display: true,
214
-                text: 'Temperaturverlauf'
225
+                text: temperatureHeading
215 226
             }
216 227
         }
217 228
     });
@@ -225,7 +236,7 @@ function generateGraph(flag, sensor, actTime) {
225 236
         options: {
226 237
             title: {
227 238
                 display: true,
228
-                text: 'Luftfeuchtigkeitverlauf'
239
+                text: humidityHeading
229 240
             }
230 241
         }
231 242
     });

+ 1
- 1
static.h
文件差異過大導致無法顯示
查看文件


Loading…
取消
儲存