Added beer selection in the CO2 meter screen. Added CO2 pressure logging.

Fri, 11 Oct 2019 21:04:48 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 11 Oct 2019 21:04:48 +0200
changeset 506
8ab0e87d579e
parent 505
c09b67fd8323
child 507
17f244137a9b

Added beer selection in the CO2 meter screen. Added CO2 pressure logging.

bmsd/bms.h file | annotate | diff | comparison | revisions
bmsd/co2meters.c file | annotate | diff | comparison | revisions
doc/bms-ch8.sgml file | annotate | diff | comparison | revisions
www/Makefile file | annotate | diff | comparison | revisions
www/cmd_co2meter.php file | annotate | diff | comparison | revisions
www/js/mon_co2meter-min.js file | annotate | diff | comparison | revisions
www/js/mon_co2meter.js file | annotate | diff | comparison | revisions
www/log_co2pressure.php file | annotate | diff | comparison | revisions
--- a/bmsd/bms.h	Fri Oct 11 13:38:31 2019 +0200
+++ b/bmsd/bms.h	Fri Oct 11 21:04:48 2019 +0200
@@ -273,6 +273,7 @@
 } sys_co2meter_list;
 
 
+
 /**
  * @brief Strcuture holding a co2 pressure log entry.
  */
@@ -283,9 +284,9 @@
     char			*product_name;		///< Product name
     float			temperature;		///< Temperature
     float			pressure;		///< Pressure
-    char			*co2meter_uuid;		///< Unit uuid
-    char			*co2meter_node;		///< Unit node
-    char			*co2meter_alias;	///< Unit alias
+    char			*uuid;			///< Unit uuid
+    char			*node;			///< Unit node
+    char			*alias;			///< Unit alias
 } co2pressure_log;
 
 
--- a/bmsd/co2meters.c	Fri Oct 11 13:38:31 2019 +0200
+++ b/bmsd/co2meters.c	Fri Oct 11 21:04:48 2019 +0200
@@ -33,6 +33,9 @@
 
 extern int		debug;
 extern sys_config       Config;
+extern MYSQL		*con;
+extern MYSQL_RES	*res_set;
+extern MYSQL_ROW	row;
 
 
 
