www/js/mon_co2meter.js

Thu, 14 May 2020 14:38:20 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 14 May 2020 14:38:20 +0200
changeset 678
14322825cb3d
parent 526
2991acd35cdb
child 680
0bb48333d133
permissions
-rw-r--r--

The co2meters monitor screen rebuild to use websockets instead of data polling.

503
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
678
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
2 * Copyright (C) 2019-2020
503
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of BMS
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * Brewery Management System istributed in the hope that it will be useful, but
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with ThermFerm; see the file COPYING. If not, write to the Free
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
678
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
21 */
503
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
526
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
24 $(document).ready(function() {
503
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
526
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
26 var record = {},
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
27 blank = {},
503
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28
526
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
29 productSource = {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
30 datatype: 'json',
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
31 cache: false,
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
32 datafields: [
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
33 { name: 'code', type: 'string' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
34 { name: 'name', type: 'string' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
35 { name: 'uuid', type: 'string' }
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
36 ],
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
37 id: 'code',
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
38 url: 'includes/db_product.php?select=ferment'
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
39 },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
40 productlist = new $.jqx.dataAdapter(productSource, {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
41 beforeLoadComplete: function(records) {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
42 var row, i, data = new Array();
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
43 // Create a dummy beer on top to store in idle meters.
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
44 blank['code'] = 'Free'; // Will override this later.
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
45 blank['name'] = 'Dummy';
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
46 blank['uuid'] = '66ecccbf-e942-4a35-af49-8b02314561a5';
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
47 data.push(blank);
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
48 for (i = 0; i < records.length; i++) {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
49 row = records[i];
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
50 data.push(row);
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
51 }
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
52 return data;
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
53 },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
54 loadError: function(jqXHR, status, error) {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
55 $('#err').text(status + ' ' + error);
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
56 },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
57 }),
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
58 gaugeoptionst = {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
59 min: 10, max: 40, width: 375, height: 375,
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
60 ranges: [{ startValue: 10, endValue: 20, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
61 { startValue: 20, endValue: 28, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
62 { startValue: 28, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }],
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
63 ticksMinor: { interval: 1, size: '5%' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
64 ticksMajor: { interval: 5, size: '9%' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
65 labels: { interval: 5 },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
66 style: { fill: '#eeeeee', stroke: '#666666' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
67 value: 0,
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
68 colorScheme: 'scheme05'
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
69 },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
70 gaugeoptionsp = {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
71 min: 0, max: 6, width: 375, height: 375,
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
72 ranges: [{ startValue: 0, endValue: 3, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
73 { startValue: 3, endValue: 6, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }],
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
74 ticksMinor: { interval: 0.2, size: '5%' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
75 ticksMajor: { interval: 1, size: '9%' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
76 labels: { interval: 1 },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
77 style: { fill: '#eeeeee', stroke: '#666666' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
78 value: 0,
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
79 colorScheme: 'scheme05'
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
80 },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
81 url = 'getco2meter.php?uuid="' + my_uuid + '"',
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
82 source = {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
83 datatype: 'json',
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
84 datafields: [
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
85 { name: 'record', type: 'int' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
86 { name: 'uuid', type: 'string' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
87 { name: 'alias', type: 'string' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
88 { name: 'node', type: 'string' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
89 { name: 'online', type: 'int' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
90 { name: 'beercode', type: 'string' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
91 { name: 'beername', type: 'string' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
92 { name: 'beeruuid', type: 'string' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
93 { name: 'mode', type: 'string' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
94 { name: 'alarm', type: 'int' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
95 { name: 'temperature_state', type: 'string' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
96 { name: 'temperature', type: 'float' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
97 { name: 'pressure_state', type: 'string' },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
98 { name: 'pressure_bar', type: 'float' }
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
99 ],
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
100 id: 'record',
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
101 url: url
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
102 },
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
103 dataAdapter = new $.jqx.dataAdapter(source, {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
104 loadComplete: function(records) {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
105 record = dataAdapter.records[0];
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
106 var oline = (record.online) ? 'On-line' : 'Off-line';
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
107 $('#info_uuid').html(record.uuid);
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
108 $('#info_system').html(record.node + '/' + record.alias);
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
109 $('#info_online').html(oline);
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
110 $('#info_beer').html(record.beercode + ' - ' + record.beername);
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
111 $('#info_mode').html(record.mode);
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
112 blank['name'] = record.alias;
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
113 blank['code'] = record.alias.toUpperCase();
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
114 blank['uuid'] = record.uuid;
503
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115
526
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
116 if (record.online && (record.mode != 'OFF')) {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
117 $('#co2meter_powerled').html('<div class="LEDblue_on"></div>Power');
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
118 $('#select_beer').jqxDropDownList({ disabled: true });
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
119 $('#select_beer').jqxDropDownList('clearSelection');
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
120 $('#select_beer').hide();
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
121 } else {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
122 $('#co2meter_powerled').html('<div class="LEDblue_off"></div>Power');
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
123 $('#select_beer').show();
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
124 $('#select_beer').jqxDropDownList({ disabled: false });
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
125 }
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
126 if (record.online && (record.alarm != '0')) {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
127 $('#co2meter_alarmled').html('<div class="LEDred_on"></div>Alarm');
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
128 } else {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
129 $('#co2meter_alarmled').html('<div class="LEDred_off"></div>Alarm');
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
130 }
503
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131
526
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
132 $('#gaugeContainer_temperature').jqxGauge({ caption: { value: 'Temp: ' + record.temperature.toFixed(3) }});
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
133 $('#gaugeContainer_temperature').jqxGauge({ value: record.temperature });
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
134 if (record.temperature_state == 'OK') {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
135 $('#gaugeContainer_temperature').jqxGauge({ disabled: false });
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
136 } else {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
137 $('#gaugeContainer_temperature').jqxGauge({ disabled: true });
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
138 }
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
139 $('#gaugeContainer_pressure').jqxGauge({ caption: { value: 'Bar: ' + record.pressure_bar.toFixed(2) }});
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
140 $('#gaugeContainer_pressure').jqxGauge({ value: record.pressure_bar });
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
141 if (record.pressure_state == 'OK') {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
142 $('#gaugeContainer_pressure').jqxGauge({ disabled: false });
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
143 } else {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
144 $('#gaugeContainer_pressure').jqxGauge({ disabled: true });
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
145 }
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
146 }
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
147 });
503
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148
526
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
149 $('#select_beer').jqxDropDownList({
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
150 placeHolder: 'Kies bier:',
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
151 theme: theme,
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
152 source: productlist,
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
153 displayMember: 'code',
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
154 width: 150,
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
155 height: 24,
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
156 dropDownWidth: 500,
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
157 autoDropDownHeight: true,
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
158 renderer: function(index, label, value) {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
159 var datarecord = productlist.records[index];
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
160 return datarecord.code + ' - ' + datarecord.name;
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
161 }
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
162 });
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
163
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
164 $('#gaugeContainer_temperature').jqxGauge(gaugeoptionst);
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
165 $('#gaugeContainer_temperature').jqxGauge({ caption: { value: 'Temp: 00.000' }});
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
166 $('#gaugeContainer_pressure').jqxGauge(gaugeoptionsp);
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
167 $('#gaugeContainer_pressure').jqxGauge({ caption: { value: 'Bar: 00.000' }});
503
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168
678
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
169 // Get the data
526
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
170 dataAdapter.dataBind();
503
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171
526
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
172 $('#select_beer').on('select', function(event) {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
173 if (event.args) {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
174 var index = event.args.index,
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
175 datarecord = productlist.records[index];
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
176 record.beercode = datarecord.code;
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
177 record.beername = datarecord.name;
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
178 record.beeruuid = datarecord.uuid;
678
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
179 console.log('Select beer ' + record.beercode + ', ' + record.beername);
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
180 var msg = '{"device":"co2meters","node":"' + record.node + '","unit":"' + record.alias +
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
181 '","beeruuid":"' + record.beeruuid + '","beercode":"' + record.beercode + '","beername":"' + record.beername + '"}';
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
182 websocket.send(msg);
526
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
183 }
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
184 });
503
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185
526
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
186 // The chart button.
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
187 $('#FLog').jqxButton({ template: 'primary', width: '150px', theme: theme });
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
188 $('#FLog').click(function() {
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
189 window.open('log_co2pressure.php?code=' + record.beercode + '&name=' + record.beername);
2991acd35cdb Code cleanup and compress.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
190 });
678
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
191
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
192 websocket.onmessage = function(evt) {
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
193 var msg = evt.data;
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
194 var obj = JSON.parse(msg);
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
195 if (obj.device == "co2meters" && obj.node == record.node && obj.unit == record.alias) {
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
196 console.log('ws got this device ' + msg);
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
197 if (obj.online) {
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
198 $('#info_online').html('On-line');
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
199 } else {
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
200 $('#info_online').html('Off-line');
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
201 }
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
202 $('#info_beer').html(obj.beercode + ' - ' + obj.beername);
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
203 $('#info_mode').html(obj.mode);
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
204 if (obj.online && obj.mode != 'OFF') {
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
205 $('#co2meter_powerled').html('<div class="LEDblue_on"></div>Power');
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
206 $('#select_beer').jqxDropDownList({ disabled: true });
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
207 $('#select_beer').jqxDropDownList('clearSelection');
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
208 $('#select_beer').hide();
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
209 } else {
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
210 $('#co2meter_powerled').html('<div class="LEDblue_off"></div>Power');
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
211 $('#select_beer').show();
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
212 $('#select_beer').jqxDropDownList({ disabled: false });
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
213 }
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
214 if (obj.online && (obj.alarm != '0')) {
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
215 $('#co2meter_alarmled').html('<div class="LEDred_on"></div>Alarm');
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
216 } else {
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
217 $('#co2meter_alarmled').html('<div class="LEDred_off"></div>Alarm');
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
218 }
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
219
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
220 $('#gaugeContainer_temperature').jqxGauge({ caption: { value: 'Temp: ' + obj.temperature.toFixed(3) }});
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
221 $('#gaugeContainer_temperature').jqxGauge({ value: obj.temperature });
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
222 $('#gaugeContainer_pressure').jqxGauge({ caption: { value: 'Bar: ' + obj.pressure_bar.toFixed(2) }});
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
223 $('#gaugeContainer_pressure').jqxGauge({ value: obj.pressure_bar });
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
224
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
225 }
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
226 ws_global(msg);
14322825cb3d The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents: 526
diff changeset
227 }
503
b23ef14c6b09 Web pages for the CO2 meters added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 });

mercurial