# HG changeset patch # User Michiel Broek # Date 1571480249 -7200 # Node ID 2991acd35cdbdb74ebc682f5ca7fd6208bc6b539 # Parent 8bbc5730aaa8399f6d11f1d46c20608a5f4e5b66 Code cleanup and compress. diff -r 8bbc5730aaa8 -r 2991acd35cdb www/js/mon_co2meter.js --- a/www/js/mon_co2meter.js Fri Oct 18 20:49:07 2019 +0200 +++ b/www/js/mon_co2meter.js Sat Oct 19 12:17:29 2019 +0200 @@ -21,203 +21,202 @@ *****************************************************************************/ -$(document).ready(function () { +$(document).ready(function() { - var record = {}, - blank = {}, - newProduct = false, - schedule = 0, + var record = {}, + blank = {}, + newProduct = false, + schedule = 0, - productSource = { - datatype: "json", - cache: false, - datafields: [ - { name: 'code', type: 'string' }, - { name: 'name', type: 'string' }, - { name: 'uuid', type: 'string' } - ], - id: 'code', - url: "includes/db_product.php?select=ferment" - }, - productlist = new $.jqx.dataAdapter(productSource, { - beforeLoadComplete: function (records) { - var row, i, data = new Array(); - // Create a dummy beer on top to store in idle meters. - blank['code'] = "Free"; // Will override this later. - blank['name'] = 'Dummy'; - blank['uuid'] = '66ecccbf-e942-4a35-af49-8b02314561a5'; - data.push(blank); - for (i = 0; i < records.length; i++) { - row = records[i]; - data.push(row); - } - return data; - }, - loadError: function(jqXHR, status, error) { - $('#err').text(status + ' ' + error); - }, - }), - gaugeoptionst = { - min: 10, max: 40, width: 375, height: 375, - ranges: [{ startValue: 10, endValue: 20, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, - { startValue: 20, endValue: 28, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, - { startValue: 28, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }], - ticksMinor: { interval: 1, size: '5%' }, - ticksMajor: { interval: 5, size: '9%' }, - labels: { interval: 5 }, - style: { fill: '#eeeeee', stroke: '#666666' }, - value: 0, - colorScheme: 'scheme05' - }, - gaugeoptionsp = { - min: 0, max: 6, width: 375, height: 375, - ranges: [{ startValue: 0, endValue: 3, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, - { startValue: 3, endValue: 6, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }], - ticksMinor: { interval: 0.2, size: '5%' }, - ticksMajor: { interval: 1, size: '9%' }, - labels: { interval: 1 }, - style: { fill: '#eeeeee', stroke: '#666666' }, - value: 0, - colorScheme: 'scheme05' - }, - url = "getco2meter.php?uuid='" + my_uuid + "'", - source = { - datatype: "json", - datafields: [ - { name: 'record', type: 'int' }, - { name: 'uuid', type: 'string' }, - { name: 'alias', type: 'string' }, - { name: 'node', type: 'string' }, - { name: 'online', type: 'int' }, - { name: 'beercode', type: 'string' }, - { name: 'beername', type: 'string' }, - { name: 'beeruuid', type: 'string' }, - { name: 'mode', type: 'string' }, - { name: 'alarm', type: 'int' }, - { name: 'temperature_state', type: 'string' }, - { name: 'temperature', type: 'float' }, - { name: 'pressure_state', type: 'string' }, - { name: 'pressure_bar', type: 'float' } - ], - id: 'record', - url: url - }, - dataAdapter = new $.jqx.dataAdapter(source, { - loadComplete: function (records) { - record = dataAdapter.records[0]; - var oline = (record.online) ? "On-line" : "Off-line"; - $("#info_uuid").html(record.uuid); - $("#info_system").html(record.node + "/" + record.alias); - $("#info_online").html(oline); - $("#info_beer").html(record.beercode + " - " + record.beername); - $("#info_mode").html(record.mode); - blank['name'] = record.alias; - blank['code'] = record.alias.toUpperCase(); - blank['uuid'] = record.uuid; + productSource = { + datatype: 'json', + cache: false, + datafields: [ + { name: 'code', type: 'string' }, + { name: 'name', type: 'string' }, + { name: 'uuid', type: 'string' } + ], + id: 'code', + url: 'includes/db_product.php?select=ferment' + }, + productlist = new $.jqx.dataAdapter(productSource, { + beforeLoadComplete: function(records) { + var row, i, data = new Array(); + // Create a dummy beer on top to store in idle meters. + blank['code'] = 'Free'; // Will override this later. + blank['name'] = 'Dummy'; + blank['uuid'] = '66ecccbf-e942-4a35-af49-8b02314561a5'; + data.push(blank); + for (i = 0; i < records.length; i++) { + row = records[i]; + data.push(row); + } + return data; + }, + loadError: function(jqXHR, status, error) { + $('#err').text(status + ' ' + error); + }, + }), + gaugeoptionst = { + min: 10, max: 40, width: 375, height: 375, + ranges: [{ startValue: 10, endValue: 20, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, + { startValue: 20, endValue: 28, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, + { startValue: 28, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }], + ticksMinor: { interval: 1, size: '5%' }, + ticksMajor: { interval: 5, size: '9%' }, + labels: { interval: 5 }, + style: { fill: '#eeeeee', stroke: '#666666' }, + value: 0, + colorScheme: 'scheme05' + }, + gaugeoptionsp = { + min: 0, max: 6, width: 375, height: 375, + ranges: [{ startValue: 0, endValue: 3, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, + { startValue: 3, endValue: 6, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }], + ticksMinor: { interval: 0.2, size: '5%' }, + ticksMajor: { interval: 1, size: '9%' }, + labels: { interval: 1 }, + style: { fill: '#eeeeee', stroke: '#666666' }, + value: 0, + colorScheme: 'scheme05' + }, + url = 'getco2meter.php?uuid="' + my_uuid + '"', + source = { + datatype: 'json', + datafields: [ + { name: 'record', type: 'int' }, + { name: 'uuid', type: 'string' }, + { name: 'alias', type: 'string' }, + { name: 'node', type: 'string' }, + { name: 'online', type: 'int' }, + { name: 'beercode', type: 'string' }, + { name: 'beername', type: 'string' }, + { name: 'beeruuid', type: 'string' }, + { name: 'mode', type: 'string' }, + { name: 'alarm', type: 'int' }, + { name: 'temperature_state', type: 'string' }, + { name: 'temperature', type: 'float' }, + { name: 'pressure_state', type: 'string' }, + { name: 'pressure_bar', type: 'float' } + ], + id: 'record', + url: url + }, + dataAdapter = new $.jqx.dataAdapter(source, { + loadComplete: function(records) { + record = dataAdapter.records[0]; + var oline = (record.online) ? 'On-line' : 'Off-line'; + $('#info_uuid').html(record.uuid); + $('#info_system').html(record.node + '/' + record.alias); + $('#info_online').html(oline); + $('#info_beer').html(record.beercode + ' - ' + record.beername); + $('#info_mode').html(record.mode); + blank['name'] = record.alias; + blank['code'] = record.alias.toUpperCase(); + blank['uuid'] = record.uuid; - if (record.online && (record.mode != "OFF")) { - $("#co2meter_powerled").html('
Power'); - $("#select_beer").jqxDropDownList({ disabled: true }); - $("#select_beer").jqxDropDownList('clearSelection'); - $("#select_beer").hide(); - } else { - $("#co2meter_powerled").html('
Power'); - $("#select_beer").show(); - $("#select_beer").jqxDropDownList({ disabled: false }); - - } - if (record.online && (record.alarm != "0")) { - $("#co2meter_alarmled").html('
Alarm'); - } else { - $("#co2meter_alarmled").html('
Alarm'); - } + if (record.online && (record.mode != 'OFF')) { + $('#co2meter_powerled').html('
Power'); + $('#select_beer').jqxDropDownList({ disabled: true }); + $('#select_beer').jqxDropDownList('clearSelection'); + $('#select_beer').hide(); + } else { + $('#co2meter_powerled').html('
Power'); + $('#select_beer').show(); + $('#select_beer').jqxDropDownList({ disabled: false }); + } + if (record.online && (record.alarm != '0')) { + $('#co2meter_alarmled').html('
Alarm'); + } else { + $('#co2meter_alarmled').html('
Alarm'); + } - $("#gaugeContainer_temperature").jqxGauge({ caption: { value: 'Temp: '+record.temperature.toFixed(3) }}); - $('#gaugeContainer_temperature').jqxGauge({ value: record.temperature }); - if (record.temperature_state == "OK") { - $("#gaugeContainer_temperature").jqxGauge({ disabled: false }); - } else { - $("#gaugeContainer_temperature").jqxGauge({ disabled: true }); - } - $("#gaugeContainer_pressure").jqxGauge({ caption: { value: 'Bar: '+record.pressure_bar.toFixed(2) }}); - $('#gaugeContainer_pressure').jqxGauge({ value: record.pressure_bar }); - if (record.pressure_state == "OK") { - $("#gaugeContainer_pressure").jqxGauge({ disabled: false }); - } else { - $("#gaugeContainer_pressure").jqxGauge({ disabled: true }); - } - } - }); + $('#gaugeContainer_temperature').jqxGauge({ caption: { value: 'Temp: ' + record.temperature.toFixed(3) }}); + $('#gaugeContainer_temperature').jqxGauge({ value: record.temperature }); + if (record.temperature_state == 'OK') { + $('#gaugeContainer_temperature').jqxGauge({ disabled: false }); + } else { + $('#gaugeContainer_temperature').jqxGauge({ disabled: true }); + } + $('#gaugeContainer_pressure').jqxGauge({ caption: { value: 'Bar: ' + record.pressure_bar.toFixed(2) }}); + $('#gaugeContainer_pressure').jqxGauge({ value: record.pressure_bar }); + if (record.pressure_state == 'OK') { + $('#gaugeContainer_pressure').jqxGauge({ disabled: false }); + } else { + $('#gaugeContainer_pressure').jqxGauge({ disabled: true }); + } + } + }); - $("#select_beer").jqxDropDownList({ - placeHolder: "Kies bier:", - theme: theme, - source: productlist, - displayMember: "code", - width: 150, - height: 24, - dropDownWidth: 500, - autoDropDownHeight: true, - renderer: function (index, label, value) { - var datarecord = productlist.records[index]; - return datarecord.code + " - " + datarecord.name; - } - }); + $('#select_beer').jqxDropDownList({ + placeHolder: 'Kies bier:', + theme: theme, + source: productlist, + displayMember: 'code', + width: 150, + height: 24, + dropDownWidth: 500, + autoDropDownHeight: true, + renderer: function(index, label, value) { + var datarecord = productlist.records[index]; + return datarecord.code + ' - ' + datarecord.name; + } + }); + + $('#gaugeContainer_temperature').jqxGauge(gaugeoptionst); + $('#gaugeContainer_temperature').jqxGauge({ caption: { value: 'Temp: 00.000' }}); + $('#gaugeContainer_pressure').jqxGauge(gaugeoptionsp); + $('#gaugeContainer_pressure').jqxGauge({ caption: { value: 'Bar: 00.000' }}); - $("#gaugeContainer_temperature").jqxGauge( gaugeoptionst ); - $("#gaugeContainer_temperature").jqxGauge( { caption: { value: 'Temp: 00.000' }} ); - $("#gaugeContainer_pressure").jqxGauge( gaugeoptionsp ); - $("#gaugeContainer_pressure").jqxGauge( { caption: { value: 'Bar: 00.000' }} ); - - function sendProduct(code, name, uuid) { + function sendProduct(code, name, uuid) { - console.log("sendProduct("+code+", "+name+", "+uuid+")"); - var data = 'uuid='+record.uuid+'&beeruuid='+uuid+'&beercode='+code+'&beername='+name; - $.ajax({ - url: "cmd_co2meter.php", - data: data, - type: "POST", - success: function(data) {}, - error: function(jqXHR, textStatus, errorThrown) { console.log("sendProduct() error"); } - }); - } + console.log('sendProduct(' + code + ', ' + name + ', ' + uuid + ')'); + var data = 'uuid=' + record.uuid + '&beeruuid=' + uuid + '&beercode=' + code + '&beername=' + name; + $.ajax({ + url: 'cmd_co2meter.php', + data: data, + type: 'POST', + success: function(data) {}, + error: function(jqXHR, textStatus, errorThrown) { console.log('sendProduct() error'); } + }); + } - // Get the data immediatly and then at regular intervals to refresh. - dataAdapter.dataBind(); - setInterval(function() { - var skip = false; - if (newProduct) { - sendProduct(record.beercode, record.beername, record.beeruuid); - newProduct = false; - skip = true; - } - if (skip) { - schedule = 4; // 2 seconds wait to get the results - } else { - if (schedule > 0) - schedule--; - } + // Get the data immediatly and then at regular intervals to refresh. + dataAdapter.dataBind(); + setInterval(function() { + var skip = false; + if (newProduct) { + sendProduct(record.beercode, record.beername, record.beeruuid); + newProduct = false; + skip = true; + } + if (skip) { + schedule = 4; // 2 seconds wait to get the results + } else { + if (schedule > 0) + schedule--; + } - if (schedule <= 0) { - dataAdapter.dataBind(); - schedule = 20; - } - }, 500); + if (schedule <= 0) { + dataAdapter.dataBind(); + schedule = 20; + } + }, 500); - $("#select_beer").on('select', function (event) { - if (event.args) { - var index = event.args.index, - datarecord = productlist.records[index]; - record.beercode = datarecord.code; - record.beername = datarecord.name; - record.beeruuid = datarecord.uuid; - newProduct = true; - } - }); + $('#select_beer').on('select', function(event) { + if (event.args) { + var index = event.args.index, + datarecord = productlist.records[index]; + record.beercode = datarecord.code; + record.beername = datarecord.name; + record.beeruuid = datarecord.uuid; + newProduct = true; + } + }); - // The chart button. - $("#FLog").jqxButton({ template: "primary", width: '150px', theme: theme }); - $("#FLog").click(function () { - window.open('log_co2pressure.php?code=' + record.beercode + '&name=' + record.beername); - }); + // The chart button. + $('#FLog').jqxButton({ template: 'primary', width: '150px', theme: theme }); + $('#FLog').click(function() { + window.open('log_co2pressure.php?code=' + record.beercode + '&name=' + record.beername); + }); }); diff -r 8bbc5730aaa8 -r 2991acd35cdb www/js/mon_fermenter.js --- a/www/js/mon_fermenter.js Fri Oct 18 20:49:07 2019 +0200 +++ b/www/js/mon_fermenter.js Sat Oct 19 12:17:29 2019 +0200 @@ -21,661 +21,656 @@ *****************************************************************************/ function createAbortElements() { - $('#eventWindow').jqxWindow({ - theme: theme, - position: { x: 440, y: 210 }, - width: 400, - height: 200, - resizable: false, - isModal: true, - modalOpacity: 0.4, - okButton: $('#delOk'), - cancelButton: $('#delCancel'), - initContent: function () { - $('#delOk').jqxButton({ template: "danger", width: '65px', theme: theme }); - $('#delCancel').jqxButton({ template: "success", width: '65px', theme: theme }); - $('#delCancel').focus(); - } - }); - $('#eventWindow').jqxWindow('hide'); + $('#eventWindow').jqxWindow({ + theme: theme, + position: { x: 440, y: 210 }, + width: 400, + height: 200, + resizable: false, + isModal: true, + modalOpacity: 0.4, + okButton: $('#delOk'), + cancelButton: $('#delCancel'), + initContent: function() { + $('#delOk').jqxButton({ template: 'danger', width: '65px', theme: theme }); + $('#delCancel').jqxButton({ template: 'success', width: '65px', theme: theme }); + $('#delCancel').focus(); + } + }); + $('#eventWindow').jqxWindow('hide'); } -$(document).ready(function () { +$(document).ready(function() { + + var record = {}, + blank = {}, + ppayload = '', + newBase = false, + newProduct = false, + newSwitch = false, + newProfile = false, + schedule = 0, + yl = 12, // Normal yeast temp range + yh = 24, - var record = {}, - blank = {}, - ppayload = '', - newBase = false, - newProduct = false, - newSwitch = false, - newProfile = false, - schedule = 0, - yl = 12, // Normal yeast temp range - yh = 24, + productSource = { + datatype: 'json', + cache: false, + datafields: [ + { name: 'code', type: 'string' }, + { name: 'name', type: 'string' }, + { name: 'uuid', type: 'string' }, + { name: 'stage', type: 'int' }, + { name: 'yeast_lo', type: 'float' }, + { name: 'yeast_hi', type: 'float' } + ], + id: 'code', + url: 'includes/db_product.php?select=ferment' + }, + productlist = new $.jqx.dataAdapter(productSource, { + beforeLoadComplete: function(records) { + var row, i, data = new Array(); + // Create a dummy beer on top to store in idle fermenters. + blank['code'] = 'Free'; // Will override this later. + blank['name'] = 'Dummy'; + blank['uuid'] = '66ecccbf-e942-4a35-af49-8b02314561a5'; + blank['stage'] = 10; + blank['yeast_lo'] = 12.0; + blank['yeast_hi'] = 24.0; + data.push(blank); + for (i = 0; i < records.length; i++) { + row = records[i]; + data.push(row); + } + return data; + }, + loadError: function(jqXHR, status, error) { + $('#err').text(status + ' ' + error); + }, + }), + profileSource = { + datatype: 'json', + cache: false, + datafields: [ + { name: 'record', type: 'int' }, + { name: 'uuid', type: 'string' }, + { name: 'name', type: 'string' }, + { name: 'inittemp_lo', type: 'float' }, + { name: 'inittemp_hi', type: 'float' }, + { name: 'fridgemode', type: 'int' }, + { name: 'totalsteps', type: 'int' }, + { name: 'duration', type: 'int' }, + { name: 'steps', type: 'array' } + ], + id: 'record', + url: 'includes/db_profile_fermentation.php' + }, + profilelist = new $.jqx.dataAdapter(profileSource, { + beforeLoadComplete: function(records) { + var data = new Array(), + empty = {}, i, row; + // Create a dummy profile on top of the list. + empty['record'] = -1; + empty['uuid'] = ''; + empty['name'] = 'Wis profiel'; + empty['inittemp_lo'] = 20; + empty['inittemp_hi'] = 20; + empty['fridgemode'] = 0; + empty['totalsteps'] = 0; + empty['duration'] = 0; + empty['steps'] = '[]'; + data.push(empty); + for (i = 0; i < records.length; i++) { + row = records[i]; + data.push(row); + } + return data; + }, + loadError: function(jqXHR, status, error) { + $('#err').text(status + ' ' + error); + }, + }), + gaugeoptions = { + min: 0, max: 40, width: 375, height: 375, + ranges: [{ startValue: 0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, + { startValue: yl, endValue: yh, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, + { startValue: yh, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }], + ticksMinor: { interval: 1, size: '5%' }, + ticksMajor: { interval: 5, size: '9%' }, + labels: { interval: 5 }, + style: { fill: '#eeeeee', stroke: '#666666' }, + value: 0, + colorScheme: 'scheme05' + }, + gaugeSmalloptions = { + min: -15, max: 25, width: 190, height: 190, + ranges: [{ startValue: -15, endValue: 0, startWidth: 5, endWidth: 5, style: { fill: '#3399FF', stroke: '#3399FF' }}, + { startValue: 0, endValue: 10, startWidth: 5, endWidth: 5, style: { fill: '#00CC33', stroke: '#00CC33' }}, + { startValue: 10, endValue: 25, startWidth: 5, endWidth: 5, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }}], + ticksMinor: { interval: 1, size: '5%' }, + ticksMajor: { interval: 5, size: '9%' }, + labels: { interval: 5 }, + style: { fill: '#eeeeee', stroke: '#666666' }, + value: 0, + colorScheme: 'scheme05', + caption: { value: 'Koeler', position: 'bottom', offset: [0, 10] } + }, + switchoptions = { + height: 68, + width: 35, + onLabel: 'AAN', + offLabel: 'UIT', + theme: theme, + thumbSize: '50%', + orientation: 'vertical' + }, + targetoptions = { inputMode: 'simple', theme: theme, width: 70, min: 0, max: 40, decimalDigits: 1, spinButtons: true }, + url = 'getfermenter.php?uuid="' + my_uuid + '"', + source = { + datatype: 'json', + datafields: [ + { name: 'record', type: 'int' }, + { name: 'uuid', type: 'string' }, + { name: 'alias', type: 'string' }, + { name: 'node', type: 'string' }, + { name: 'online', type: 'int' }, + { name: 'beercode', type: 'string' }, + { name: 'beername', type: 'string' }, + { name: 'air_state', type: 'string' }, + { name: 'air_temperature', type: 'float' }, + { name: 'beer_state', type: 'string' }, + { name: 'beer_temperature', type: 'float' }, + { name: 'chiller_state', type: 'string' }, + { name: 'chiller_temperature', type: 'float' }, + { name: 'heater_state', type: 'int' }, + { name: 'heater_usage', type: 'int' }, + { name: 'cooler_state', type: 'int' }, + { name: 'cooler_usage', type: 'int' }, + { name: 'fan_state', type: 'int' }, + { name: 'fan_usage', type: 'int' }, + { name: 'light_address', type: 'string' }, + { name: 'light_state', type: 'int' }, + { name: 'light_usage', type: 'int' }, + { name: 'door_address', type: 'string' }, + { name: 'door_state', type: 'int' }, + { name: 'psu_address', type: 'string' }, + { name: 'psu_state', type: 'int' }, + { name: 'mode', type: 'string' }, + { name: 'alarm', type: 'int' }, + { name: 'setpoint_high', type: 'float' }, + { name: 'setpoint_low', type: 'float' }, + { name: 'profile_uuid', type: 'string' }, + { name: 'profile_name', type: 'string' }, + { name: 'profile_state', type: 'string' }, + { name: 'profile_percent', type: 'int' }, + { name: 'profile_inittemp_high', type: 'float' }, + { name: 'profile_inittemp_low', type: 'float' }, + { name: 'profile_steps', type: 'string' }, + { name: 'stage', type: 'string' }, + { name: 'beeruuid', type: 'string' }, + { name: 'yeast_lo', type: 'float' }, + { name: 'yeast_hi', type: 'float' }, + { name: 'webcam_url', type: 'string' }, + { name: 'webcam_light', type: 'int' } + ], + id: 'record', + url: url + }, + dataAdapter = new $.jqx.dataAdapter(source, { + loadComplete: function(records) { + record = dataAdapter.records[0]; + var range, oline = (record.online) ? 'On-line' : 'Off-line'; + $('#info_uuid').html(record.uuid); + $('#info_system').html(record.node + '/' + record.alias); + $('#info_online').html(oline); + $('#info_beer').html(record.beercode + ' - ' + record.beername); + $('#info_mode').jqxDropDownList('selectItem', record.mode); + $('#info_stage').jqxDropDownList('selectItem', record.stage); + $('#info_profile').html(record.profile_name); + blank['name'] = record.alias; + blank['code'] = record.alias.toUpperCase(); + blank['uuid'] = record.uuid; + if (record.profile_name == '') + $('#info_mode').jqxDropDownList('disableItem', 'PROFILE'); + else + $('#info_mode').jqxDropDownList('enableItem', 'PROFILE'); + $('#target_lo').val(record.setpoint_low); + $('#target_hi').val(record.setpoint_high); + if (record.online && ((record.mode == 'FRIDGE') || (record.mode == 'BEER'))) { + $('#target_lo').jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true }); + $('#target_hi').jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true }); + } else { + $('#target_lo').jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false }); + $('#target_hi').jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false }); + } + + if (record.online && record.door_address && (record.door_state != '0')) { + $('#fermenter_doorled').html('
Door'); + } else { + $('#fermenter_doorled').html('
Door'); + } + if (record.online && record.light_address && (record.light_state != '0')) { + $('#fermenter_lightled').html('
Light'); + } else { + $('#fermenter_lightled').html('
Light'); + } - productSource = { - datatype: "json", - cache: false, - datafields: [ - { name: 'code', type: 'string' }, - { name: 'name', type: 'string' }, - { name: 'uuid', type: 'string' }, - { name: 'stage', type: 'int' }, - { name: 'yeast_lo', type: 'float' }, - { name: 'yeast_hi', type: 'float' } - ], - id: 'code', - url: "includes/db_product.php?select=ferment" - }, - productlist = new $.jqx.dataAdapter(productSource, { - beforeLoadComplete: function (records) { - var row, i, data = new Array(); - // Create a dummy beer on top to store in idle fermenters. - blank['code'] = "Free"; // Will override this later. - blank['name'] = 'Dummy'; - blank['uuid'] = '66ecccbf-e942-4a35-af49-8b02314561a5'; - blank['stage'] = 10; - blank['yeast_lo'] = 12.0; - blank['yeast_hi'] = 24.0; - data.push(blank); - for (i = 0; i < records.length; i++) { - row = records[i]; - data.push(row); - } - return data; - }, - loadError: function(jqXHR, status, error) { - $('#err').text(status + ' ' + error); - }, - }), - profileSource = { - datatype: "json", - cache: false, - datafields: [ - { name: 'record', type: 'int' }, - { name: 'uuid', type: 'string' }, - { name: 'name', type: 'string' }, - { name: 'inittemp_lo', type: 'float' }, - { name: 'inittemp_hi', type: 'float' }, - { name: 'fridgemode', type: 'int' }, - { name: 'totalsteps', type: 'int' }, - { name: 'duration', type: 'int' }, - { name: 'steps', type: 'array' } - ], - id: 'record', - url: "includes/db_profile_fermentation.php" - }, - profilelist = new $.jqx.dataAdapter(profileSource, { - beforeLoadComplete: function (records) { - var data = new Array(), - empty = {}, i, row; - // Create a dummy profile on top of the list. - empty['record'] = -1; - empty['uuid'] = ''; - empty['name'] = 'Wis profiel'; - empty['inittemp_lo'] = 20; - empty['inittemp_hi'] = 20; - empty['fridgemode'] = 0; - empty['totalsteps'] = 0; - empty['duration'] = 0; - empty['steps'] = '[]'; - data.push(empty); - for (i = 0; i < records.length; i++) { - row = records[i]; - data.push(row); - } - return data; - }, - loadError: function(jqXHR, status, error) { - $('#err').text(status + ' ' + error); - }, - }), - gaugeoptions = { - min: 0, max: 40, width: 375, height: 375, - ranges: [{ startValue: 0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, - { startValue: yl, endValue: yh, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, - { startValue: yh, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }], - ticksMinor: { interval: 1, size: '5%' }, - ticksMajor: { interval: 5, size: '9%' }, - labels: { interval: 5 }, - style: { fill: '#eeeeee', stroke: '#666666' }, - value: 0, - colorScheme: 'scheme05' - }, - gaugeSmalloptions = { - min: -15, max: 25, width: 190, height: 190, - ranges: [{ startValue: -15, endValue: 0, startWidth: 5, endWidth: 5, style: { fill: '#3399FF', stroke: '#3399FF' }}, - { startValue: 0, endValue: 10, startWidth: 5, endWidth: 5, style: { fill: '#00CC33', stroke: '#00CC33' }}, - { startValue: 10, endValue: 25, startWidth: 5, endWidth: 5, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }}], - ticksMinor: { interval: 1, size: '5%' }, - ticksMajor: { interval: 5, size: '9%' }, - labels: { interval: 5 }, - style: { fill: '#eeeeee', stroke: '#666666' }, - value: 0, - colorScheme: 'scheme05', - caption: { value: 'Chiller', position: 'bottom', offset: [0, 10] } - }, - switchoptions = { - height: 68, - width: 35, - onLabel:'AAN', - offLabel:'UIT', - theme: theme, - thumbSize:'50%', - orientation: 'vertical' - }, - targetoptions = { inputMode: 'simple', theme: theme, width: 70, min: 0, max: 40, decimalDigits: 1, spinButtons: true }, - url = "getfermenter.php?uuid='" + my_uuid + "'", - source = { - datatype: "json", - datafields: [ - { name: 'record', type: 'int' }, - { name: 'uuid', type: 'string' }, - { name: 'alias', type: 'string' }, - { name: 'node', type: 'string' }, - { name: 'online', type: 'int' }, - { name: 'beercode', type: 'string' }, - { name: 'beername', type: 'string' }, - { name: 'air_state', type: 'string' }, - { name: 'air_temperature', type: 'float' }, - { name: 'beer_state', type: 'string' }, - { name: 'beer_temperature', type: 'float' }, - { name: 'chiller_state', type: 'string' }, - { name: 'chiller_temperature', type: 'float' }, - { name: 'heater_state', type: 'int' }, - { name: 'heater_usage', type: 'int' }, - { name: 'cooler_state', type: 'int' }, - { name: 'cooler_usage', type: 'int' }, - { name: 'fan_state', type: 'int' }, - { name: 'fan_usage', type: 'int' }, - { name: 'light_address', type: 'string' }, - { name: 'light_state', type: 'int' }, - { name: 'light_usage', type: 'int' }, - { name: 'door_address', type: 'string' }, - { name: 'door_state', type: 'int' }, - { name: 'psu_address', type: 'string' }, - { name: 'psu_state', type: 'int' }, - { name: 'mode', type: 'string' }, - { name: 'alarm', type: 'int' }, - { name: 'setpoint_high', type: 'float' }, - { name: 'setpoint_low', type: 'float' }, - { name: 'profile_uuid', type: 'string' }, - { name: 'profile_name', type: 'string' }, - { name: 'profile_state', type: 'string' }, - { name: 'profile_percent', type: 'int' }, - { name: 'profile_inittemp_high', type: 'float' }, - { name: 'profile_inittemp_low', type: 'float' }, - { name: 'profile_steps', type: 'string' }, - { name: 'stage', type: 'string' }, - { name: 'beeruuid', type: 'string' }, - { name: 'yeast_lo', type: 'float' }, - { name: 'yeast_hi', type: 'float' }, - { name: 'webcam_url', type: 'string' }, - { name: 'webcam_light', type: 'int' } - ], - id: 'record', - url: url - }, - dataAdapter = new $.jqx.dataAdapter(source, { - loadComplete: function (records) { - record = dataAdapter.records[0]; - var range, oline = (record.online) ? "On-line" : "Off-line"; - $("#info_uuid").html(record.uuid); - $("#info_system").html(record.node + "/" + record.alias); - $("#info_online").html(oline); - $("#info_beer").html(record.beercode + " - " + record.beername); - $("#info_mode").jqxDropDownList('selectItem', record.mode); - $("#info_stage").jqxDropDownList('selectItem', record.stage); - $("#info_profile").html(record.profile_name); - blank['name'] = record.alias; - blank['code'] = record.alias.toUpperCase(); - blank['uuid'] = record.uuid; - if (record.profile_name == "") - $("#info_mode").jqxDropDownList('disableItem', "PROFILE"); - else - $("#info_mode").jqxDropDownList('enableItem', "PROFILE"); - $("#target_lo").val(record.setpoint_low); - $("#target_hi").val(record.setpoint_high); - if (record.online && ((record.mode == "FRIDGE") || (record.mode == "BEER"))) { - $("#target_lo").jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true }); - $("#target_hi").jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true }); - } else { - $("#target_lo").jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false }); - $("#target_hi").jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false }); - } + if (record.online && (record.mode != 'OFF')) { + $('#fermenter_powerled').html('
Power'); + $('#select_beer').jqxDropDownList({ disabled: true }); + $('#select_beer').jqxDropDownList('clearSelection'); + $('#select_beer').hide(); + } else { + $('#fermenter_powerled').html('
Power'); + $('#select_beer').show(); + $('#select_beer').jqxDropDownList({ disabled: false }); + } + if (record.online && (record.alarm != '0')) { + $('#fermenter_alarmled').html('
Alarm'); + } else { + $('#fermenter_alarmled').html('
Alarm'); + } + + if (record.online && (record.heater_state != '0')) { + $('#fermenter_led1').html('
Heat'); + } else { + $('#fermenter_led1').html('
Heat'); + } + if (record.online && (record.cooler_state != '0')) { + $('#fermenter_led2').html('
Cool'); + } else { + $('#fermenter_led2').html('
Cool'); + } + if (record.online && (record.fan_state != '0')) { + $('#fermenter_led3').html('
Fan'); + } else { + $('#fermenter_led3').html('
Fan'); + } + if (record.online && (record.mode == 'NONE')) { + $('#fermenter_toggle1').jqxSwitchButton('enable'); + $('#fermenter_toggle2').jqxSwitchButton('enable'); + $('#fermenter_toggle3').jqxSwitchButton('enable'); + } else { + $('#fermenter_toggle1').jqxSwitchButton('disable'); + $('#fermenter_toggle2').jqxSwitchButton('disable'); + $('#fermenter_toggle3').jqxSwitchButton('disable'); + $('#fermenter_toggle1').val(record.heater_state != '0'); + $('#fermenter_toggle2').val(record.cooler_state != '0'); + $('#fermenter_toggle3').val(record.fan_state != '0'); + } + + if (record.online && (record.mode == 'PROFILE')) { + if (record.profile_state == 'OFF') { + $('#select_profile').show(); + $('#select_profile').jqxDropDownList({ disabled: false }); + $('#info_mode').jqxDropDownList({ disabled: false }); + $('#Profile1').jqxButton({ template: 'success', value: 'Starten' }); + $('#Profile1').show(); + $('#Profile2').hide(); + $('#status_profile').html(''); + } else if (record.profile_state == 'RUN') { + $('#select_profile').jqxDropDownList({ disabled: true }); + $('#select_profile').hide(); + $('#info_mode').jqxDropDownList({ disabled: true }); + $('#Profile1').jqxButton({ template: 'danger', value: 'Afbreken' }); + $('#Profile2').jqxButton({ template: 'primary', value: 'Pauze' }); + $('#Profile1').show(); + $('#Profile2').show(); + $('#status_profile').html('Profiel actief, ' + record.profile_percent + '% gereed'); + } else if (record.profile_state == 'PAUSE') { + $('#select_profile').jqxDropDownList({ disabled: true }); + $('#select_profile').hide(); + $('#info_mode').jqxDropDownList({ disabled: true }); + $('#Profile1').jqxButton({ template: 'danger', value: 'Afbreken' }); + $('#Profile2').jqxButton({ template: 'success', value: 'Doorgaan' }); + $('#Profile1').show(); + $('#Profile2').show(); + $('#status_profile').html('Profiel pauze, ' + record.profile_percent + '% gereed'); + } else if (record.profile_state == 'DONE') { + $('#select_profile').jqxDropDownList({ disabled: true }); + $('#select_profile').hide(); + $('#info_mode').jqxDropDownList({ disabled: true }); + $('#Profile1').jqxButton({ template: 'primary', value: 'Profiel Ok' }); + $('#Profile1').show(); + $('#Profile2').hide(); + $('#status_profile').html('Profiel is gereed'); + } + } else { + $('#select_profile').show(); + $('#select_profile').jqxDropDownList({ disabled: false }); + $('#info_mode').jqxDropDownList({ disabled: false }); + $('#Profile1').hide(); + $('#Profile2').hide(); + $('#status_profile').html(''); + } + if (record.online && (record.webcam_url != '')) { + $('#Camera').show(); + } else { + $('#Camera').hide(); + } + + yl = record.yeast_lo; + yh = record.yeast_hi; + range = { ranges: [{ startValue: 0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, + { startValue: yl, endValue: yh, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, + { startValue: yh, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }]}; + $('#gaugeContainer_air').jqxGauge(range); + $('#gaugeContainer_beer').jqxGauge(range); - if (record.online && record.door_address && (record.door_state != "0")) { - $("#fermenter_doorled").html('
Door'); - } else { - $("#fermenter_doorled").html('
Door'); - } - if (record.online && record.light_address && (record.light_state != "0")) { - $("#fermenter_lightled").html('
Light'); - } else { - $("#fermenter_lightled").html('
Light'); - } - - if (record.online && (record.mode != "OFF")) { - $("#fermenter_powerled").html('
Power'); - $("#select_beer").jqxDropDownList({ disabled: true }); - $("#select_beer").jqxDropDownList('clearSelection'); - $("#select_beer").hide(); - } else { - $("#fermenter_powerled").html('
Power'); - $("#select_beer").show(); - $("#select_beer").jqxDropDownList({ disabled: false }); - } - if (record.online && (record.alarm != "0")) { - $("#fermenter_alarmled").html('
Alarm'); - } else { - $("#fermenter_alarmled").html('
Alarm'); - } + $('#gaugeContainer_air').jqxGauge({ caption: { value: 'Lucht: ' + record.air_temperature.toFixed(3) }}); + $('#gaugeContainer_air').jqxGauge({ value: record.air_temperature }); + if (record.air_state == 'OK') { + $('#gaugeContainer_air').jqxGauge({ disabled: false }); + } else { + $('#gaugeContainer_air').jqxGauge({ disabled: true }); + } + $('#gaugeContainer_beer').jqxGauge({ caption: { value: 'Bier: ' + record.beer_temperature.toFixed(3) }}); + $('#gaugeContainer_beer').jqxGauge({ value: record.beer_temperature }); + if (record.beer_state == 'OK') { + $('#gaugeContainer_beer').jqxGauge({ disabled: false }); + } else { + $('#gaugeContainer_beer').jqxGauge({ disabled: true }); + } + $('#gaugeContainer_chiller').jqxGauge({ value: record.chiller_temperature }); + if (record.chiller_state == 'OK') { + $('#gaugeContainer_chiller').jqxGauge({ disabled: false }); + } else { + $('#gaugeContainer_chiller').jqxGauge({ disabled: true }); + } + } + }); - if (record.online && (record.heater_state != "0")) { - $("#fermenter_led1").html('
Heat'); - } else { - $("#fermenter_led1").html('
Heat'); - } - if (record.online && (record.cooler_state != "0")) { - $("#fermenter_led2").html('
Cool'); - } else { - $("#fermenter_led2").html('
Cool'); - } - if (record.online && (record.fan_state != "0")) { - $("#fermenter_led3").html('
Fan'); - } else { - $("#fermenter_led3").html('
Fan'); - } - if (record.online && (record.mode == "NONE")) { - $("#fermenter_toggle1").jqxSwitchButton( 'enable' ); - $("#fermenter_toggle2").jqxSwitchButton( 'enable' ); - $("#fermenter_toggle3").jqxSwitchButton( 'enable' ); - } else { - $("#fermenter_toggle1").jqxSwitchButton( 'disable' ); - $("#fermenter_toggle2").jqxSwitchButton( 'disable' ); - $("#fermenter_toggle3").jqxSwitchButton( 'disable' ); - $("#fermenter_toggle1").val( (record.heater_state != "0") ); - $("#fermenter_toggle2").val( (record.cooler_state != "0") ); - $("#fermenter_toggle3").val( (record.fan_state != "0") ); - } + $('#select_beer').jqxDropDownList({ + placeHolder: 'Kies bier:', + theme: theme, + source: productlist, + displayMember: 'code', + width: 150, + height: 24, + dropDownWidth: 500, + autoDropDownHeight: true, + renderer: function(index, label, value) { + var datarecord = productlist.records[index]; + return datarecord.code + ' - ' + datarecord.name; + } + }); + $('#select_profile').jqxDropDownList({ + placeHolder: 'Kies profiel:', + theme: theme, + source: profilelist, + displayMember: 'name', + width: 150, + height: 24, + dropDownWidth: 500, + autoDropDownHeight: true, + }); + + $('#gaugeContainer_air').jqxGauge(gaugeoptions); + $('#gaugeContainer_air').jqxGauge({ caption: { value: 'Lucht: 00.000' }}); + $('#gaugeContainer_beer').jqxGauge(gaugeoptions); + $('#gaugeContainer_beer').jqxGauge({ caption: { value: 'Bier: 00.000' }}); + $('#gaugeContainer_chiller').jqxGauge(gaugeSmalloptions); + + $('#fermenter_toggle1').jqxSwitchButton(switchoptions); + $('#fermenter_toggle2').jqxSwitchButton(switchoptions); + $('#fermenter_toggle3').jqxSwitchButton(switchoptions); + + srcMode = ['OFF', 'NONE', 'FRIDGE', 'BEER', 'PROFILE']; + srcStage = ['PRIMARY', 'SECONDARY', 'TERTIARY', 'CARBONATION']; + $('#info_mode').jqxDropDownList({ theme: theme, source: srcMode, width: 100, height: 24, dropDownHeight: 156 }); + $('#info_stage').jqxDropDownList({ theme: theme, source: srcStage, width: 150, height: 24, dropDownHeight: 125 }); - if (record.online && (record.mode == "PROFILE")) { - if (record.profile_state == "OFF") { - $("#select_profile").show(); - $("#select_profile").jqxDropDownList({ disabled: false }); - $("#info_mode").jqxDropDownList({ disabled: false }); - $('#Profile1').jqxButton({ template: "success", value: "Starten" }); - $("#Profile1").show(); - $("#Profile2").hide(); - $("#status_profile").html(''); - } else if (record.profile_state == "RUN") { - $("#select_profile").jqxDropDownList({ disabled: true }); - $("#select_profile").hide(); - $("#info_mode").jqxDropDownList({ disabled: true }); - $('#Profile1').jqxButton({ template: "danger", value: "Afbreken" }); - $('#Profile2').jqxButton({ template: "primary", value: "Pauze" }); - $("#Profile1").show(); - $("#Profile2").show(); - $("#status_profile").html('Profiel actief, '+record.profile_percent+'% gereed'); - } else if (record.profile_state == "PAUSE") { - $("#select_profile").jqxDropDownList({ disabled: true }); - $("#select_profile").hide(); - $("#info_mode").jqxDropDownList({ disabled: true }); - $('#Profile1').jqxButton({ template: "danger", value: "Afbreken" }); - $('#Profile2').jqxButton({ template: "success", value: "Doorgaan" }); - $("#Profile1").show(); - $("#Profile2").show(); - $("#status_profile").html('Profiel pauze, '+record.profile_percent+'% gereed'); - } else if (record.profile_state == "DONE") { - $("#select_profile").jqxDropDownList({ disabled: true }); - $("#select_profile").hide(); - $("#info_mode").jqxDropDownList({ disabled: true }); - $('#Profile1').jqxButton({ template: "primary", value: "Profiel Ok" }); - $("#Profile1").show(); - $("#Profile2").hide(); - $("#status_profile").html('Profiel is gereed'); - } - } else { - $("#select_profile").show(); - $("#select_profile").jqxDropDownList({ disabled: false }); - $("#info_mode").jqxDropDownList({ disabled: false }); - $("#Profile1").hide(); - $("#Profile2").hide(); - $("#status_profile").html(''); - } - if (record.online && (record.webcam_url != "")) { - $("#Camera").show(); - } else { - $("#Camera").hide(); - } + $('#target_lo').jqxNumberInput(targetoptions); + $('#target_hi').jqxNumberInput(targetoptions); + + $('#Profile1').jqxButton({ template: 'info', width: '150px', height: 24, theme: theme }); + $('#Profile2').jqxButton({ template: 'info', width: '150px', height: 24, theme: theme }); + $('#Profile1').hide(); // Hide these until they are needed. + $('#Profile2').hide(); + + function sendBase(stage, mode, tlo, thi) { + + console.log('sendBase(' + stage + ', ' + mode + ', ' + tlo + ', ' + thi + ')'); + var data = 'node=' + record.node + '&alias=' + record.alias + '&payload={"stage":"' + stage; + data += '","mode":"' + mode + '","setpoint":{"low":' + tlo + ',"high":' + thi + '}}'; + $.ajax({ + url: 'cmd_fermenter.php', + data: data, + type: 'POST', + success: function(data) {}, + error: function(jqXHR, textStatus, errorThrown) { console.log('sendBase() error'); } + }); + } + + function sendSwitch(sw1, sw2, sw3, sw4) { - yl = record.yeast_lo; - yh = record.yeast_hi; - range = { ranges: [{ startValue: 0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, - { startValue: yl, endValue: yh, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, - { startValue: yh, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }] }; - $("#gaugeContainer_air").jqxGauge( range ); - $("#gaugeContainer_beer").jqxGauge( range ); + console.log('sendSwitch(' + sw1 + ', ' + sw2 + ', ' + sw3 + ', ' + sw4 + ')'); + var data = 'node=' + record.node + '&alias=' + record.alias + '&payload='; + data += '{"heater":{"state":' + sw1 + '},"cooler":{"state":' + sw2 + '},"fan":{"state":' + sw3 + '},"light":{"state":' + sw4 + '}}'; + $.ajax({ + url: 'cmd_fermenter.php', + data: data, + type: 'POST', + success: function(data) {}, + error: function(jqXHR, textStatus, errorThrown) { console.log('sendSwitch() error'); } + }); + } + + function sendProduct(code, name, uuid, yeast_lo, yeast_hi) { - $("#gaugeContainer_air").jqxGauge({ caption: { value: 'Air: '+record.air_temperature.toFixed(3) }}); - $('#gaugeContainer_air').jqxGauge({ value: record.air_temperature }); - if (record.air_state == "OK") { - $("#gaugeContainer_air").jqxGauge({ disabled: false }); - } else { - $("#gaugeContainer_air").jqxGauge({ disabled: true }); - } - $("#gaugeContainer_beer").jqxGauge({ caption: { value: 'Beer: '+record.beer_temperature.toFixed(3) }}); - $('#gaugeContainer_beer').jqxGauge({ value: record.beer_temperature }); - if (record.beer_state == "OK") { - $("#gaugeContainer_beer").jqxGauge({ disabled: false }); - } else { - $("#gaugeContainer_beer").jqxGauge({ disabled: true }); - } - $("#gaugeContainer_chiller").jqxGauge({ value: record.chiller_temperature }); - if (record.chiller_state == "OK") { - $("#gaugeContainer_chiller").jqxGauge({ disabled: false }); - } else { - $("#gaugeContainer_chiller").jqxGauge({ disabled: true }); - } - } - }); + console.log('sendProduct(' + code + ', ' + name + ', ' + uuid + ', ' + yeast_lo + ', ' + yeast_hi + ')'); + var data = 'node=' + record.node + '&alias=' + record.alias + '&payload='; + data += '{"product":{"code":"' + code + '","name":"' + name + '","uuid":"' + uuid + '","yeast_lo":' + yeast_lo + ',"yeast_hi":' + yeast_hi + '}}'; + $.ajax({ + url: 'cmd_fermenter.php', + data: data, + type: 'POST', + success: function(data) {}, + error: function(jqXHR, textStatus, errorThrown) { console.log('sendProduct() error'); } + }); + } + + function sendProfile(payload) { + + console.log('sendProfile(' + payload + ')'); + var data = 'node=' + record.node + '&alias=' + record.alias + '&payload=' + payload; + $.ajax({ + url: 'cmd_fermenter.php', + data: data, + type: 'POST', + success: function(data) {}, + error: function(jqXHR, textStatus, errorThrown) { console.log('sendProfile() error'); } + }); + } - - - - - $("#select_beer").jqxDropDownList({ - placeHolder: "Kies bier:", - theme: theme, - source: productlist, - displayMember: "code", - width: 150, - height: 24, - dropDownWidth: 500, - autoDropDownHeight: true, - renderer: function (index, label, value) { - var datarecord = productlist.records[index]; - return datarecord.code + " - " + datarecord.name; - } - }); - $("#select_profile").jqxDropDownList({ - placeHolder: "Kies profiel:", - theme: theme, - source: profilelist, - displayMember: "name", - width: 150, - height: 24, - dropDownWidth: 500, - autoDropDownHeight: true, - }); + // Get the data immediatly and then at regular intervals to refresh. + dataAdapter.dataBind(); + setInterval(function() { + var skip = false; + if (newBase) { + sendBase(record.stage, record.mode, record.setpoint_low, record.setpoint_high); + newBase = false; + skip = true; + } + if (newSwitch) { + sendSwitch(record.heater_state, record.cooler_state, record.fan_state, record.light_state); + newSwitch = false; + skip = true; + } + if (newProduct) { + sendProduct(record.beercode, record.beername, record.beeruuid, record.yeast_lo, record.yeast_hi); + newProduct = false; + skip = true; + } + if (newProfile) { + sendProfile(ppayload); + newProfile = false; + skip = true; + } + if (skip) { + schedule = 4; // 2 seconds wait to get the results + } else { + if (schedule > 0) + schedule--; + } - $("#gaugeContainer_air").jqxGauge( gaugeoptions ); - $("#gaugeContainer_air").jqxGauge( { caption: { value: 'Air: 00.000' }} ); - $("#gaugeContainer_beer").jqxGauge( gaugeoptions ); - $("#gaugeContainer_beer").jqxGauge( { caption: { value: 'Beer: 00.000' }} ); - $("#gaugeContainer_chiller").jqxGauge( gaugeSmalloptions ); - - $("#fermenter_toggle1").jqxSwitchButton( switchoptions ); - $("#fermenter_toggle2").jqxSwitchButton( switchoptions ); - $("#fermenter_toggle3").jqxSwitchButton( switchoptions ); - - srcMode = [ "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" ]; - srcStage = [ "PRIMARY", "SECONDARY", "TERTIARY", "CARBONATION" ]; - $("#info_mode").jqxDropDownList({ theme: theme, source: srcMode, width: 100, height: 24, dropDownHeight: 156 }); - $("#info_stage").jqxDropDownList({ theme: theme, source: srcStage, width: 150, height: 24, dropDownHeight: 125 }); - - $("#target_lo").jqxNumberInput( targetoptions ); - $("#target_hi").jqxNumberInput( targetoptions ); - - $("#Profile1").jqxButton({ template: "info", width: '150px', height: 24, theme: theme }); - $("#Profile2").jqxButton({ template: "info", width: '150px', height: 24, theme: theme }); - $("#Profile1").hide(); // Hide these until they are needed. - $("#Profile2").hide(); - - function sendBase(stage, mode, tlo, thi) { - - console.log("sendBase("+stage+", "+mode+", "+tlo+", "+thi+")"); - var data = 'node=' + record.node + '&alias=' + record.alias + '&payload={"stage":"' + stage; - data += '","mode":"' + mode + '","setpoint":{"low":' + tlo + ',"high":' + thi + '}}'; - $.ajax({ - url: "cmd_fermenter.php", - data: data, - type: "POST", - success: function(data) {}, - error: function(jqXHR, textStatus, errorThrown) { console.log("sendBase() error"); } - }); - } - - function sendSwitch(sw1, sw2, sw3, sw4) { + if (schedule <= 0) { + dataAdapter.dataBind(); + schedule = 20; + } + }, 500); - console.log("sendSwitch("+sw1+", "+sw2+", "+sw3+", "+sw4+")"); - var data = 'node='+record.node+'&alias='+record.alias+'&payload='; - data += '{"heater":{"state":'+sw1+'},"cooler":{"state":'+sw2+'},"fan":{"state":'+sw3+'},"light":{"state":'+sw4+'}}'; - $.ajax({ - url: "cmd_fermenter.php", - data: data, - type: "POST", - success: function(data) {}, - error: function(jqXHR, textStatus, errorThrown) { console.log("sendSwitch() error"); } - }); - } - - function sendProduct(code, name, uuid, yeast_lo, yeast_hi) { - - console.log("sendProduct("+code+", "+name+", "+uuid+", "+yeast_lo+", "+yeast_hi+")"); - var data = 'node='+record.node+'&alias='+record.alias+'&payload='; - data += '{"product":{"code":"'+code+'","name":"'+name+'","uuid":"'+uuid+'","yeast_lo":'+yeast_lo+',"yeast_hi":'+yeast_hi+'}}'; - $.ajax({ - url: "cmd_fermenter.php", - data: data, - type: "POST", - success: function(data) {}, - error: function(jqXHR, textStatus, errorThrown) { console.log("sendProduct() error"); } - }); - } - - function sendProfile(payload) { - - console.log("sendProfile("+payload+")"); - var data = 'node='+record.node+'&alias='+record.alias+'&payload='+payload; - $.ajax({ - url: "cmd_fermenter.php", - data: data, - type: "POST", - success: function(data) {}, - error: function(jqXHR, textStatus, errorThrown) { console.log("sendProfile() error"); } - }); - } - - - // Get the data immediatly and then at regular intervals to refresh. - dataAdapter.dataBind(); - setInterval(function() { - var skip = false; - if (newBase) { - sendBase(record.stage, record.mode, record.setpoint_low, record.setpoint_high); - newBase = false; - skip = true; - } - if (newSwitch) { - sendSwitch(record.heater_state, record.cooler_state, record.fan_state, record.light_state); - newSwitch = false; - skip = true; - } - if (newProduct) { - sendProduct(record.beercode, record.beername, record.beeruuid, record.yeast_lo, record.yeast_hi); - newProduct = false; - skip = true; - } - if (newProfile) { - sendProfile(ppayload); - newProfile = false; - skip = true; - } - if (skip) { - schedule = 4; // 2 seconds wait to get the results - } else { - if (schedule > 0) - schedule--; - } - - if (schedule <= 0) { - dataAdapter.dataBind(); - schedule = 20; - } - }, 500); + $('#info_mode').on('change', function(event) { + var args = event.args; + if (args) { + record.mode = args.item.value; + $('#fermenter_toggle1').val(0); + $('#fermenter_toggle2').val(0); + $('#fermenter_toggle3').val(0); + } + newBase = true; + }); + $('#info_stage').on('select', function(event) { + var args = event.args; + if (args) + record.stage = args.item.value; + newBase = true; + }); + $('#select_beer').on('select', function(event) { + if (event.args) { + var index = event.args.index, + datarecord = productlist.records[index]; + record.beercode = datarecord.code; + record.beername = datarecord.name; + record.beeruuid = datarecord.uuid; + record.yeast_lo = datarecord.yeast_lo; + record.yeast_hi = datarecord.yeast_hi; + newProduct = true; + } + }); + $('#select_profile').on('select', function(event) { + if (event.args) { + var index = event.args.index, + datarecord = profilelist.records[index], + row, i; + if (datarecord.record == -1) { + ppayload = '{"profile":null}'; + } else { + ppayload = '{"profile":{"uuid":"' + datarecord.uuid + '","name":"' + datarecord.name + '",'; + ppayload += '"inittemp":{"low":' + datarecord.inittemp_lo + ',"high":' + datarecord.inittemp_hi + '},'; + ppayload += '"fridgemode":' + datarecord.fridgemode + ',"steps":['; + for (i = 0; i < datarecord.steps.length; i++) { + row = datarecord.steps[i]; + if (i > 0) + ppayload += ','; + ppayload += '{"steptime":' + row['steptime'] + ',"resttime":' + row['resttime']; + ppayload += ',"target_lo":' + row['target_lo'] + ',"target_hi":' + row['target_hi']; + ppayload += ',"fridgemode":' + row['fridgemode'] + ',"name":"' + row['name'] + '"}'; + } + ppayload += ']}}'; + } + newProfile = true; + } + }); - $('#info_mode').on('change', function (event) { - var args = event.args; - if (args) { - record.mode = args.item.value; - $("#fermenter_toggle1").val(0); - $("#fermenter_toggle2").val(0); - $("#fermenter_toggle3").val(0); - } - newBase = true; - }); - $('#info_stage').on('select', function (event) { - var args = event.args; - if (args) - record.stage = args.item.value; - newBase = true; - }); - $("#select_beer").on('select', function (event) { - if (event.args) { - var index = event.args.index, - datarecord = productlist.records[index]; - record.beercode = datarecord.code; - record.beername = datarecord.name; - record.beeruuid = datarecord.uuid; - record.yeast_lo = datarecord.yeast_lo; - record.yeast_hi = datarecord.yeast_hi; - newProduct = true; - } - }); - $("#select_profile").on('select', function (event) { - if (event.args) { - var index = event.args.index, - datarecord = profilelist.records[index], - row, i; - if (datarecord.record == -1) { - ppayload = '{"profile":null}'; - } else { - ppayload = '{"profile":{"uuid":"'+datarecord.uuid+'","name":"'+datarecord.name+'",'; - ppayload += '"inittemp":{"low":'+datarecord.inittemp_lo+',"high":'+datarecord.inittemp_hi+'},'; - ppayload += '"fridgemode":'+datarecord.fridgemode+',"steps":['; - for (i = 0; i < datarecord.steps.length; i++) { - row = datarecord.steps[i]; - if (i > 0) - ppayload += ','; - ppayload += '{"steptime":'+row['steptime']+',"resttime":'+row['resttime']; - ppayload += ',"target_lo":'+row['target_lo']+',"target_hi":'+row['target_hi']; - ppayload += ',"fridgemode":'+row['fridgemode']+',"name":"'+row['name']+'"}'; - } - ppayload += ']}}'; - } - newProfile = true; - } - }); - - $('#target_lo').on('change', function (event) { - record.setpoint_low = parseFloat(event.args.value); - // Keep the high target above the low. - if (record.setpoint_low > record.setpoint_high) { - record.setpoint_high = record.setpoint_low; - $("#target_hi").val(record.setpoint_high); - } - newBase = true; - }); - $('#target_hi').on('change', function (event) { - record.setpoint_high = parseFloat(event.args.value); - // Keep the low target below the high. - if (record.setpoint_high < record.setpoint_low) { - record.setpoint_low = record.setpoint_high; - $("#target_lo").val(record.setpoint_low); - } - newBase = true; - }); + $('#target_lo').on('change', function(event) { + record.setpoint_low = parseFloat(event.args.value); + // Keep the high target above the low. + if (record.setpoint_low > record.setpoint_high) { + record.setpoint_high = record.setpoint_low; + $('#target_hi').val(record.setpoint_high); + } + newBase = true; + }); + $('#target_hi').on('change', function(event) { + record.setpoint_high = parseFloat(event.args.value); + // Keep the low target below the high. + if (record.setpoint_high < record.setpoint_low) { + record.setpoint_low = record.setpoint_high; + $('#target_lo').val(record.setpoint_low); + } + newBase = true; + }); - $("#fermenter_toggle1").on('checked', function (event) { - if (record.mode == "NONE") { - record.heater_state = 0; - newSwitch = true; - } - }); - $("#fermenter_toggle1").on('unchecked', function (event) { - if (record.mode == "NONE") { - record.heater_state = 100; - record.cooler_state = 0; - $("#fermenter_toggle2").val(0); - newSwitch = true; - } - }); - $("#fermenter_toggle2").on('checked', function (event) { - if (record.mode == "NONE") { - record.cooler_state = 0; - newSwitch = true; - } - }); - $("#fermenter_toggle2").on('unchecked', function (event) { - if (record.mode == "NONE") { - record.cooler_state = 100; - record.heater_state = 0; - $("#fermenter_toggle1").val(0); - newSwitch = true; - } - }); - $("#fermenter_toggle3").on('checked', function (event) { - if (record.mode == "NONE") { - record.fan_state = 0; - newSwitch = true; - } - }); - $("#fermenter_toggle3").on('unchecked', function (event) { - if (record.mode == "NONE") { - record.fan_state = 100; - newSwitch = true; - } - }); - $("#Profile1").click(function () { - if (record.mode == "PROFILE") { - if (record.profile_state == "OFF") { - ppayload = '{"profile":{"command":"start"}}'; - newProfile = true; - } else if ((record.profile_state == "RUN") || (record.profile_state == "PAUSE")) { - // Open a popup to confirm this action. - $('#eventWindow').jqxWindow('open'); - $("#delOk").click(function () { - ppayload = '{"profile":{"command":"abort"}}'; - newProfile = true; - }); - } else if (record.profile_state == "DONE") { - ppayload = '{"profile":{"command":"done"}}'; - newProfile = true; - } - } - }); - $("#Profile2").click(function () { - if (record.mode == "PROFILE") { - if ((record.profile_state == "RUN") || (record.profile_state == "PAUSE")) { - ppayload = '{"profile":{"command":"pause"}}'; - newProfile = true; - } - } - }); + $('#fermenter_toggle1').on('checked', function(event) { + if (record.mode == 'NONE') { + record.heater_state = 0; + newSwitch = true; + } + }); + $('#fermenter_toggle1').on('unchecked', function(event) { + if (record.mode == 'NONE') { + record.heater_state = 100; + record.cooler_state = 0; + $('#fermenter_toggle2').val(0); + newSwitch = true; + } + }); + $('#fermenter_toggle2').on('checked', function(event) { + if (record.mode == 'NONE') { + record.cooler_state = 0; + newSwitch = true; + } + }); + $('#fermenter_toggle2').on('unchecked', function(event) { + if (record.mode == 'NONE') { + record.cooler_state = 100; + record.heater_state = 0; + $('#fermenter_toggle1').val(0); + newSwitch = true; + } + }); + $('#fermenter_toggle3').on('checked', function(event) { + if (record.mode == 'NONE') { + record.fan_state = 0; + newSwitch = true; + } + }); + $('#fermenter_toggle3').on('unchecked', function(event) { + if (record.mode == 'NONE') { + record.fan_state = 100; + newSwitch = true; + } + }); + $('#Profile1').click(function() { + if (record.mode == 'PROFILE') { + if (record.profile_state == 'OFF') { + ppayload = '{"profile":{"command":"start"}}'; + newProfile = true; + } else if ((record.profile_state == 'RUN') || (record.profile_state == 'PAUSE')) { + // Open a popup to confirm this action. + $('#eventWindow').jqxWindow('open'); + $('#delOk').click(function() { + ppayload = '{"profile":{"command":"abort"}}'; + newProfile = true; + }); + } else if (record.profile_state == 'DONE') { + ppayload = '{"profile":{"command":"done"}}'; + newProfile = true; + } + } + }); + $('#Profile2').click(function() { + if (record.mode == 'PROFILE') { + if ((record.profile_state == 'RUN') || (record.profile_state == 'PAUSE')) { + ppayload = '{"profile":{"command":"pause"}}'; + newProfile = true; + } + } + }); - // The chart button. - $("#FLog").jqxButton({ template: "primary", width: '150px', theme: theme }); - $("#FLog").click(function () { - window.open('log_fermentation.php?code=' + record.beercode + '&name=' + record.beername); - }); - $("#Camera").jqxButton({ template: "primary", width: '150px', theme: theme }); - $("#Camera").click(function () { - record.light_state = 100; - newSwitch = true; - window.open(record.webcam_url); - }); - createAbortElements(); + // The chart button. + $('#FLog').jqxButton({ template: 'primary', width: '150px', theme: theme }); + $('#FLog').click(function() { + window.open('log_fermentation.php?code=' + record.beercode + '&name=' + record.beername); + }); + $('#Camera').jqxButton({ template: 'primary', width: '150px', theme: theme }); + $('#Camera').click(function() { + record.light_state = 100; + newSwitch = true; + window.open(record.webcam_url); + }); + createAbortElements(); }); diff -r 8bbc5730aaa8 -r 2991acd35cdb www/js/mon_node.js --- a/www/js/mon_node.js Fri Oct 18 20:49:07 2019 +0200 +++ b/www/js/mon_node.js Sat Oct 19 12:17:29 2019 +0200 @@ -21,76 +21,76 @@ *****************************************************************************/ -$(document).ready(function () { +$(document).ready(function() { - var url = "getnode.php?uuid='" + my_uuid + "'", - source = { - datatype: "json", - datafields: [ - { name: 'record', type: 'int' }, - { name: 'uuid', type: 'string' }, - { name: 'node', type: 'string' }, - { name: 'online', type: 'bool' }, - { name: 'group_id', type: 'string' }, - { name: 'hardwaremake', type: 'string' }, - { name: 'hardwaremodel', type: 'string' }, - { name: 'os', type: 'string' }, - { name: 'os_version', type: 'string' }, - { name: 'firmware', type: 'string' }, - { name: 'firstseen', type: 'string' }, - { name: 'lastseen', type: 'string' }, - { name: 'temperature', type: 'float' }, - { name: 'humidity', type: 'float' }, - { name: 'barometer', type: 'float' }, - { name: 'gps_latitude', type: 'float' }, - { name: 'gps_longitude', type: 'float' }, - { name: 'gps_altitude', type: 'float' }, - { name: 'net_address', type: 'string' }, - { name: 'net_ifname', type: 'string' }, - { name: 'net_rssi', type: 'int' } - ], - id: 'record', - url: url - }, - dataAdapter = new $.jqx.dataAdapter(source, { - loadComplete: function (records) { - var record = dataAdapter.records[0], - html = "
"; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - if (record.online) { - html += ""; - if (record.humidity > 0) { - html += ""; - } - if (record.barometer > 0) { - html += ""; - } - if ((record.gps_latitude != 0) && (record.gps_longitude != 0)) { - html += ""; - } - html += ""; - } - html += ""; - html += ""; - $("#ContentPanel").html(html); - } - }); + var url = 'getnode.php?uuid="' + my_uuid + '"', + source = { + datatype: 'json', + datafields: [ + { name: 'record', type: 'int' }, + { name: 'uuid', type: 'string' }, + { name: 'node', type: 'string' }, + { name: 'online', type: 'bool' }, + { name: 'group_id', type: 'string' }, + { name: 'hardwaremake', type: 'string' }, + { name: 'hardwaremodel', type: 'string' }, + { name: 'os', type: 'string' }, + { name: 'os_version', type: 'string' }, + { name: 'firmware', type: 'string' }, + { name: 'firstseen', type: 'string' }, + { name: 'lastseen', type: 'string' }, + { name: 'temperature', type: 'float' }, + { name: 'humidity', type: 'float' }, + { name: 'barometer', type: 'float' }, + { name: 'gps_latitude', type: 'float' }, + { name: 'gps_longitude', type: 'float' }, + { name: 'gps_altitude', type: 'float' }, + { name: 'net_address', type: 'string' }, + { name: 'net_ifname', type: 'string' }, + { name: 'net_rssi', type: 'int' } + ], + id: 'record', + url: url + }, + dataAdapter = new $.jqx.dataAdapter(source, { + loadComplete: function(records) { + var record = dataAdapter.records[0], + html = '
'; + html += '
Systeem overzicht
Uuid" + record.uuid + "
Systeem" + record.node + "
Online" + record.online + "
Type" + record.group_id + "
Eerst gezien" + record.firstseen + "
Laatst gezien" + record.lastseen + "
Hardware maker" + record.hardwaremake+ "
Hardware model" + record.hardwaremodel+ "
OS" + record.os + " versie: " + record.os_version + "
Firmware" + record.firmware + "
Temperatuur" + record.temperature.toFixed(1) + "°C
Vochtigheid" + record.humidity.toFixed(1) + "%
Luchtdruk" + record.barometer.toFixed(0) + "
GPS"+ record.gps_latitude + " " + record.gps_longitude + " " + record.gps_altitude + "
Netwerk"+ record.net_ifname + " " + record.net_address + "
'; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + if (record.online) { + html += ''; + if (record.humidity > 0) { + html += ''; + } + if (record.barometer > 0) { + html += ''; + } + if ((record.gps_latitude != 0) && (record.gps_longitude != 0)) { + html += ''; + } + html += ''; + } + html += ''; + html += ''; + $('#ContentPanel').html(html); + } + }); - // Get the data immediatly and then at regular intervals to refresh. - dataAdapter.dataBind(); - setInterval(function(){ - dataAdapter.dataBind(); - }, 30000); + // Get the data immediatly and then at regular intervals to refresh. + dataAdapter.dataBind(); + setInterval(function() { + dataAdapter.dataBind(); + }, 30000); });
Systeem overzicht
Uuid' + record.uuid + '
Systeem' + record.node + '
Online' + record.online + '
Type' + record.group_id + '
Eerst gezien' + record.firstseen + '
Laatst gezien' + record.lastseen + '
Hardware maker' + record.hardwaremake + '
Hardware model' + record.hardwaremodel + '
OS' + record.os + ' versie: ' + record.os_version + '
Firmware' + record.firmware + '
Temperatuur' + record.temperature.toFixed(1) + '°C
Vochtigheid' + record.humidity.toFixed(1) + '%
Luchtdruk' + record.barometer.toFixed(0) + '
GPS' + record.gps_latitude + ' ' + record.gps_longitude + ' ' + record.gps_altitude + '
Netwerk' + record.net_ifname + ' ' + record.net_address + '