Add new fermenter adds dummy yeast temperatures. Periodic thermferm unit logging adds the unit alias name. Added Green LED hide color. Moved getglobal.php to dbglobal.php. Adjusted several record types in global and fermenter javascript records so there is less guesswork. Only display control leds and switches for defined equipment.

Fri, 03 May 2024 14:14:01 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 03 May 2024 14:14:01 +0200
changeset 717
22dd7ab614e5
parent 716
5c30c8ef83a8
child 718
39a68509b138

Add new fermenter adds dummy yeast temperatures. Periodic thermferm unit logging adds the unit alias name. Added Green LED hide color. Moved getglobal.php to dbglobal.php. Adjusted several record types in global and fermenter javascript records so there is less guesswork. Only display control leds and switches for defined equipment.

thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
www/css/style.css file | annotate | diff | comparison | revisions
www/dbglobal.php file | annotate | diff | comparison | revisions
www/fermenter.php file | annotate | diff | comparison | revisions
www/getglobal.php file | annotate | diff | comparison | revisions
www/js/fermenter.js file | annotate | diff | comparison | revisions
www/js/set_devices.js file | annotate | diff | comparison | revisions
www/js/set_fermenters.js file | annotate | diff | comparison | revisions
www/js/set_global.js file | annotate | diff | comparison | revisions
www/set_fermenters.php file | annotate | diff | comparison | revisions
--- a/thermferm/server.c	Thu May 02 15:49:16 2024 +0200
+++ b/thermferm/server.c	Fri May 03 14:14:01 2024 +0200
@@ -1113,7 +1113,6 @@
 
 	my_simulator_command = THREAD_PAUSE;
         while (my_simulator_state != THREAD_PAUSE) { mDelay(50); };
-	syslog(LOG_NOTICE, "SIMULATOR ADD thread paused");
 
 	nsim = (simulator_list *)malloc(sizeof(simulator_list));
 	memset(nsim, 0, sizeof(simulator_list));
@@ -1169,22 +1168,17 @@
 	nsim->s_yeast_started = nsim->s_cool_changed = nsim->s_heat_changed = (int)0;
 
 	if (Config.simulators == NULL) {
-		syslog(LOG_NOTICE, "SIMULATOR ADD root");
 	    Config.simulators = nsim;
 	} else {
 	    for (simulator = Config.simulators; simulator; simulator = simulator->next) {
-		    syslog(LOG_NOTICE, "SIMULATOR ADD no %d %s", simulator->simno, simulator->name);
 		if (simulator->next == NULL) {
 		    simulator->next = nsim;
-		    syslog(LOG_NOTICE, "SIMULATOR ADD here");
 		    break;
 		}
 	    }
 	}
-
 	my_simulator_command = THREAD_RUN;
         while (my_simulator_state != THREAD_RUN) { mDelay(50); };
-        syslog(LOG_NOTICE, "SIMULATOR ADD thread runs");
 
 	syslog(LOG_NOTICE, "Simulator %s no %d added", param, highno + 1);
 	srv_send(s, (char *)"211 Simulator %s added", param);
@@ -1194,21 +1188,19 @@
     if (strcmp(opt, (char *)"DEL") == 0) {
 	    // TODO: check devices in use.
 	    // TODO: delete simulated devices.
-	syslog(LOG_NOTICE, "Simulator DEL %s", param);
 
 	my_simulator_command = THREAD_PAUSE;
         while (my_simulator_state != THREAD_PAUSE) { mDelay(50); };
-        syslog(LOG_NOTICE, "SIMULATOR DEL thread paused");
 	rc = delete_Simulator(param);
 	my_simulator_command = THREAD_RUN;
         while (my_simulator_state != THREAD_RUN) { mDelay(50); };
-        syslog(LOG_NOTICE, "SIMULATOR DEL thread runs");
 
 	if (rc) {
 	    syslog(LOG_NOTICE, "Simulator %s deleted", param);
 	    srv_send(s, (char *)"211 Simulator %s deleted", param);
 	    return 1;
 	} else {
+	    syslog(LOG_NOTICE, "Simulator %s del error", param);
 	    srv_send(s, (char *)"440 No such simulator");
 	    return 0;
 	}
@@ -1832,6 +1824,8 @@
 	unit->product_uuid = NULL;
 	unit->product_code = xstrcpy((char *)"FAKE0000");
 	unit->product_name = xstrcpy(param);
+	unit->yeast_lo = 17.0;
+	unit->yeast_hi = 24.0;
 	unit->alias = xstrcpy(an);
 	unit->air_address = unit->beer_address = unit->beer_address2 = unit->chiller_address = unit->heater_address = unit->cooler_address = \
 			    unit->fan_address = unit->door_address = unit->light_address = \
--- a/thermferm/thermferm.c	Thu May 02 15:49:16 2024 +0200
+++ b/thermferm/thermferm.c	Fri May 03 14:14:01 2024 +0200
@@ -1413,8 +1413,8 @@
 	    	unit->PID_heat->OutP = 0.0;
 	    }
 	    if ((seconds == 60) && (unit->mode > UNITMODE_NONE)) {
-	    	syslog(LOG_NOTICE, "Heat: sp=%.3f Input=%.3f iState=%.3f Err=%.3f Out=%.1f",
-				unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP);
+	    	syslog(LOG_NOTICE, "Heat: sp=%.3f Input=%.3f iState=%.3f Err=%.3f Out=%.1f Unit=%s",
+				unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP, unit->alias);
 	    }
     	} else {
 	    unit->PID_heat->OutP = 0.0;
@@ -1439,8 +1439,8 @@
 	    	}
 	    }
 	    if ((seconds == 60) && (unit->mode > UNITMODE_NONE)) {
-	    	syslog(LOG_NOTICE, "Cool: sp=%.3f Input=%.3f iState=%.3f Err=%.3f Out=%.1f",
-	    	unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP);
+	    	syslog(LOG_NOTICE, "Cool: sp=%.3f Input=%.3f iState=%.3f Err=%.3f Out=%.1f Unit=%s",
+	    	unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP, unit->alias);
 	    }
     	} else {
 	    unit->PID_cool->OutP = 0.0;
--- a/www/css/style.css	Thu May 02 15:49:16 2024 +0200
+++ b/www/css/style.css	Fri May 03 14:14:01 2024 +0200
@@ -234,6 +234,15 @@
     box-shadow: #250 0 0px 1px 1px;
 }
 
+.LEDgreen_hide {
+    margin: 5px auto;
+    width: 18px;
+    height: 18px;
+    background-color: #130;
+    border-radius: 50%;
+    box-shadow: #250 0 0px 1px 1px;
+}
+
 .LEDblue_on {
     margin: 5px auto;
     width: 18px;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/dbglobal.php	Fri May 03 14:14:01 2024 +0200
@@ -0,0 +1,95 @@
+<?php
+
+
+function open_socket()
+{
+    $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+
+    if (!($sock === false)) {
+        if (socket_connect($sock, "localhost", 6554)) {
+            socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 15, 'usec' => 0));
+        } else {
+            socket_close($sock);
+        }
+    }
+    return $sock;
+}
+
+
+/**
+ * @param string $command to send to the server.
+ * @return string with the complete reply from the
+ *         server. This can be a multiline reply.
+ */
+function send_cmd($command)
+{
+    $sock = open_socket();
+    if ($sock == false) {
+        return "";
+    }
+    socket_write($sock, $command . "\r\n", 4096);
+
+    $answer = "";
+    while (1) {
+        $line = socket_read($sock, 4096);
+        if ($line === '')
+            break;
+        $answer .= $line;
+    }
+    socket_close($sock);
+
+    return $answer;
+}
+
+
+function startsWith($haystack, $needle)
+{
+    return !strncmp($haystack, $needle, strlen($needle));
+}
+
+$response = array(
+   'error' => false,
+   'msg' => 'Ok',
+);
+
+
+if (isset($_POST['update'])) {
+
+    /* Changing ports does not yet work in the web scripts, disabled. */
+    $cmd  = "GLOBAL PUT\r\n";
+    $cmd .= "NAME," . $_POST['name'] . "\r\n";
+//  $cmd .= "PORT," . $_POST['port'] . "\r\n";
+    $cmd .= "TEMP_UUID," . $_POST['temp_uuid'] . "\r\n";
+    $cmd .= "HUM_UUID," . $_POST['hum_uuid'] . "\r\n";
+    $cmd .= "TEMP_HUM_IDX," . $_POST['temp_hum_idx'] . "\r\n";
+    $cmd .= "LCD_ADDRESS," . $_POST['lcd_address'] . "\r\n";
+    $cmd .= "LCD_COLS," . $_POST['lcd_cols'] . "\r\n";
+    $cmd .= "LCD_ROWS," . $_POST['lcd_rows'] . "\r\n";
+    $cmd .= "MQTT_HOST," . $_POST['mqtt_host'] . "\r\n";
+    $cmd .= "MQTT_PORT," . $_POST['mqtt_port'] . "\r\n";
+    $cmd .= "MQTT_USER," . $_POST['mqtt_user'] . "\r\n";
+    $cmd .= "MQTT_PASS," . $_POST['mqtt_pass'] . "\r\n";
+//  $cmd .= "WEBSOCKET_PORT," . $_POST['websocket_port'] . "\r\n";
+    $cmd .= ".";
+    $answer = send_cmd($cmd);
+    $arr = explode("\r\n", $answer);
+    if (! startsWith($arr[0], "219")) {
+	$response['error'] = true;
+    }
+    exit(json_encode($response));
+
+} else {
+
+    $answer = send_cmd("GLOBAL JSON");
+    header("Content-type: application/json");
+
+    $arr = explode("\r\n", $answer);
+    if (startsWith($arr[0], "213")) {
+    	echo $arr[1];
+    } else {
+    	echo '{}';
+    }
+}
+
+
+?>
--- a/www/fermenter.php	Thu May 02 15:49:16 2024 +0200
+++ b/www/fermenter.php	Fri May 03 14:14:01 2024 +0200
@@ -69,12 +69,12 @@
      </div> <!-- fermenter_panel_display -->
 
      <div id="fermenter_panel_control">
