# HG changeset patch # User Michiel Broek # Date 1547148126 -3600 # Node ID 4c25db9e810205265d35413a97bbf8d93c02b31a # Parent 3dbe1d2265ed9b426f50639dd5c11f068622cfe0 Added configuration settings for MQTT in config.php. Finished screen box sizes for the fermenters monitor. Select beername and code from the current brew products and send it to the fermenter. Added switch commands to the fermenter. Delay data get from the fermenter after sending any command so there is time to process the commands. Turn switches off when the mode changes. Removed 0.2 degrees setpoint diffs for low and high, the fermenter must deal with it. Prevent turning the heater and cooler together on. diff -r 3dbe1d2265ed -r 4c25db9e8102 www/cmd_fermenter.php --- a/www/cmd_fermenter.php Wed Jan 09 16:19:26 2019 +0100 +++ b/www/cmd_fermenter.php Thu Jan 10 20:22:06 2019 +0100 @@ -1,4 +1,5 @@ diff -r 3dbe1d2265ed -r 4c25db9e8102 www/config.php.dist --- a/www/config.php.dist Wed Jan 09 16:19:26 2019 +0100 +++ b/www/config.php.dist Thu Jan 10 20:22:06 2019 +0100 @@ -3,7 +3,7 @@ /* * Check for development server */ -if ( strcmp($_SERVER['SERVER_NAME'], "seaport.mbse.ym") == 0) { +if (isset($_SERVER['SERVER_NAME']) && ( strcmp($_SERVER['SERVER_NAME'], "seaport.mbse.ym") == 0)) { define ('DBASE_NAME', 'bms_dev'); define ('DBASE_HOST', 'lx02'); @@ -13,6 +13,11 @@ define ('EMAIL_FROM', 'noreply@mbse.ym'); + define ('MQTT_HOST', 'localhost'); + define ('MQTT_PORT', 1883 ); + define ('MQTT_USER', 'mqtt_user' ); + define ('MQTT_PASS', 'mqtt_pass' ); + setlocale ( LC_TIME , 'nl_NL' ); } else { @@ -25,6 +30,11 @@ define ('EMAIL_FROM', 'noreply@mbse.ym'); + define ('MQTT_HOST', 'localhost'); + define ('MQTT_PORT', 1883 ); + define ('MQTT_USER', 'mqtt_user' ); + define ('MQTT_PASS', 'mqtt_pass' ); + setlocale ( LC_TIME , 'nl_NL' ); } diff -r 3dbe1d2265ed -r 4c25db9e8102 www/css/style.css --- a/www/css/style.css Wed Jan 09 16:19:26 2019 +0100 +++ b/www/css/style.css Thu Jan 10 20:22:06 2019 +0100 @@ -128,7 +128,7 @@ * +-------------------------------+ */ #fermenter_panel_top { - width: 280px; + width: 290px; height: 200px; float: right; margin: 5px; @@ -165,7 +165,7 @@ #fermenter_panel_display { - width: 280px; + width: 290px; height: 70px; float: right; margin: 5px; @@ -176,7 +176,7 @@ margin-bottom: 3px; } #fermenter_display { - width: 140px; + width: 145px; height: 70px; float: left; text-align: center; @@ -184,7 +184,7 @@ #fermenter_panel_control { - width: 280px; + width: 290px; height: 140px; float: right; margin: 5px; @@ -198,7 +198,7 @@ #fermenter_led1, #fermenter_led2, #fermenter_led3 { - width: 93px; + width: 96px; height: 30px; float: left; text-align: center; @@ -214,21 +214,20 @@ #fermenter_toggle2, #fermenter_toggle3 { float: left; - margin-left: 57px; + margin-left: 60px; margin-top: 20px; } #fermenter_panel_buttons { - width: 280px; - height: 130px; + width: 290px; + height: 155px; float: right; margin: 5px; background-color: #252526; border: 2px solid; border-color: #59b4d4; border-radius: 5px 5px 5px 5px; - margin-bottom: 3px; } diff -r 3dbe1d2265ed -r 4c25db9e8102 www/includes/db_product.php --- a/www/includes/db_product.php Wed Jan 09 16:19:26 2019 +0100 +++ b/www/includes/db_product.php Thu Jan 10 20:22:06 2019 +0100 @@ -335,6 +335,24 @@ } /* + * SELECT, produce a list of products that can be fermented. + */ + if (isset($_GET['select']) && ($_GET['select'] == "ferment")) { + $query = "SELECT code,name,stage FROM products WHERE "; + $query .= "stage='Wait' OR stage='Brew' OR stage='Primary' OR stage='Secondary' OR stage='Tertiary' OR stage='Carbonation' ORDER BY code;"; + $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $brews[] = array( + 'code' => $row['code'], + 'name' => $row['name'], + 'stage' => $row['stage'] + ); + } + echo json_encode($brews); + return; + } + + /* * Default, select all or a given record. */ if (isset($_GET['record'])) { diff -r 3dbe1d2265ed -r 4c25db9e8102 www/js/mon_fermenter.js --- a/www/js/mon_fermenter.js Wed Jan 09 16:19:26 2019 +0100 +++ b/www/js/mon_fermenter.js Thu Jan 10 20:22:06 2019 +0100 @@ -31,6 +31,33 @@ var yl = 12; // Normal yeast temp range var yh = 24; + var productSource = { + datatype: "json", + cache: false, + datafields: [ + { name: 'code', type: 'string' }, + { name: 'name', type: 'string' }, + { name: 'stage', type: 'string' }, + ], + id: 'code', + url: "includes/db_product.php?select=ferment" + }; + var productlist = new $.jqx.dataAdapter(productSource); + $("#select_beer").jqxDropDownList({ + placeHolder: "Kies bier:", + theme: theme, + source: productlist, + displayMember: "code", + width: 150, + height: 23, + dropDownWidth: 500, + autoDropDownHeight: true, + renderer: function (index, label, value) { + var datarecord = productlist.records[index]; + return datarecord.code + " - " + datarecord.name; + } + }); + var gaugeoptions = { min: 0, max: 40, width: 375, height: 375, ranges: [{ startValue: 0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, @@ -97,14 +124,50 @@ function sendBase(stage, mode, tlo, thi) { console.log("sendBase("+stage+", "+mode+", "+tlo+", "+thi+")"); - var data = 'node=rpi01&alias=unit0&payload={"stage":"'+stage; + 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) { - //do something after something is recieved from php + //do something after something is received from php + }, + error: function(jqXHR, textStatus, errorThrown) { + console.log("sendBase() error"); + } + }); + } + + function sendSwitch(sw1, sw2, sw3, sw4) { + + 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) { + //do something after something is received from php + }, + error: function(jqXHR, textStatus, errorThrown) { + console.log("sendBase() error"); + } + }); + } + + function sendProduct(code, name) { + + console.log("sendProduct("+code+", "+name+")"); + var data = 'node='+record.node+'&alias='+record.alias+'&payload='; + data += '{"product":{"code":"'+code+'","name":"'+name+'"}}'; + $.ajax({ + url: "cmd_fermenter.php", + data: data, + type: "POST", + success: function(data) { + //do something after something is received from php }, error: function(jqXHR, textStatus, errorThrown) { console.log("sendBase() error"); @@ -165,6 +228,11 @@ $("#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); + 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"))) { @@ -177,8 +245,11 @@ if (record.online && (record.mode != "OFF")) { $("#fermenter_powerled").html('
Power'); + $("#select_beer").jqxDropDownList({ disabled: true }); + $("#select_beer").jqxDropDownList('clearSelection'); } else { $("#fermenter_powerled").html('
Power'); + $("#select_beer").jqxDropDownList({ disabled: false }); } if (record.online && (record.alarm != "0")) { $("#fermenter_alarmled").html('
Alarm'); @@ -240,26 +311,55 @@ // 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; } - dataAdapter.dataBind(); + if (newSwitch) { + sendSwitch(record.heater_state, record.cooler_state, record.fan_state, record.light_state); + newSwitch = false; + skip = true; + } + if (newProduct) { + sendProduct(record.code, record.name); + newProduct = false; + skip = true; + } + + if (! skip) { + // Only if we didn't send a command so that a command can be processed. + dataAdapter.dataBind(); + } }, 10000); $('#info_mode').on('change', function (event) { record.mode = args.item.value; + $("#fermenter_toggle1").val(0); + $("#fermenter_toggle2").val(0); + $("#fermenter_toggle3").val(0); newBase = true; }); - $('#info_stage').on('change', function (event) { + $('#info_stage').on('select', function (event) { record.stage = args.item.value; newBase = true; }); + $("#select_beer").on('select', function (event) { + if (event.args) { + var index = event.args.index; + var datarecord = productlist.records[index]; + record.code = datarecord.code; + record.name = datarecord.name; + newProduct = 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 - 0.2)) { - record.setpoint_high = record.setpoint_low + 0.2; + if (record.setpoint_low > record.setpoint_high) { + record.setpoint_high = record.setpoint_low; $("#target_hi").val(record.setpoint_high); } newBase = true; @@ -267,13 +367,54 @@ $('#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 + 0.2)) { - record.setpoint_low = record.setpoint_high - 0.2; + 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; + } + }); + // The chart button. $("#FLog").jqxButton({ template: "info", width: '150px', theme: theme }); diff -r 3dbe1d2265ed -r 4c25db9e8102 www/mon_fermenter.php --- a/www/mon_fermenter.php Wed Jan 09 16:19:26 2019 +0100 +++ b/www/mon_fermenter.php Thu Jan 10 20:22:06 2019 +0100 @@ -9,12 +9,13 @@
- - - - - - + + + + + + +
Klimaatkast overzicht
Uuid
Systeem
Bier
Werking
Fase
Klimaatkast overzicht
Uuid
Systeem
Code en bier
Werking
Vergisting fase
Vergisting profiel
@@ -54,7 +55,7 @@
- +