SOLVED : Problem with negative number server script

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
BenGonGon
Posts: 19
Joined: Mon Aug 29, 2011 3:03 pm

SOLVED : Problem with negative number server script

Post by BenGonGon »

Hello,
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:39.55 ESP32_LoadAvg:37.8 ESP32_RSSI:75 ESP32_Signal:-62.5

"ESP32_Temperature" graphed
"ESP32_LoadAvg" graphed
"ESP32_RSSI" graphed
"ESP32_Signal" not graphed :-? (it is dBm, negative number)

Someone have an idea?
Last edited by BenGonGon on Fri Jun 18, 2021 1:35 am, edited 1 time in total.
BenGonGon
Posts: 19
Joined: Mon Aug 29, 2011 3:03 pm

Re: Problem with negative number server script

Post by BenGonGon »

Solved

FYI :
-I have use spine and not cmd.php
-data template->data source item->minimum value checked and "U" for value
-data template->data source item->maximum value checked and "U" for value
-graphic template->scaling options->auto scale checked
-graphic template->scaling options->auto scale options checked and "Use --alt-autoscale (ignoring given limits)" selected
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests