The global settings screen added. No Save function yet.

Mon, 22 Apr 2024 20:58:55 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 22 Apr 2024 20:58:55 +0200
changeset 697
685f20ad87ed
parent 696
fe042f9484ac
child 698
92a080c1a5d5

The global settings screen added. No Save function yet.

www/drop_tempsensors.php file | annotate | diff | comparison | revisions
www/js/global.js file | annotate | diff | comparison | revisions
www/js/set_global.js file | annotate | diff | comparison | revisions
www/set_global.php file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/drop_tempsensors.php	Mon Apr 22 20:58:55 2024 +0200
@@ -0,0 +1,79 @@
+<?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));
+}
+
+$answer = send_cmd("DEVICES JSON");
+
+$arr = explode("\r\n", $answer);
+if (startsWith($arr[0], "212")) {
+
+    /*
+     * Build reply with only temperature sensors.
+     */
+    $sensors[] = array(
+	'uuid' => '',
+	'name' => 'Not Assigned'
+    );
+
+    $rows = json_decode($arr[1], true);
+
+    foreach($rows as $item) {
+	if ($item['direction'] == "IN_ANALOG") {
+	    $sensors[] = array(
+		'uuid' => $item['uuid'],
+		'name' => $item['description']." ".$item['comment']
+	    );
+	}
+    }
+    header("Content-type: application/json");
+    exit(json_encode($sensors));
+}
+
+header("Content-type: application/json");
+echo '{}';
+
+?>
--- a/www/js/global.js	Mon Apr 22 15:12:27 2024 +0200
+++ b/www/js/global.js	Mon Apr 22 20:58:55 2024 +0200
@@ -45,10 +45,23 @@
 },
 DeviceDirectionAdapter = new $.jqx.dataAdapter(DeviceDirectionSource),
 
+// Temp sensors droptdown list
+tempsensorSource = {
+ datatype: 'json',
+ datafields: [
+  { name: 'uuid', type: 'string' },
+  { name: 'name', type: 'string' }
+ ],
+ url: 'drop_tempsensors.php'
+},
+tempsensorlist = new $.jqx.dataAdapter(tempsensorSource),
+
 // options for editors
 
 Show0dec = { inputMode: 'simple', theme: theme, width: 90, height: 23, readOnly: true, decimalDigits: 0 },
+Show1dec = { inputMode: 'simple', theme: theme, width: 90, height: 23, readOnly: true, decimalDigits: 1 },
 Spin0dec = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, decimalDigits: 0, spinButtons: true },
+  PosInt = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, decimalDigits: 0, spinButtons: true },
   SubInt = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, max: 63, decimalDigits: 0, spinButtons: true },
  GPIOInt = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: -1, max:31, decimalDigits: 0, spinButtons: true };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/js/set_global.js	Mon Apr 22 20:58:55 2024 +0200
@@ -0,0 +1,160 @@
+/*****************************************************************************
+ * Copyright (C) 2024
+ *
+ * Michiel Broek <mbroek at mbse dot eu>
+ *
+ * This file is part of mbsePi-apps
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * BrewCloud is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with ThermFerm; see the file COPYING.  If not, write to the Free
+ * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *****************************************************************************/
+
+
+$(document).ready(function() {
+ var global = {},
+ globalSource = {
+  datatype: 'json',
+  cache: false,
+  datafields: [
+   { name: 'type', type: 'string' },
+   { name: 'name', type: 'string' },
+   { name: 'uuid', type: 'string' },
+   { name: 'node', type: 'string' },
+   { name: 'os' },
+   { name: 'os_version' },
+   { 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: 'hum_uuid', map: 'THB>humidity>uuid' },
+   { name: 'hum_state', map: 'THB>humidity>state' },
+   { name: 'hum_value', map: 'THB>humidity>value', type: 'int' },
+   { name: 'temp_hum_idx', map: 'THB>index', type: 'int' },
+   { name: 'lcd_address', map: 'LCD>address' },
+   { name: 'lcd_cols', map: 'LCD>cols', type: 'int' },
+   { name: 'lcd_rows', map: 'LCD>rows', type: 'int' },
+   { name: 'mqtt_host', map: 'MQTT>host' },
+   { name: 'mqtt_port', map: 'MQTT>port', type: 'int' },
+   { name: 'mqtt_username', map: 'MQTT_username' },
+   { name: 'mqtt_password', map: 'MQTT_password' }
+  ],
+  id: 'name',
+  url: 'getglobal.php'
+ },
+ globalData = new $.jqx.dataAdapter(globalSource, {
+  loadComplete: function(records) {
+   global = globalData.records[0];
+   updateScreen();
+  }
+ }),
+ tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds
+
+ function updateScreen() {
+  $('#name').val(global.name);
+  $('#uuid').val(global.uuid);
+  $('#node').val(global.node);
+  $('#os').val(global.os + ' ' + global.os_version);
+  $('#FW').val(global.FW);
+  $('#server_port').val(global.server_port);
+  $('#websocket_port').val(global.websocket_port);
+  $('#temp_uuid').val(global.temp_uuid);
+  $('#temp_state').val(global.temp_state);
+  $('#temp_value').val(global.temp_value / 1000.0);
+  $('#hum_uuid').val(global.hum_uuid);
+  $('#hum_state').val(global.hum_state);
+  $('#hum_value').val(global.hum_value / 1000.0);
+  $('#temp_hum_idx').val(global.temp_hum_idx);
+  $('#lcd_address').val(global.lcd_address);
+  $('#lcd_cols').val(global.lcd_cols);
+  $('#lcd_rows').val(global.lcd_rows)
+  $('#mqtt_host').val(global.mqtt_host);
+  $('#mqtt_port').val(global.mqtt_port);
+  $('#mqtt_username').val(global.mqtt_username);
+  $('#mqtt_password').val(global.mqtt_password);
+ }
+
+ // initialize the input fields.
+ $('#name').jqxInput({ theme: theme, width: 240, height: 23 });
+ $('#uuid').jqxInput({ theme: theme, width: 480, height: 23 });
+ $('#node').jqxInput({ theme: theme, width: 240, height: 23 });
+ $('#os').jqxInput({ theme: theme, width: 240, height: 23 });
+ $('#FW').jqxInput({ theme: theme, width: 120, height: 23 });
+ $('#server_port').jqxNumberInput(Spin0dec);
+ $('#websocket_port').jqxNumberInput(Spin0dec);
+ $('#temp_uuid').jqxDropDownList({
+  theme: theme,
+  source: tempsensorlist,
+  valueMember: 'uuid',
+  displayMember: 'name',
+  width: 240,
+  dropDownWidth: 480,
+  autoDropDownHeight: true
+ });
+ $('#temp_state').jqxInput({ theme: theme, width: 120, height: 23 });
+ $('#temp_value').jqxNumberInput(Show1dec);
+ $('#hum_uuid').jqxDropDownList({
+  theme: theme,
+  source: tempsensorlist,
+  valueMember: 'uuid',
+  displayMember: 'name',
+  width: 240,
+  dropDownWidth: 480,
+  autoDropDownHeight: true
+ });
+ $('#hum_state').jqxInput({ theme: theme, width: 120, height: 23 });
+ $('#hum_value').jqxNumberInput(Show1dec);
+ $('#temp_hum_idx').jqxNumberInput(Spin0dec);
+
+ $('#lcd_address').jqxNumberInput(Spin0dec);
+ $('#lcd_cols').jqxNumberInput(GPIOInt);
+ $('#lcd_rows').jqxNumberInput(GPIOInt);
+
+ $('#mqtt_host').jqxInput({ theme: theme, width: 240, height: 23 });
+ $('#mqtt_port').jqxNumberInput(Spin0dec);
+ $('#mqtt_username').jqxInput({ theme: theme, width: 240, height: 23 });
+ $('#mqtt_password').jqxInput({ theme: theme, width: 240, height: 23 });
+
+ globalData.dataBind();
+
+
+ $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme });
+ $('#Save').click(function() {
+  var row, rowID = -1;
+  if (editrow >= 0) {
+   rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
+  }
+  row = {
+   uuid: dataRecord.uuid,
+   type: $('#type').val()
+  };
+//   $('#jqxgrid').jqxGrid('updaterow', rowID, row);
+ });
+
+ websocket.onmessage = function(evt) {
+  var msg = evt.data;
+  var obj = JSON.parse(msg);
+
+  if (obj.ping) {
+   websocket.send('{"pong":' + obj.ping + '}');
+  }
+
+  if (obj.type == 'global') {
+   // Use the message to trigger update.
+//   $('#jqxgrid').jqxGrid('updatebounddata');
+  }
+ }
+});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/set_global.php	Mon Apr 22 20:58:55 2024 +0200
@@ -0,0 +1,96 @@
+<?php
+require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php');
+page_header('Global settings', 'set_global');
+?>
+
+   <div id="MainPanel">
+    <div style="overflow: hidden;">
+     <table style="width: 100%;">
+      <tr>
+       <td colspan="6">&nbsp;</td>
+      </tr>
+      <tr>
+       <td style="vertical-align: top; float: right; padding: 3px;">System name:</td>
+       <td align="left" style="vertical-align: top; padding: 3px;"><input id="name" readonly /></td>
+       <td style="vertical-align: top; float: right; padding: 3px;">Firmware:</td>
+       <td align="left" colspan="3" style="vertical-align: top; padding: 3px;"><input id="FW" readonly /></td>
+      </tr>
+       <td style="vertical-align: top; float: right; padding: 3px;">System uuid:</td>
+       <td align="left" colspan="5" style="vertical-align: top; padding: 3px;"><input id="uuid" readonly /></td>
+      </tr>
+      </tr>
+       <td style="vertical-align: top; float: right; padding: 3px;">Node:</td>
+       <td align="left" style="vertical-align: top; padding: 3px;"><input id="node" readonly /></td>
+       <td style="vertical-align: top; float: right; padding: 3px;">OS:</td>
+       <td align="left" colspan="3" style="vertical-align: top; padding: 3px;"><input id="os" readonly /></td>
+      </tr>
+      <tr>
+       <td colspan="6">&nbsp;</td>
+      </tr>
+      <tr>
+       <td style="vertical-align: top; float: right; padding: 3px;">Server client port:</td>
+       <td style="padding: 3px;"><div id="server_port"></div></td>
+       <td style="vertical-align: top; float: right; padding: 3px;">Websocket port:</td>
+       <td style="padding: 3px;" colspan="3"><div style="float: left;" id="websocket_port"></div></td>
+      </tr>
+      <tr>
+       <td colspan="6">&nbsp;</td>
+      </tr>
+      <tr>
+       <td style="vertical-align: top; float: right; padding: 3px;">Room temp address:</td>
+       <td style="padding: 3px;"><div id="temp_uuid"></div></td>
+       <td style="vertical-align: top; float: right; padding: 3px;">Room temp state:</td>
+       <td align="left" style="vertical-align: top; padding: 3px;"><input id="temp_state" readonly /></td>
+       <td style="vertical-align: top; float: right; padding: 3px;">Room temperature:</td>
+       <td style="padding: 3px;"><div style="float: left;" id="temp_value"></div></td>
+      </tr>
+      <tr>
+       <td style="vertical-align: top; float: right; padding: 3px;">Room hum address:</td>
+       <td style="padding: 3px;"><div id="hum_uuid"></div></td>
+       <td style="vertical-align: top; float: right; padding: 3px;">Room hum state:</td>
+       <td align="left" style="vertical-align: top; padding: 3px;"><input id="hum_state" readonly /></td>
+       <td style="vertical-align: top; float: right; padding: 3px;">Room humidity:</td>
+       <td style="padding: 3px;"><div style="float: left;" id="hum_value"></div></td>
+      </tr>
+      <tr>
+       <td style="vertical-align: top; float: right; padding: 3px;">Room Domoticz idx:</td>
+       <td style="padding: 3px;" colspan="5"><div id="temp_hum_idx"></div></td>
+      </tr>
+      <tr>
+       <td colspan="6">&nbsp;</td>
+      </tr>
+      <tr>
+       <td style="vertical-align: top; float: right; padding: 3px;">LCD I2C address:</td>
+       <td style="padding: 3px;"><div id="lcd_address"></div></td>
+       <td style="vertical-align: top; float: right; padding: 3px;">LCD columns:</td>
+       <td style="padding: 3px;"><div id="lcd_cols"></div></td>
+       <td style="vertical-align: top; float: right; padding: 3px;">LCD rows:</td>
+       <td style="padding: 3px;"><div style="float: left;" id="lcd_rows"></div></td>
+      </tr>
+      <tr>
+       <td colspan="6">&nbsp;</td>
+      </tr>
+      <tr>
+       <td style="vertical-align: top; float: right; padding: 3px;">MQTT host:</td>
+       <td align="left" style="vertical-align: top; padding: 3px;"><input id="mqtt_host" /></td>
+       <td style="vertical-align: top; float: right; padding: 3px;">MQTT username:</td>
+       <td align="left" colspan="3" style="vertical-align: top; padding: 3px;"><input id="mqtt_username" /></td>
+      </tr>
+      <tr>
+       <td style="vertical-align: top; float: right; padding: 3px;">MQTT port:</td>
+       <td style="padding: 3px;"><div id="mqtt_port"></div></td>
+       <td style="vertical-align: top; float: right; padding: 3px;">MQTT password:</td>
+       <td align="left" colspan="3" style="vertical-align: top; padding: 3px;"><input id="mqtt_password" /></td>
+      </tr>
+     </table>
+     <div style="float: right; margin-top: 120px; margin-bottom: 10px;">
+      <input style="margin-right: 595px;" type="button" id="Save"   value="Save" />
+     </div>
+    </div>
+   </div>
+
+
+
+<?php
+page_footer();
+?>

mercurial