I have problem with negative number.
my script :
Code: Select all
<?php
$no_http_headers = true;
/* display No errors */
error_reporting(E_ERROR);
include_once(dirname(__FILE__) . "/../include/config.php");
include_once(dirname(__FILE__) . "/../lib/snmp.php");
if (!isset($called_by_script_server))
{
array_shift($_SERVER["argv"]);
print call_user_func_array("ss_tasmota_ESP32", $_SERVER["argv"]);
}
function ss_tasmota_ESP32($hostname)
{
$tableauNom=array();
$tableauSample=array();
$tableauResultat=array();
$oversampling = 1; //nombre d'échantillon
$pause = 0; //temps en milliseconde
for ($cpt=0 ; $cpt<$oversampling ; $cpt++){
usleep(rand(0, $pause) * 1000);
$results = file_get_contents('http://10.230.77.140:1880/' . $hostname);
$results = json_decode($results);
$tableauSample[0][$cpt] = $results->{'StatusSNS'}->{'ESP32'}->{'Temperature'};
$tableauNom[0] = "ESP32_Temperature";
$tableauSample[1][$cpt] = $results->{'StatusSNS'}->{'ESP32'}->{'LoadAvg'};
$tableauNom[1] = "ESP32_LoadAvg";
$tableauSample[2][$cpt] = $results->{'StatusSNS'}->{'ESP32'}->{'RSSI'};
$tableauNom[2] = "ESP32_RSSI";
$tableauSample[3][$cpt] = $results->{'StatusSNS'}->{'ESP32'}->{'Signal'};
$tableauNom[3] = "ESP32_Signal";
}
$nbEle = count($tableauNom);
for ($cpt=0 ; $cpt<$nbEle ; $cpt++){
$tableauResultat[$cpt] = 0;
}
for ($cpt=0 ; $cpt<$nbEle ; $cpt++){
for ($cpt1=0 ; $cpt1<$oversampling ; $cpt1++){
$tableauResultat[$cpt] += $tableauSample[$cpt][$cpt1];
}
$tableauResultat[$cpt] = $tableauResultat[$cpt] / $oversampling;
}
// example - ps_total:56 ps_i:5 ps_d:9\n
$results = "";
for ($cpt=0 ; $cpt<$nbEle ; $cpt++){
$results .= $tableauNom[$cpt] . ":" . $tableauResultat[$cpt] . " ";
}
$results .= "\n";
return($results);
}
?>
"ESP32_Temperature" graphed
"ESP32_LoadAvg" graphed
"ESP32_RSSI" graphed
"ESP32_Signal" not graphed (it is dBm, negative number)
Someone have an idea?