www/js/mon_node.js

Wed, 06 Dec 2023 20:26:00 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 06 Dec 2023 20:26:00 +0100
changeset 855
2d328a2a4025
parent 703
faeede125639
permissions
-rw-r--r--

Fixed init scripts names in Makefile. Update crontasks to use the database to check the log entries for products.

/*****************************************************************************
 * Copyright (C) 2019-2020
 *
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of BMS
 *
 * 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.
 *
 * Brewery Management System istributed 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 record = {},
 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: 'int' },
   { 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_ssid', type: 'string' },
   { name: 'net_rssi', type: 'int' },
   { name: 'up_interval', type: 'int' }
  ],
  id: 'record',
  url: url
 },
 dataAdapter = new $.jqx.dataAdapter(source, {
  loadComplete: function(records) {
   record = dataAdapter.records[0];
   updateScreen();
  }
 });

 function updateScreen() {
  var oline = (record.online) ? 'On-line' : 'Off-line',
  html = '<div id="node_table">';
  html += '<table style="width: 100%; padding: 10px;">';
  html += '<tr><th colspan=2>Systeem overzicht</th></tr>';
  html += '<tr><td>Uuid</td><td>' + record.uuid + '</td></tr>';
  html += '<tr><td>Systeem</td><td>' + record.node + '</td></tr>';
  html += '<tr><td>Online</td><td>' + oline + '</td></tr>';
  html += '<tr><td>Type</td><td>' + record.group_id + '</td></tr>';
  html += '<tr><td>Eerst gezien</td><td>' + record.firstseen + '</td></tr>';
  html += '<tr><td>Laatst gezien</td><td>' + record.lastseen + '</td></tr>';
  if (record.online) {
   html += '<tr><td>Hardware maker</td><td>' + record.hardwaremake + '</td></tr>';
   html += '<tr><td>Hardware model</td><td>' + record.hardwaremodel + '</td></tr>';
   html += '<tr><td>OS</td><td>' + record.os + ' versie: ' + record.os_version + '</td></tr>';
   html += '<tr><td>Firmware</td><td>' + record.firmware + '</td></tr>';

   if (record.temperature > 0)
    html += '<tr><td>Temperatuur</td><td>' + record.temperature.toFixed(1) + '&deg;C</td></tr>';
   if (record.humidity > 0)
    html += '<tr><td>Vochtigheid</td><td>' + record.humidity.toFixed(1) + '%</td></tr>';
   if (record.barometer > 0)
    html += '<tr><td>Luchtdruk</td><td>' + record.barometer.toFixed(0) + '</td></tr>';
   if ((record.gps_latitude != 0) && (record.gps_longitude != 0))
    html += '<tr><td>GPS</td><td>' + record.gps_latitude + ' ' + record.gps_longitude + ' ' + record.gps_altitude + '</td></tr>';
   html += '<tr><td>Netwerk</td><td>' + record.net_ifname + ' ' + record.net_address + '</td></tr>';
   if (record.net_ssid)
    html += '<tr><td>WiFi SSID</td><td>' + record.net_ssid + '</td></tr>';
   if (record.net_rssi < 0)
    html += '<tr><td>WiFi signaal</td><td>' + record.net_rssi + '</td></tr>';
   html += '<tr><td>Update interval</td><td>' + record.up_interval + ' sec.</td></tr>';
  }
  html += '</<table>';
  html += '</div>';
  $('#ContentPanel').html(html);
 }

 // Get the data.
 dataAdapter.dataBind();

 websocket.onmessage = function(evt) {
  var msg = evt.data;
  var obj = JSON.parse(msg);
  if (! obj.device && obj.node == record.node) {
   record.online = obj.online;
   if (record.online) {
    record.group_id = obj.group_id;
    record.lastseen = obj.lastseen;
    if (obj.hardwaremake)
     record.harwaremake = obj.hardwaremake;
    if (obj.hardwaremodel)
     record.hardwaremodel = obj.hardwaremodel;
    if (obj.os)
     record.os = obj.os;
    if (obj.os_version)
     record.os_version = obj.os_version;
    if (obj.firmware)
     record.firmware = obj.firmware;
    if (obj.temperature)
     record.temperature = obj.temperature;
    if (obj.humidity)
     record.humidity = obj.humidity;
    record.net_ifname = obj.net_ifname;
    record.net_address = obj.net_address;
    if (obj.net_ssid)
     record.net_ssid = obj.net_ssid;
    if (obj.net_rssi)
     record.net_rssi = obj.net_rssi;
   }
   updateScreen();
  }
 }
});

mercurial