-      <div class="f_control_leds">
+      <div>
        <div id="fermenter_led1"></div>
        <div id="fermenter_led2"></div>
        <div id="fermenter_led3"></div>
       </div>
-      <div class="f_control_switches">
+      <div>
        <div id="fermenter_toggle1"></div>
        <div id="fermenter_toggle2"></div>
        <div id="fermenter_toggle3"></div>
--- a/www/getglobal.php	Thu May 02 15:49:16 2024 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +0,0 @@
-<?php
-
-
-function open_socket()
-{
-    $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
-
-    if (!($sock === false)) {
-        if (socket_connect($sock, "localhost", 6554)) {
-            socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 15, 'usec' => 0));
-        } else {
-            socket_close($sock);
-        }
-    }
-    return $sock;
-}
-
-
-/**
- * @param string $command to send to the server.
- * @return string with the complete reply from the
- *         server. This can be a multiline reply.
- */
-function send_cmd($command)
-{
-    $sock = open_socket();
-    if ($sock == false) {
-        return "";
-    }
-    socket_write($sock, $command . "\r\n", 4096);
-
-    $answer = "";
-    while (1) {
-        $line = socket_read($sock, 4096);
-        if ($line === '')
-            break;
-        $answer .= $line;
-    }
-    socket_close($sock);
-
-    return $answer;
-}
-
-
-function startsWith($haystack, $needle)
-{
-    return !strncmp($haystack, $needle, strlen($needle));
-}
-
-$response = array(
-   'error' => false,
-   'msg' => 'Ok',
-);
-
-
-if (isset($_POST['update'])) {
-
-    /* Changing ports does not yet work in the web scripts, disabled. */
-    $cmd  = "GLOBAL PUT\r\n";
-    $cmd .= "NAME," . $_POST['name'] . "\r\n";
-//  $cmd .= "PORT," . $_POST['port'] . "\r\n";
-    $cmd .= "TEMP_UUID," . $_POST['temp_uuid'] . "\r\n";
-    $cmd .= "HUM_UUID," . $_POST['hum_uuid'] . "\r\n";
-    $cmd .= "TEMP_HUM_IDX," . $_POST['temp_hum_idx'] . "\r\n";
-    $cmd .= "LCD_ADDRESS," . $_POST['lcd_address'] . "\r\n";
-    $cmd .= "LCD_COLS," . $_POST['lcd_cols'] . "\r\n";
-    $cmd .= "LCD_ROWS," . $_POST['lcd_rows'] . "\r\n";
-    $cmd .= "MQTT_HOST," . $_POST['mqtt_host'] . "\r\n";
-    $cmd .= "MQTT_PORT," . $_POST['mqtt_port'] . "\r\n";
-    $cmd .= "MQTT_USER," . $_POST['mqtt_user'] . "\r\n";
-    $cmd .= "MQTT_PASS," . $_POST['mqtt_pass'] . "\r\n";
-//  $cmd .= "WEBSOCKET_PORT," . $_POST['websocket_port'] . "\r\n";
-    $cmd .= ".";
-    $answer = send_cmd($cmd);
-    $arr = explode("\r\n", $answer);
-    if (! startsWith($arr[0], "219")) {
-	$response['error'] = true;
-    }
-    exit(json_encode($response));
-
-} else {
-
-    $answer = send_cmd("GLOBAL JSON");
-    header("Content-type: application/json");
-
-    $arr = explode("\r\n", $answer);
-    if (startsWith($arr[0], "213")) {
-    	echo $arr[1];
-    } else {
-    	echo '{}';
-    }
-}
-
-
-?>
--- a/www/js/fermenter.js	Thu May 02 15:49:16 2024 +0200
+++ b/www/js/fermenter.js	Fri May 03 14:14:01 2024 +0200
@@ -98,16 +98,15 @@
    { name: 'FW' },
    { name: 'server_port', type: 'int' },
    { name: 'websocket_port', type: 'int' },