@@ -211,7 +214,7 @@
 
 void co2meter_log(char *topic, char *payload)
 {
-    char                *edge_node, *alias, *line, buf[65], *logfile;
+    char                *edge_node, *alias, *line, buf[128], *logfile;
     struct json_object  *jobj, *val, *metric;
     co2pressure_log	*log;
     struct tm		*mytime;
@@ -227,8 +230,8 @@
     log = (co2pressure_log *)malloc(sizeof(co2pressure_log));
     memset(log, 0, sizeof(co2pressure_log));
 
-    log->co2meter_node = xstrcpy(edge_node);
-    log->co2meter_alias = xstrcpy(alias);
+    log->node = xstrcpy(edge_node);
+    log->alias = xstrcpy(alias);
     jobj = json_tokener_parse(payload);
 
     timestamp = time(NULL);
@@ -238,23 +241,9 @@
 	mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
 
     if (json_object_object_get_ex(jobj, "metric", &metric)) {
-
-/*	    if (json_object_object_get_ex(metric2, "uuid", &val)) {
-		if (strcmp((char *)"(null)", json_object_get_string(val)))
-		    log->product_uuid = xstrcpy((char *)json_object_get_string(val));
-	    }
-	    if (json_object_object_get_ex(metric2, "code", &val)) {
-		if (strcmp((char *)"(null)", json_object_get_string(val)))
-		    log->product_code = xstrcpy((char *)json_object_get_string(val));
-	    }
-	    if (json_object_object_get_ex(metric2, "name", &val)) {
-		if (strcmp((char *)"(null)", json_object_get_string(val)))
-		    log->product_name = xstrcpy((char *)json_object_get_string(val));
-	    }
-*/
-	if (json_object_object_get_ex(metric, "co2meter_uuid", &val)) {
+	if (json_object_object_get_ex(metric, "uuid", &val)) {
 	    if (strcmp((char *)"(null)", json_object_get_string(val)))
-	    	log->co2meter_uuid = xstrcpy((char *)json_object_get_string(val));
+	    	log->uuid = xstrcpy((char *)json_object_get_string(val));
 	}
 	if (json_object_object_get_ex(metric, "temperature", &val)) {
 	    log->temperature = json_object_get_double(val);
@@ -269,9 +258,21 @@
      * Because co2meters are not so smart and don't hold product information
      * search the missing pieces in the database.
      */
-    // log->co2meter_uuid is the search, fill:
-    // log->product_uuid log->product_name log->product_code
-    // log->co2meter_node log->co2meter_alias
+    snprintf(buf, 127, "SELECT beercode,beername,beeruuid FROM mon_co2meters WHERE uuid='%s'", log->uuid);
+    if (mysql_query(con, buf)) {
+        syslog(LOG_NOTICE, "MySQL: %s error %u (%s))", buf, mysql_errno(con), mysql_error(con));
+    } else {
+        res_set = mysql_store_result(con);
+        if (res_set == NULL) {
+            syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con));
+        } else {
+            if ((row = mysql_fetch_row(res_set)) != NULL) {
+		log->product_code = xstrcpy(row[0]);
+		log->product_name = xstrcpy(row[1]);
+		log->product_uuid = xstrcpy(row[2]);
+	    }
+	}
+    }
 
     /*
      * Build csv log line
@@ -284,7 +285,7 @@
     snprintf(buf, 64, "%.3f", log->pressure);
     line = xstrcat(line, buf);
     line = xstrcat(line, (char *)",");
-    line = xstrcat(line, log->co2meter_uuid);
+    line = xstrcat(line, log->uuid);
 
     /*
      * Build logfile name
@@ -320,12 +321,12 @@
 	free(log->product_code );
     if (log->product_name )
 	free(log->product_name );
-    if (log->co2meter_uuid)
-	free(log->co2meter_uuid);
-    if (log->co2meter_node)
-	free(log->co2meter_node);
-    if (log->co2meter_alias)
-	free(log->co2meter_alias);
+    if (log->uuid)
+	free(log->uuid);
+    if (log->node)
+	free(log->node);
+    if (log->alias)
+	free(log->alias);
     free(log);
 }
 
--- a/doc/bms-ch8.sgml	Fri Oct 11 13:38:31 2019 +0200
+++ b/doc/bms-ch8.sgml	Fri Oct 11 21:04:48 2019 +0200
@@ -319,25 +319,44 @@
 De bestandsnamen zijn <code>product_code\ product_name.log</code>.
 Het interne formaat is:</para>
 <programlisting>
-   2014-11-15 18:39,BEER,PRIMARY,20.312,19.750,-1.500,20.5,18.6,18.8,35,12345,0,67890,Whatsup,Fermenter
-            |         |     |      |      |      |      |    |    |   |   |   |   |      |        |
- 0 datetime +         |     |      |      |      |      |    |    |   |   |   |   |      |        |
- 1 werkwijze ---------+     |      |      |      |      |    |    |   |   |   |   |      |        |
- 2 vergisting fase ---------+      |      |      |      |    |    |   |   |   |   |      |        |
- 3 temperatuur lucht --------------+      |      |      |    |    |   |   |   |   |      |        |
- 4 temperatuur bier ----------------------+      |      |    |    |   |   |   |   |      |        |
- 5 temperatuur koeler ---------------------------+      |    |    |   |   |   |   |      |        |
- 6 temperatuur ruimte ----------------------------------+    |    |   |   |   |   |      |        |
- 7 instelwaarde laag ----------------------------------------+    |   |   |   |   |      |        |
- 8 instelwaarde hoog ---------------------------------------------+   |   |   |   |      |        |
- 9 verwarming vermogen -----------------------------------------------+   |   |   |      |        |
-10 verwarming verbruik ---------------------------------------------------+   |   |      |        |
-11 koeler vermogen -----------------------------------------------------------+   |      |        |
-12 koeler verbruik ---------------------------------------------------------------+      |        |
-13 gebeurtenis --------------------------------------------------------------------------+        |
-14 vergister uuid --------------------------------------------------------------------------------+
+   2014-11-15 18:39:12,BEER,PRIMARY,20.312,19.750,-1.500,20.5,18.6,18.8,35,12345,0,67890,Whatsup,Fermenter
+            |            |     |      |      |      |      |    |    |   |   |   |   |      |        |
+ 0 datetime +            |     |      |      |      |      |    |    |   |   |   |   |      |        |
+ 1 werkwijze ------------+     |      |      |      |      |    |    |   |   |   |   |      |        |
+ 2 vergisting fase ------------+      |      |      |      |    |    |   |   |   |   |      |        |
+ 3 temperatuur lucht -----------------+      |      |      |    |    |   |   |   |   |      |        |
+ 4 temperatuur bier -------------------------+      |      |    |    |   |   |   |   |      |        |
+ 5 temperatuur koeler ------------------------------+      |    |    |   |   |   |   |      |        |
+ 6 temperatuur ruimte -------------------------------------+    |    |   |   |   |   |      |        |
+ 7 instelwaarde laag -------------------------------------------+    |   |   |   |   |      |        |
+ 8 instelwaarde hoog ------------------------------------------------+   |   |   |   |      |        |
+ 9 verwarming vermogen --------------------------------------------------+   |   |   |      |        |
+10 verwarming verbruik ------------------------------------------------------+   |   |      |        |
+11 koeler vermogen --------------------------------------------------------------+   |      |        |
+12 koeler verbruik ------------------------------------------------------------------+      |        |
+13 gebeurtenis -----------------------------------------------------------------------------+        |
+14 vergister uuid -----------------------------------------------------------------------------------+
 </programlisting>
 </sect1>
 
+<sect1 id="payloadco2log">
+<title>Netwerk payload log formaat voor CO2 meters.</title>
+
+<para>
+De ontvangen CO2 log gegevens worden niet opgeslagen in de SQL database
+maar in platte tekst bestanden. Hierdoor is de gelogde informatie sneller toegankelijk.
+Ieder brouw product heeft zijn eigen bestand.
+De bestanden staan in <code>www/logs/co2pressure/</code>.
+De bestandsnamen zijn <code>product_code\ product_name.log</code>.
+Het interne formaat is:</para>
+<programlisting>
+   2019-10-11 16:13:33,22.250,5.964,c0ffeeee-dead-beef-caf0-3c71bffe4054
+            |            |      |                  |
+ 0 datetime +            |      |                  |
+ 1 temperatuur ----------+      |                  |
+ 2 CO2 flesdruk in bar ---------+                  |
+ 3 meter uuid -------------------------------------+
+</programlisting>
+</sect1>
 
 </chapter>
--- a/www/Makefile	Fri Oct 11 13:38:31 2019 +0200
+++ b/www/Makefile	Fri Oct 11 21:04:48 2019 +0200
@@ -3,14 +3,15 @@
 
 include ../Makefile.global
 
-SRC		= cmd_fermenter.php config.php.dist crontasks.php favicon.ico gen_about.php \
-		  getbrewlog.php getfermentablesources.php getfermenter.php getfermentlog.php \
-		  gethopsources.php getmiscsources.php getnode.php getwatersources.php \
-		  getyeastsources.php import_ingredients.php index.php \
+SRC		= cmd_fermenter.php cmd_co2meter.php \
+		  config.php.dist crontasks.php favicon.ico gen_about.php \
+		  getbrewlog.php getco2meter.php getfermentablesources.php getfermenter.php \
+		  getfermentlog.php gethopsources.php getmiscsources.php getnode.php \
+		  getwatersources.php getyeastsources.php import_ingredients.php index.php \
 		  inv_equipments.php inv_fermentables.php inv_hops.php inv_instock.php \
 		  inv_miscs.php inv_suppliers.php inv_waters.php inv_yeasts.php \
-		  log_brew.php log_fermentation.php \
-		  mon_brewer.php mon_fermenter.php mon_node.php \
+		  log_brew.php log_co2pressure.php log_fermentation.php \
+		  mon_brewer.php mon_co2meter.php mon_fermenter.php mon_node.php \
 		  prod_archive_code.php prod_archive_date.php prod_archive_name.php prod_beerxml.php \
 		  prod_checklist.php prod_divide.php prod_duplicate.php prod_edit.php prod_export.php prod_forum.php \
 		  prod_impbrew.php prod_inprod.php prod_new.php prod_print.php prod_torecipe.php \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/cmd_co2meter.php	Fri Oct 11 21:04:48 2019 +0200
@@ -0,0 +1,24 @@
+<?php
+require_once('config.php');
+
+#Connect to the database
+$connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
+if (! $connect) {
+        die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
+}
+mysqli_set_charset($connect, "utf8" );
+
+$sql  = "UPDATE `mon_co2meters` SET ";
+$sql .=    "beername='" . mysqli_real_escape_string($connect, $_POST['beername']);
+$sql .= "', beercode='" . mysqli_real_escape_string($connect, $_POST['beercode']);
+$sql .= "', beeruuid='" . mysqli_real_escape_string($connect, $_POST['beeruuid']);
+$sql .= "' WHERE uuid='" . $_POST['uuid'] . "';";
+
+$result = mysqli_query($connect, $sql);
+if (! $result) {
+	syslog(LOG_NOTICE, "cmd_co2meters: result: ".mysqli_error($connect));
+} else {
+	syslog(LOG_NOTICE, "cmd_co2meters: updated record ".$_POST['uuid']);
+}
+echo $result;
+?>
--- a/www/js/mon_co2meter-min.js	Fri Oct 11 13:38:31 2019 +0200
+++ b/www/js/mon_co2meter-min.js	Fri Oct 11 21:04:48 2019 +0200
@@ -1,1 +1,1 @@
-$(document).ready(function(){var f={},e={},g=0,h={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"},j=new $.jqx.dataAdapter(h,{beforeLoadComplete:function(k){var n,l,m=new Array();e.code="Free";e.name="Dummy";e.uuid="66ecccbf-e942-4a35-af49-8b02314561a5";m.push(e);for(l=0;l<k.length;l++){n=k[l];m.push(n)}return m},loadError:function(m,k,l){$("#err").text(k+" "+l)},}),c={min:0,max:40,width:375,height:375,ranges:[{startValue:0,endValue:20,style:{fill:"#3399FF",stroke:"#3399FF"},endWidth:10,startWidth:10},{startValue:20,endValue:26,style:{fill:"#00CC33",stroke:"#00CC33"},endWidth:10,startWidth:10},{startValue:26,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"},d={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"},b="getco2meter.php?uuid='"+my_uuid+"'",a={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:b},i=new $.jqx.dataAdapter(a,{loadComplete:function(k){f=i.records[0];var l=(f.online)?"On-line":"Off-line";$("#info_uuid").html(f.uuid);$("#info_system").html(f.node+"/"+f.alias);$("#info_online").html(l);$("#info_mode").jqxDropDownList("selectItem",f.mode);e.name=f.alias;e.code=f.alias.toUpperCase();e.uuid=f.uuid;if(f.online&&(f.mode!="OFF")){$("#co2meter_powerled").html('<div class="LEDblue_on"></div>Power')}else{$("#co2meter_powerled").html('<div class="LEDblue_off"></div>Power')}if(f.online&&(f.alarm!="0")){$("#co2meter_alarmled").html('<div class="LEDred_on"></div>Alarm')}else{$("#co2meter_alarmled").html('<div class="LEDred_off"></div>Alarm')}$("#gaugeContainer_temperature").jqxGauge({caption:{value:"Temp: "+f.temperature.toFixed(3)}});$("#gaugeContainer_temperature").jqxGauge({value:f.temperature});if(f.temperature_state=="OK"){$("#gaugeContainer_temperature").jqxGauge({disabled:false})}else{$("#gaugeContainer_temperature").jqxGauge({disabled:true})}$("#gaugeContainer_pressure").jqxGauge({caption:{value:"Bar: "+f.pressure_bar.toFixed(2)}});$("#gaugeContainer_pressure").jqxGauge({value:f.pressure_bar});if(f.pressure_state=="OK"){$("#gaugeContainer_pressure").jqxGauge({disabled:false})}else{$("#gaugeContainer_pressure").jqxGauge({disabled:true})}}});$("#select_beer").jqxDropDownList({placeHolder:"Kies bier:",theme:theme,source:j,displayMember:"code",width:150,height:24,dropDownWidth:500,autoDropDownHeight:true,renderer:function(l,k,n){var m=j.records[l];return m.code+" - "+m.name}});$("#gaugeContainer_temperature").jqxGauge(c);$("#gaugeContainer_temperature").jqxGauge({caption:{value:"Temp: 00.000"}});$("#gaugeContainer_pressure").jqxGauge(d);$("#gaugeContainer_pressure").jqxGauge({caption:{value:"Bar: 00.000"}});srcMode=["OFF","ON"];$("#info_mode").jqxDropDownList({theme:theme,source:srcMode,width:100,height:24,dropDownHeight:62});i.dataBind();setInterval(function(){var k=false;if(k){g=4}else{if(g>0){g--}}if(g<=0){i.dataBind();g=20}},500);$("#info_mode").on("change",function(l){var k=l.args;if(k){f.mode=k.item.value}});$("#FLog").jqxButton({template:"primary",width:"150px",theme:theme});$("#FLog").click(function(){window.open("log_fermentation.php?code="+f.beercode+"&name="+f.beername)})});
\ No newline at end of file
+$(document).ready(function(){var g={},f={},d=false,h=0,i={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"},l=new $.jqx.dataAdapter(i,{beforeLoadComplete:function(m){var p,n,o=new Array();f.code="Free";f.name="Dummy";f.uuid="66ecccbf-e942-4a35-af49-8b02314561a5";o.push(f);for(n=0;n<m.length;n++){p=m[n];o.push(p)}return o},loadError:function(o,m,n){$("#err").text(m+" "+n)},}),c={min:0,max:40,width:375,height:375,ranges:[{startValue:0,endValue:20,style:{fill:"#3399FF",stroke:"#3399FF"},endWidth:10,startWidth:10},{startValue:20,endValue:26,style:{fill:"#00CC33",stroke:"#00CC33"},endWidth:10,startWidth:10},{startValue:26,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"},e={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"},b="getco2meter.php?uuid='"+my_uuid+"'",a={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:b},k=new $.jqx.dataAdapter(a,{loadComplete:function(m){g=k.records[0];var n=(g.online)?"On-line":"Off-line";$("#info_uuid").html(g.uuid);$("#info_system").html(g.node+"/"+g.alias);$("#info_online").html(n);$("#info_beer").html(g.beercode+" - "+g.beername);$("#info_mode").html(g.mode);f.name=g.alias;f.code=g.alias.toUpperCase();f.uuid=g.uuid;if(g.online&&(g.mode!="OFF")){$("#co2meter_powerled").html('<div class="LEDblue_on"></div>Power');$("#select_beer").jqxDropDownList({disabled:true});$("#select_beer").jqxDropDownList("clearSelection");$("#select_beer").hide()}else{$("#co2meter_powerled").html('<div class="LEDblue_off"></div>Power');$("#select_beer").show();$("#select_beer").jqxDropDownList({disabled:false})}if(g.online&&(g.alarm!="0")){$("#co2meter_alarmled").html('<div class="LEDred_on"></div>Alarm')}else{$("#co2meter_alarmled").html('<div class="LEDred_off"></div>Alarm')}$("#gaugeContainer_temperature").jqxGauge({caption:{value:"Temp: "+g.temperature.toFixed(3)}});$("#gaugeContainer_temperature").jqxGauge({value:g.temperature});if(g.temperature_state=="OK"){$("#gaugeContainer_temperature").jqxGauge({disabled:false})}else{$("#gaugeContainer_temperature").jqxGauge({disabled:true})}$("#gaugeContainer_pressure").jqxGauge({caption:{value:"Bar: "+g.pressure_bar.toFixed(2)}});$("#gaugeContainer_pressure").jqxGauge({value:g.pressure_bar});if(g.pressure_state=="OK"){$("#gaugeContainer_pressure").jqxGauge({disabled:false})}else{$("#gaugeContainer_pressure").jqxGauge({disabled:true})}}});$("#select_beer").jqxDropDownList({placeHolder:"Kies bier:",theme:theme,source:l,displayMember:"code",width:150,height:24,dropDownWidth:500,autoDropDownHeight:true,renderer:function(n,m,p){var o=l.records[n];return o.code+" - "+o.name}});$("#gaugeContainer_temperature").jqxGauge(c);$("#gaugeContainer_temperature").jqxGauge({caption:{value:"Temp: 00.000"}});$("#gaugeContainer_pressure").jqxGauge(e);$("#gaugeContainer_pressure").jqxGauge({caption:{value:"Bar: 00.000"}});function j(o,m,n){console.log("sendProduct("+o+", "+m+", "+n+")");var p="uuid="+g.uuid+"&beeruuid="+n+"&beercode="+o+"&beername="+m;$.ajax({url:"cmd_co2meter.php",data:p,type:"POST",success:function(q){},error:function(q,s,r){console.log("sendProduct() error")}})}k.dataBind();setInterval(function(){var m=false;if(d){j(g.beercode,g.beername,g.beeruuid);d=false;m=true}if(m){h=4}else{if(h>0){h--}}if(h<=0){k.dataBind();h=20}},500);$("#select_beer").on("select",function(o){if(o.args){var m=o.args.index,n=l.records[m];g.beercode=n.code;g.beername=n.name;g.beeruuid=n.uuid;d=true}});$("#FLog").jqxButton({template:"primary",width:"150px",theme:theme});$("#FLog").click(function(){window.open("log_fermentation.php?code="+g.beercode+"&name="+g.beername)})});
\ No newline at end of file
--- a/www/js/mon_co2meter.js	Fri Oct 11 13:38:31 2019 +0200
+++ b/www/js/mon_co2meter.js	Fri Oct 11 21:04:48 2019 +0200
@@ -25,8 +25,7 @@
 
 	var record = {},
 	blank = {},
-//	newBase = false,
-//	newProduct = false,
+	newProduct = false,
 	schedule = 0,
 
 	productSource = {
@@ -43,7 +42,7 @@
 	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.
+			// 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';
@@ -59,10 +58,10 @@
 		},
 	}),
         gaugeoptionst = {
-                min: 0, max: 40, width: 375, height: 375,
-                ranges: [{ startValue:  0, endValue: 20, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 },
-                         { startValue: 20, endValue: 26, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 },
-                         { startValue: 26, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }],
+                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 },
@@ -110,15 +109,22 @@
                         $("#info_uuid").html(record.uuid);
                         $("#info_system").html(record.node +  "/" + record.alias);
                         $("#info_online").html(oline);
-                        $("#info_mode").jqxDropDownList('selectItem', record.mode);
+			$("#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('<div class="LEDblue_on"></div>Power');
+                                $("#select_beer").jqxDropDownList({ disabled: true });
+                                $("#select_beer").jqxDropDownList('clearSelection');
+                                $("#select_beer").hide();
                         } else {
                                 $("#co2meter_powerled").html('<div class="LEDblue_off"></div>Power');
+                                $("#select_beer").show();
+                                $("#select_beer").jqxDropDownList({ disabled: false });
+
                         }
 			if (record.online && (record.alarm != "0")) {
                                 $("#co2meter_alarmled").html('<div class="LEDred_on"></div>Alarm');
@@ -163,32 +169,28 @@
 	$("#gaugeContainer_pressure").jqxGauge( gaugeoptionsp );
 	$("#gaugeContainer_pressure").jqxGauge( { caption: { value: 'Bar: 00.000' }} );
 
-	srcMode = [ "OFF", "ON" ];
-	$("#info_mode").jqxDropDownList({ theme: theme, source: srcMode, width: 100, height: 24, dropDownHeight: 62 });
-
-//	function sendProduct(code, name, uuid, yeast_lo, yeast_hi) {
+	function sendProduct(code, name, uuid) {
 
-//		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"); }
-//		});
-//	}
+		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, record.yeast_lo, record.yeast_hi);
-//			newProduct = false;
-//			skip = true;
-//		}
+		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 {
@@ -202,29 +204,20 @@
 		}
 	}, 500);
 
-	$('#info_mode').on('change', function (event) {
-		var args = event.args;
-		if (args) {
-			record.mode = args.item.value;
+	$("#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;
 		}
-//		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;
-//		}
-//	});
 
 	// 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);
+		window.open('log_co2meter.php?code=' + record.beercode + '&name=' + record.beername);
 	});
 });
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/log_co2pressure.php	Fri Oct 11 21:04:48 2019 +0200
@@ -0,0 +1,19 @@
+<?php
+require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php');
+page_header('Hergisting grafiek', "log_co2pressure");
+?>
+
+   <div id="MainPanel">
+    <div id="ContentPanel"></div>
+    <div id="fermenter_chart" style="width:1130px; height:610px; float:left; margin-left: 10px; margin-top: 10px;"></div>
+    <div style="margin-top: 10px; margin-left: 10px;">
+     <input style="float: left; margin-left: 10px;" id="print" type="button" value="Print grafiek" />
+     <input style="float: left; margin-left: 10px; margin-top: 10px;" id="pdfButton" type="button" value="Maak PDF" />
+     <input style="float: left; margin-left: 10px; margin-top: 10px;" id="pngButton" type="button" value="Maak PNG" />
+     <input style="float: left; margin-left: 10px; margin-top: 10px;" id="Close" type="button" value="Sluiten" />
+    </div>
+   </div>
+
+<?php
+page_footer();
+?>

mercurial