Changeset 917


Ignore:
Timestamp:
Feb 23, 2022, 10:24:50 AM (2 years ago)
Author:
chronos
Message:
  • Added: Support for reading signal from RouterOS W60G wireless devices.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Version.php

    r915 r917  
    11<?php
    22
    3 $Revision = 915; // Subversion revision
     3$Revision = 917; // Subversion revision
    44$DatabaseRevision = 911; // SQL structure revision
    5 $ReleaseTime = strtotime('2021-12-07');
     5$ReleaseTime = strtotime('2022-02-23');
  • trunk/Modules/Network/Network.php

    r914 r917  
    384384        'Value' => array('Type' => 'Integer', 'Caption' => 'Signál', 'Default' => '0', 'Suffix' => 'dBm'),
    385385        'Remote' => array('Type' => 'Integer', 'Caption' => 'Vzdálený signál', 'Default' => '0', 'Suffix' => 'dBm'),
    386         'RateRx' => array('Type' => 'Integer', 'Caption' => 'Rychlost Rx', 'Default' => '0', 'Suffix' => 'MHz'),
    387         'RateTx' => array('Type' => 'Integer', 'Caption' => 'Rychlost Tx', 'Default' => '0', 'Suffix' => 'MHz'),
     386        'RateRx' => array('Type' => 'Integer', 'Caption' => 'Rychlost Rx', 'Default' => '0', 'Suffix' => 'Mbps'),
     387        'RateTx' => array('Type' => 'Integer', 'Caption' => 'Rychlost Tx', 'Default' => '0', 'Suffix' => 'Mbps'),
    388388        'Device' => array('Type' => 'TNetworkDevice', 'Caption' => 'Měřeno z', 'Default' => '0'),
    389389      ),
  • trunk/Modules/NetworkConfigRouterOS/Generators/Signal.php

    r911 r917  
    33class ConfigRouterOSSignal extends NetworkConfigItem
    44{
     5  private int $Time;
     6
    57  function ReadWirelessRegistration(): void
    68  {
    7     $Time = time();
     9    $this->Time = time();
    810    $Queries = array();
    9 
    10     // Load netwatch status from all DHCP routers
     11   
    1112    $DbResult3 = $this->Database->query('SELECT `Id`, '.
    12         '(SELECT `LocalIP` FROM `NetworkInterface` WHERE `NetworkInterface`.`Device` = `NetworkDevice`.`Id` LIMIT 1) AS `LocalIP` '.
    13         'FROM `NetworkDevice` WHERE (`API` = 1) AND (`Used` = 1)');
     13      '(SELECT `LocalIP` FROM `NetworkInterface` WHERE `NetworkInterface`.`Device` = `NetworkDevice`.`Id` LIMIT 1) AS `LocalIP`, '.
     14      '`Name` '.
     15      'FROM `NetworkDevice` WHERE (`API` = 1) AND (`Used` = 1)');
    1416    while ($Device = $DbResult3->fetch_assoc())
    1517    {
    16       echo($Device['LocalIP']."\n");
     18      echo($Device['LocalIP'].' ('.$Device['Name'].")\n");
    1719      $Routerboard = new RouterosAPI();
    1820      //$Routerboard->SSL = true;
     
    2022      $Routerboard->Connect($Device['LocalIP'], $this->System->Config['API']['UserName'], $this->System->Config['API']['Password']);
    2123      if (!$Routerboard->Connected) continue;
    22       $Routerboard->Write('/interface/wireless/registration-table/getall', false);
    23       $Routerboard->Write('=.proplist=signal-strength,tx-signal-strength,mac-address,rx-rate,tx-rate', false);
    24       $Routerboard->Write('=stats=');
    25       $Read = $Routerboard->Read(false);
    26       $Array = $Routerboard->ParseResponse($Read);
    27       foreach ($Array as $Properties)
    28       {
    29         $DbResult = $this->Database->select('NetworkInterface', 'Id', 'MAC="'.$Properties['mac-address'].'"');
    30         if ($DbResult->num_rows > 0)
    31         {
    32           $DbRow = $DbResult->fetch_assoc();
    33           $Interface = $DbRow['Id'];
    34         } else $Interface = 'NULL';
    3524
    36         if (strpos($Properties['signal-strength'], '@') === false)
    37         {
    38           $Strength = $Properties['signal-strength'];
    39         } else
    40         {
    41           $Parts = explode('@', $Properties['signal-strength']);
    42           if (substr($Parts[0], -3) == 'dBm')
    43             $Strength = substr($Parts[0], 0, -3); // without dBm
    44             else $Strength = $Parts[0];
    45         }
    46 
    47         if (array_key_exists('tx-signal-strength', $Properties))
    48         {
    49           if (strpos($Properties['tx-signal-strength'], '@') === false)
    50           {
    51             $RemoteSignal = $Properties['tx-signal-strength'];
    52           } else
    53           {
    54             $Parts = explode('@', $Properties['tx-signal-strength']);
    55             if (substr($Parts[0], -3) == 'dBm')
    56               $RemoteSignal = substr($Parts[0], 0, -3); // without dBm
    57               else $RemoteSignal = $Parts[0];
    58           }
    59         } else $RemoteSignal = 0;
    60 
    61         $RateRx = $this->StripUnits($Properties['rx-rate']);
    62         $RateTx = $this->StripUnits($Properties['tx-rate']);
    63         $Queries[] = 'INSERT INTO `NetworkSignal` (`MAC`, `Value`, `Remote`, `RateRx`, `RateTx`, `Time`, `Interface`, `Device`) VALUES '.
    64           '("'.$Properties['mac-address'].'", '.$Strength.', '.$RemoteSignal.', '.$RateRx.', '.$RateTx.', "'.
    65           TimeToMysqlDateTime($Time).'", '.$Interface.', '.$Device['Id'].')';
    66         /*
    67          $DbResult = $this->Database->select('Measure', 'Id', '`Name` = "'.$Properties['mac-address'].'"');
    68          if ($DbResult->num_rows > 0)
    69          {
    70          $this->Database->insert('Measure', array('Name' => $Properties['mac-address']));
    71          $Id = $this->Database->LastInsertId;
    72          } else {
    73          $DbRow = $DbResult->fetch_assoc();
    74          $Id = $DbRow['Id'];
    75          }
    76          $Measure = new Measure($Id);
    77          $Measure->Load($Id);
    78          $Measure->AddValue($Properties['signal-strength']);
    79          */
    80       }
     25      $Queries = array_merge($Queries, $this->ReadWireless($Device, $Routerboard));
     26      $Queries = array_merge($Queries, $this->ReadWireless60G($Device, $Routerboard));
    8127    }
    8228    $this->Database->Transaction($Queries);
    8329  }
    8430
    85   function StripUnits($Value): string
     31  // Read normal wireless clients signal
     32  function ReadWireless(array $Device, RouterosAPI $Routerboard): array
     33  {
     34    $Queries = array();
     35     
     36    $Routerboard->Write('/interface/wireless/registration-table/getall', false);
     37    $Routerboard->Write('=.proplist=signal-strength,tx-signal-strength,mac-address,rx-rate,tx-rate', false);
     38    $Routerboard->Write('=stats=');
     39    $Read = $Routerboard->Read(false);
     40    $Array = $Routerboard->ParseResponse($Read);
     41    foreach ($Array as $Properties)
     42    {
     43      $DbResult = $this->Database->select('NetworkInterface', 'Id', 'MAC="'.$Properties['mac-address'].'"');
     44      if ($DbResult->num_rows > 0)
     45      {
     46        $DbRow = $DbResult->fetch_assoc();
     47        $Interface = $DbRow['Id'];
     48      } else $Interface = 'NULL';
     49
     50      if (strpos($Properties['signal-strength'], '@') === false)
     51      {
     52        $Strength = $Properties['signal-strength'];
     53      } else
     54      {
     55        $Parts = explode('@', $Properties['signal-strength']);
     56        if (substr($Parts[0], -3) == 'dBm')
     57          $Strength = substr($Parts[0], 0, -3); // without dBm
     58          else $Strength = $Parts[0];
     59      }
     60
     61      if (array_key_exists('tx-signal-strength', $Properties))
     62      {
     63        if (strpos($Properties['tx-signal-strength'], '@') === false)
     64        {
     65          $RemoteSignal = $Properties['tx-signal-strength'];
     66        } else
     67        {
     68          $Parts = explode('@', $Properties['tx-signal-strength']);
     69          if (substr($Parts[0], -3) == 'dBm')
     70            $RemoteSignal = substr($Parts[0], 0, -3); // without dBm
     71            else $RemoteSignal = $Parts[0];
     72        }
     73      } else $RemoteSignal = 0;
     74
     75      $RateRx = $this->StripUnits($Properties['rx-rate']);
     76      $RateTx = $this->StripUnits($Properties['tx-rate']);
     77      $Queries[] = 'INSERT INTO `NetworkSignal` (`MAC`, `Value`, `Remote`, `RateRx`, `RateTx`, `Time`, `Interface`, `Device`) VALUES '.
     78        '("'.$Properties['mac-address'].'", '.$Strength.', '.$RemoteSignal.', '.$RateRx.', '.$RateTx.', "'.
     79        TimeToMysqlDateTime($this->Time).'", '.$Interface.', '.$Device['Id'].')';             
     80    }
     81    return $Queries;
     82  }
     83
     84  // Read 60 GHz wireless clients signal
     85  function ReadWireless60G(array $Device, RouterosAPI $Routerboard): array
     86  {
     87    $Queries = array();
     88   
     89    $Routerboard->Write('/interface/w60g/monitor', false);
     90    $Routerboard->Write('=.proplist=tx-phy-rate,rssi,remote-address', false);
     91    $Routerboard->Write('=numbers=wlan60-1', false);
     92    $Routerboard->Write('=once=');
     93    $Read = $Routerboard->Read(false);
     94    $Array = $Routerboard->ParseResponse($Read);
     95    if (array_key_exists('!trap', $Array))
     96    {
     97      //print_r($Array['!trap']);
     98      return array();
     99    }   
     100    foreach ($Array as $Properties)
     101    {
     102      $DbResult = $this->Database->select('NetworkInterface', 'Id', 'MAC="'.$Properties['remote-address'].'"');
     103      if ($DbResult->num_rows > 0)
     104      {
     105        $DbRow = $DbResult->fetch_assoc();
     106        $Interface = $DbRow['Id'];
     107      } else $Interface = 'NULL';
     108
     109      if (strpos($Properties['rssi'], '@') === false)
     110      {
     111        $Strength = $Properties['rssi'];
     112      } else
     113      {
     114        $Parts = explode('@', $Properties['rssi']);
     115        if (substr($Parts[0], -3) == 'dBm')
     116          $Strength = substr($Parts[0], 0, -3); // without dBm
     117          else $Strength = $Parts[0];
     118      }
     119
     120      $RateTx = $this->StripUnits($Properties['tx-phy-rate']);
     121      $Queries[] = 'INSERT INTO `NetworkSignal` (`MAC`, `Value`, `Remote`, `RateRx`, `RateTx`, `Time`, `Interface`, `Device`) VALUES '.
     122        '("'.$Properties['remote-address'].'", '.$Strength.', 0, 0, '.round($RateTx / 1000000).', "'.
     123        TimeToMysqlDateTime($this->Time).'", '.$Interface.', '.$Device['Id'].')';             
     124    }
     125    return $Queries;
     126  }
     127
     128  function StripUnits(string $Value): string
    86129  {
    87130    if (strpos($Value, '-') !== false) $Value = substr($Value, 0, strpos($Value, '-') - 1); // without channel info
    88131    if (substr($Value, -3, 3) == "MHz") $Value = substr($Value, 0, -3); // without MHz unit
    89     if (substr($Value, -4, 4) == "Mbps") $Value = substr($Value, 0, -4); // without Mbps unit
    90     if (substr($Value, -3, 3) == "Mbp") $Value = substr($Value, 0, -3); // without Mbp unit
    91     if (substr($Value, -1, 1) == "M") $Value = substr($Value, 0, -1); // without M unit
     132    else if (substr($Value, -4, 4) == "Mbps") $Value = substr($Value, 0, -4); // without Mbps unit
     133    else if (substr($Value, -3, 3) == "Mbp") $Value = substr($Value, 0, -3); // without Mbp unit
     134    else if (substr($Value, -1, 1) == "M") $Value = substr($Value, 0, -1); // without M unit
     135    else if (substr($Value, -4, 4) == "Gbps") $Value = substr($Value, 0, -4) * 1000; // without Gbps unit
     136    else if (substr($Value, -3, 3) == "Gbp") $Value = substr($Value, 0, -3) * 1000; // without Gbp unit
     137    else if (substr($Value, -1, 1) == "G") $Value = substr($Value, 0, -1) * 1000; // without G unit
    92138    return $Value;
    93139  }
Note: See TracChangeset for help on using the changeset viewer.