-   { name: 'thb_temp_uuid', map: 'THB>temperature>uuid' },
    { name: 'temp_uuid', map: 'THB>temperature>uuid' },
    { name: 'temp_state', map: 'THB>temperature>state' },
-   { name: 'temp_value', map: 'THB>temperature>value', type: 'int' },
+   { name: 'temp_value', map: 'THB>temperature>value', type: 'float' },
    { name: 'hum_uuid', map: 'THB>humidity>uuid' },
    { name: 'hum_state', map: 'THB>humidity>state' },
-   { name: 'hum_value', map: 'THB>humidity>value', type: 'int' }
+   { name: 'hum_value', map: 'THB>humidity>value', type: 'float' }
   ],
   id: 'name',
-  url: 'getglobal.php'
+  url: 'dbglobal.php'
  },
  globalData = new $.jqx.dataAdapter(globalSource, {
   loadComplete: function(records) {
@@ -121,33 +120,40 @@
   datafields: [
    { name: 'type' },
    { name: 'unit' },
+   { name: 'beeruuid', map: 'metric>product>uuid' },
    { name: 'beercode', map: 'metric>product>code' },
    { name: 'beername', map: 'metric>product>name' },
-   { name: 'yeast_lo', map: 'metric>product>yeast_lo' },
-   { name: 'yeast_hi', map: 'metric>product>yeast_hi' },
+   { name: 'yeast_lo', map: 'metric>product>yeast_lo', type: 'float' },
+   { name: 'yeast_hi', map: 'metric>product>yeast_hi', type: 'float' },
+   { name: 'air_address', map: 'metric>air>address' },
    { name: 'air_state', map: 'metric>air>state' },
-   { name: 'air_temperature', map: 'metric>air>temperature' },
+   { name: 'air_temperature', map: 'metric>air>temperature', type: 'float' },
+   { name: 'beer_address', map: 'metric>beer>address' },
    { name: 'beer_state', map: 'metric>beer>state' },
-   { name: 'beer_temperature', map: 'metric>beer>temperature' },
+   { name: 'beer_temperature', map: 'metric>beer>temperature', type: 'float' },
+   { name: 'chiller_address', map: 'metric>chiller>address' },
    { name: 'chiller_state', map: 'metric>chiller>state' },
-   { name: 'chiller_temperature', map: 'metric>chiller>temperature' },
-   { name: 'heater_state', map: 'metric>heater>state' },
-   { name: 'heater_usage', map: 'metric>heater>usage' },
-   { name: 'cooler_state', map: 'metric>cooler>state' },
-   { name: 'cooler_usage', map: 'metric>cooler>usage' },
-   { name: 'fan_state', map: 'metric>fan>state' },
-   { name: 'fan_usage', map: 'metric>fan>usage' },
+   { name: 'chiller_temperature', map: 'metric>chiller>temperature', type: 'float' },
+   { name: 'heater_address', map: 'metric>heater>address' },
+   { name: 'heater_state', map: 'metric>heater>state', type: 'int' },
+   { name: 'heater_usage', map: 'metric>heater>usage', type: 'int' },
+   { name: 'cooler_address', map: 'metric>cooler>address' },
+   { name: 'cooler_state', map: 'metric>cooler>state', type: 'int' },
+   { name: 'cooler_usage', map: 'metric>cooler>usage', type: 'int' },
+   { name: 'fan_address', map: 'metric>fan>address' },
+   { name: 'fan_state', map: 'metric>fan>state', type: 'int' },
+   { name: 'fan_usage', map: 'metric>fan>usage', type: 'int' },
    { name: 'light_address', map: 'metric>light>address' },
-   { name: 'light_state', map: 'metric>light>state' },
-   { name: 'light_usage', map: 'metric>light>usage' },
+   { name: 'light_state', map: 'metric>light>state', type: 'int' },
+   { name: 'light_usage', map: 'metric>light>usage', type: 'int' },
    { name: 'door_address', map: 'metric>door>address' },
-   { name: 'door_state', map: 'metric>door>state' },
+   { name: 'door_state', map: 'metric>door>state', type: 'int' },
    { name: 'psu_address', map: 'metric>psu>address' },
-   { name: 'psu_state', map: 'metric>psu>state' },
+   { name: 'psu_state', map: 'metric>psu>state', type: 'int' },
    { name: 'mode', map: 'metric>mode' },
    { name: 'alarm', map: 'metric>alarm', type: 'int' },
-   { name: 'setpoint_high', map: 'metric>setpoint>high' },
-   { name: 'setpoint_low', map: 'metric>setpoint>low' },
+   { name: 'setpoint_high', map: 'metric>setpoint>high', type: 'float' },
+   { name: 'setpoint_low', map: 'metric>setpoint>low', type: 'float' },
    { name: 'profile_uuid', map: 'metric>profile>uuid' },
    { name: 'profile_name', map: 'metric>profile>name' },
    { name: 'profile_state', map: 'metric>profile>state', type: 'string' },
@@ -155,10 +161,9 @@
    { name: 'profile_inittemp_high', map: 'metric>profile>inittemp>high', type: 'float' },
    { name: 'profile_inittemp_low', map: 'metric>profile>inittemp>low', type: 'float' },
    { name: 'profile_steps', map: 'metric>profile>steps', type: 'string' },
-   { name: 'stage', map: 'metric>stage', type: 'string' },
-   { name: 'beeruuid', map: 'metric>product>uuid' }
+   { name: 'stage', map: 'metric>stage', type: 'string' }
   ],
-  id: 'alias',
+  id: 'unit',
   url: url
  },
  dataAdapter = new $.jqx.dataAdapter(source, {
@@ -169,24 +174,24 @@
  });
 
  function updateScreen() {
-   $('#room_thb').html(global.temp_value + '&deg;C&nbsp;&nbsp;' + global.hum_value + '% humidity');
+   $('#room_thb').html(global.temp_value.toFixed(1) + '&deg;C&nbsp;&nbsp;' + global.hum_value.toFixed(1) + '% humidity');
    $('#info_system').html(record.unit);
    $('#info_beer').html(record.beercode + ' - ' + record.beername);
    $('#info_mode').jqxDropDownList('selectItem', record.mode);
    $('#info_stage').jqxDropDownList('selectItem', record.stage);
    if (record.door_address) {
-     if (record.door_state != '0') {
-      $('#fermenter_doorled').html('<div class="LEDyellow_on"></div>Door');
-     } else {
-      $('#fermenter_doorled').html('<div class="LEDyellow_off"></div>Door');
-     }
+    if (record.door_state != '0') {
+     $('#fermenter_doorled').html('<div class="LEDyellow_on"></div>Door');
+    } else {
+     $('#fermenter_doorled').html('<div class="LEDyellow_off"></div>Door');
+    }
    }
    if (record.light_address) {
-     if (record.light_state != '0') {
-      $('#fermenter_lightled').html('<div class="LEDyellow_on"></div>Light');
-     } else {
-      $('#fermenter_lightled').html('<div class="LEDyellow_off"></div>Light');
-     }
+    if (record.light_state != '0') {
+     $('#fermenter_lightled').html('<div class="LEDyellow_on"></div>Light');
+    } else {
+     $('#fermenter_lightled').html('<div class="LEDyellow_off"></div>Light');
+    }
    }
    if (record.mode != 'OFF') {
     $('#fermenter_powerled').html('<div class="LEDblue_on"></div>Power');
@@ -209,25 +214,41 @@
     $('#target_hi').jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false });
    }
 
-   $('.f_control_leds').show();
-   if (record.heater_state != '0') {
-    $('#fermenter_led1').html('<div class="LEDgreen_on"></div>Heat');
+   if (record.heater_address) {
+    if (record.heater_state != '0') {
+     $('#fermenter_led1').html('<div class="LEDgreen_on"></div>Heat');
+    } else {
+     $('#fermenter_led1').html('<div class="LEDgreen_off"></div>Heat');
+    }
    } else {
-    $('#fermenter_led1').html('<div class="LEDgreen_off"></div>Heat');
+    $('#fermenter_led1').html('<div class="LEDgreen_hide"></div>Heat');
    }
-   if (record.cooler_state != '0') {
-    $('#fermenter_led2').html('<div class="LEDgreen_on"></div>Cool');
+
+   if (record.cooler_address) {
+    if (record.cooler_state != '0') {
+     $('#fermenter_led2').html('<div class="LEDgreen_on"></div>Cool');
+    } else {
+     $('#fermenter_led2').html('<div class="LEDgreen_off"></div>Cool');
+    }
    } else {
-    $('#fermenter_led2').html('<div class="LEDgreen_off"></div>Cool');
+    $('#fermenter_led2').html('<div class="LEDgreen_hide"></div>Cool');
    }
-   if (record.fan_state != '0') {
-    $('#fermenter_led3').html('<div class="LEDgreen_on"></div>Fan');
+
+   if (record.fan_address) {
+    if (record.fan_state != '0') {
+     $('#fermenter_led3').html('<div class="LEDgreen_on"></div>Fan');
+    } else {
+     $('#fermenter_led3').html('<div class="LEDgreen_off"></div>Fan');
+    }
    } else {
-    $('#fermenter_led3').html('<div class="LEDgreen_off"></div>Fan');
+    $('#fermenter_led3').html('<div class="LEDgreen_hide"></div>Fan');
    }
 
    if (record.mode == 'NONE') {
-    $('.f_control_switches').show();
+    $('#fermenter_toggle1,#fermenter_toggle2,#fermenter_toggle3').show();
+    $('#fermenter_toggle1').jqxSwitchButton({ disabled: (record.heater_address) ? false:true });
+    $('#fermenter_toggle2').jqxSwitchButton({ disabled: (record.cooler_address) ? false:true });
+    $('#fermenter_toggle3').jqxSwitchButton({ disabled: (record.fan_address) ? false:true });
     if ((record.heater_state != 0) != $('#fermenter_toggle1').jqxSwitchButton('val'))
      $('#fermenter_toggle1').val(record.heater_state != 0);
     if ((record.cooler_state != 0) != $('#fermenter_toggle2').jqxSwitchButton('val'))
@@ -235,7 +256,8 @@
     if ((record.fan_state != 0) != $('#fermenter_toggle3').jqxSwitchButton('val'))
      $('#fermenter_toggle3').val(record.fan_state != 0);
    } else {
-    $('.f_control_switches').hide();
+    $('#fermenter_toggle1,#fermenter_toggle2,#fermenter_toggle3').jqxSwitchButton({ disabled:true });
+    $('#fermenter_toggle1,#fermenter_toggle2,#fermenter_toggle3').hide();
    }
 
    $('#info_profile').html(record.profile_name);
@@ -291,29 +313,17 @@
     $('#gaugeContainer_air').jqxGauge({ caption: { value: 'Air: ' + record.air_temperature.toFixed(3) }});
     $('#gaugeContainer_air').jqxGauge({ value: record.air_temperature });
    }
-   if (record.air_state == 'YES') {
-    $('#gaugeContainer_air').jqxGauge({ disabled: false });
-   } else {
-    $('#gaugeContainer_air').jqxGauge({ disabled: true });
-   }
+   $('#gaugeContainer_air').jqxGauge({ disabled: (record.air_state == 'YES') ? false:true });
    if (record.beer_temperature !== undefined) {
     $('#gaugeContainer_beer').jqxGauge({ caption: { value: 'Beer: ' + record.beer_temperature.toFixed(3) }});
     $('#gaugeContainer_beer').jqxGauge({ value: record.beer_temperature });
    }
-   if (record.beer_state == 'YES') {
-    $('#gaugeContainer_beer').jqxGauge({ disabled: false });
-   } else {
-    $('#gaugeContainer_beer').jqxGauge({ disabled: true });
-   }
+   $('#gaugeContainer_beer').jqxGauge({ disabled: (record.beer_state == 'YES') ? false:true });
    if (record.chiller_temperature !== undefined) {
     $('#gaugeContainer_chiller').jqxGauge({ value: record.chiller_temperature });
    }
-   if (record.chiller_state == 'YES') {
-    $('#gaugeContainer_chiller').jqxGauge({ disabled: false });
-   } else {
-    $('#gaugeContainer_chiller').jqxGauge({ disabled: true });
-   }
- }
+   $('#gaugeContainer_chiller').jqxGauge({ disabled: (record.chiller_state == 'YES') ? false:true });
+ } /* Updatescreen */
 
  $('#gaugeContainer_air').jqxGauge(gaugeoptions);
  $('#gaugeContainer_air').jqxGauge({ caption: { value: 'Air: 00.000' }});
@@ -442,7 +452,7 @@
   var msg = evt.data;
   var obj = JSON.parse(msg);
 
-  console.log('ws got ' + msg);
+ // console.log('ws got ' + msg);
 
   if (obj.ping) {
    websocket.send('{"pong":' + obj.ping + '}');
@@ -459,6 +469,7 @@
    global.room_hum = obj.THB.humidity;
    updateScreen();
   } else if (obj.type == 'fermenter' && obj.unit == record.unit) {
+	  console.log('ws got unit ' + msg);
    record.beeruuid = obj.metric.product.uuid;
    record.beercode = obj.metric.product.code;
    record.beername = obj.metric.product.name;
@@ -476,14 +487,28 @@
      record.chiller_state = obj.metric.chiller.state;
      record.chiller_temperature = obj.metric.chiller.temperature;
    }
-   if (obj.metric.heater)
-     record.heater_state = obj.metric.heater.state;
-   if (obj.metric.cooler)
-     record.cooler_state = obj.metric.cooler.state;
-   if (obj.metric.fan)
+   if (obj.metric.heater) {
+    record.heater_address = obj.metric.heater.address;
+    record.heater_state = obj.metric.heater.state;
+   } else {
+    record.heater_address = '';
+   }
+   if (obj.metric.cooler) {
+    record.cooler_address = obj.metric.cooler.address;
+    record.cooler_state = obj.metric.cooler.state;
+   } else {
+    record.cooler_address = '';
+   }
+   if (obj.metric.fan) {
+    record.fan_address = obj.metric.fan.address;
     record.fan_state = obj.metric.fan.state;
-   if (obj.metric.door)
-     record.door_state = obj.metric.door.state;
+   } else {
+    record.fan_address = '';
+   }
+   if (obj.metric.door) {
+    record.door_address = obj.metric.door.address;
+    record.door_state = obj.metric.door.state;
+   }
    if (obj.metric.light)
      record.light_state = obj.metric.light.state;
    if (obj.metric.psu)
--- a/www/js/set_devices.js	Thu May 02 15:49:16 2024 +0200
+++ b/www/js/set_devices.js	Fri May 03 14:14:01 2024 +0200
@@ -253,31 +253,29 @@
  });
  $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme });
  $('#Delete').click(function() {
-  if (editrow >= 0) {
-   // Open a popup to confirm this action.
-   $('#eventWindow').jqxWindow('open');
-   $('#delOk').click(function() {
-    var data,
-    data = 'del=true&uuid=' + $('#dev_uuid').val();
-    $.ajax({
-     dataType: 'json',
-     url: url,
-     cache: false,
-     data: data,
-     type: 'POST',
-     success: function(data) {
-      if (data.error) {
-       console.log('del: ' + data.msg);
-       alert('Error: ' + data.msg);
-      } else {
-       console.log('del: success');
-      }
-     },
-     error: function(jqXHR, textStatus, errorThrown) {}
-    });
-    $('#jqxgrid').jqxGrid('updatebounddata');
+  // Open a popup to confirm this action.
+  $('#eventWindow').jqxWindow('open');
+  $('#delOk').click(function() {
+//   var data,
+   var data = 'del=true&uuid=' + $('#dev_uuid').val();
+   $.ajax({
+    dataType: 'json',
+    url: url,
+    cache: false,
+    data: data,
+    type: 'POST',
+    success: function(data) {
+     if (data.error) {
+      console.log('del: ' + data.msg);
+      alert('Error: ' + data.msg);
+     } else {
+      console.log('del: success');
+     }
+    },
+    error: function(jqXHR, textStatus, errorThrown) {}
    });
-  }
+   $('#jqxgrid').jqxGrid('updatebounddata');
+  });
   $('#popupWindow').jqxWindow('hide');
  });
  $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme });
--- a/www/js/set_fermenters.js	Thu May 02 15:49:16 2024 +0200
+++ b/www/js/set_fermenters.js	Fri May 03 14:14:01 2024 +0200
@@ -45,9 +45,9 @@
 function createAddElements() {
  $('#addWindow').jqxWindow({
   theme: theme,
-  position: { x: 400, y: 210 },
-  width: 480,
-  height: 180,
+  position: { x: 430, y: 210 },
+  width: 420,
+  height: 175,
   resizable: false,
   isModal: true,
   modalOpacity: 0.4,
--- a/www/js/set_global.js	Thu May 02 15:49:16 2024 +0200
+++ b/www/js/set_global.js	Fri May 03 14:14:01 2024 +0200
@@ -23,7 +23,7 @@
 
 $(document).ready(function() {
  var global = {},
- url = 'getglobal.php',
+ url = 'dbglobal.php',
  globalSource = {
   datatype: 'json',
   cache: false,
@@ -38,13 +38,12 @@
    { name: 'server_port', type: 'int' },
    { name: 'websocket_port', type: 'int' },
    { name: 'nextunit', type: 'int' },
-   { name: 'thb_temp_uuid', map: 'THB>temperature>uuid' },
    { name: 'temp_uuid', map: 'THB>temperature>uuid' },
    { name: 'temp_state', map: 'THB>temperature>state' },
-   { name: 'temp_value', map: 'THB>temperature>value', type: 'int' },
+   { name: 'temp_value', map: 'THB>temperature>value', type: 'float' },
    { name: 'hum_uuid', map: 'THB>humidity>uuid' },
    { name: 'hum_state', map: 'THB>humidity>state' },
-   { name: 'hum_value', map: 'THB>humidity>value', type: 'int' },
+   { name: 'hum_value', map: 'THB>humidity>value', type: 'float' },
    { name: 'temp_hum_idx', map: 'THB>index', type: 'int' },
    { name: 'lcd_address', map: 'LCD>address' },
    { name: 'lcd_cols', map: 'LCD>cols', type: 'int' },
@@ -70,10 +69,10 @@
    $('#nextunit').val(global.nextunit);
    $('#temp_uuid').val(global.temp_uuid);
    $('#temp_state').val(global.temp_state);
-   $('#temp_value').val(global.temp_value / 1000.0);
+   $('#temp_value').val(global.temp_value);
    $('#hum_uuid').val(global.hum_uuid);
    $('#hum_state').val(global.hum_state);
-   $('#hum_value').val(global.hum_value / 1000.0);
+   $('#hum_value').val(global.hum_value);
    $('#temp_hum_idx').val(global.temp_hum_idx);
    $('#lcd_address').val(global.lcd_address);
    $('#lcd_cols').val(global.lcd_cols);
@@ -161,8 +160,7 @@
      console.log('update: success');
     }
    },
-    error: function(jqXHR, textStatus, errorThrown) {
-   }
+   error: function(jqXHR, textStatus, errorThrown) {}
   });
  });
 
@@ -173,10 +171,5 @@
   if (obj.ping) {
    websocket.send('{"pong":' + obj.ping + '}');
   }
-
-  if (obj.type == 'global') {
-   // Use the message to trigger update.
-//   $('#jqxgrid').jqxGrid('updatebounddata');
-  }
  }
 });
--- a/www/set_fermenters.php	Thu May 02 15:49:16 2024 +0200
+++ b/www/set_fermenters.php	Fri May 03 14:14:01 2024 +0200
@@ -158,9 +158,9 @@
       Press "Cancel" to close without adding a new unit.
      </div>
      <div>
-      <div style="float: right; margin-top: 25px; margin-bottom: 10px;">
+      <div style="float: right; margin-top: 45px; margin-bottom: 10px;">
        <input type="button" id="addOk" value="OK" style="margin-right: 15px" />
-       <input type="button" id="addCancel" value="Cancel" style="margin-right: 65px" />
+       <input type="button" id="addCancel" value="Cancel" style="margin-right: 160px" />
       </div>
      </div>
     </div>

mercurial