meterN 1.0

Talks about metering
jeanmarc
Posts: 2057
Joined: Thu Aug 29, 2013 7:16 am

Re: meterN 1.0

Post by jeanmarc » Tue Jan 14, 2020 4:44 pm

Hi solidtear,
I haven't changed that part. Check in data/meters/xxxx2020.csv and 2019 files, you may have an empty line somewhere. I don't know the reason..
Also beware to keep the good permission to allow 'http' user to write in them.

solidtear
Posts: 3
Joined: Tue Jan 14, 2020 9:58 am

Re: meterN 1.0

Post by solidtear » Tue Jan 14, 2020 5:33 pm

You're right, there was an extra carriage return in one of the files.
Thank you

robinc
Posts: 18
Joined: Wed Jul 13, 2016 2:07 pm

Re: meterN 1.0

Post by robinc » Fri Jan 17, 2020 2:02 pm

Hi,
I have previously been unsuccessful in upgrading to meterN 1.2 ( refer to my previous post dated 18Oct 2019 )
I have now attempted to upgrade to 1.2.2 and encountered the same issue with both the power 'gauge' and live values on the index page always displaying a value of '0'
Also the dashboard page shows a 'communication lost' error.
These same symptoms were also reported by another user.

I believe I have now identified the cause of the issue ....

Firstly I found that the /dev/shm/mN_LIVEMEMORY file contained valid 'live' values but the UTC timestamp was zero ( "UTC":0 )

Also, I turned on debug and found many of the following error messsages :

Code: Select all

PHP Warning:  exec(): Cannot execute a blank command in /srv/http/metern/scripts/metern.php on line 23
PHP Warning:  implode(): Argument must be an array in /srv/http/metern/scripts/metern.php on line 24

It seems that the following test at line 21 of metern.php fails for all of those meters that have no live command configured. This results in the UTC timestamp getting set to zero.

Code: Select all

if (!${'SKIPMONITORING' . $metnum} &&  isset(${'LIVECOMMAND' . $metnum})) {
I have made the following change to line 21 and this seems to have resolved the problem for me.

Code: Select all

if (!${'SKIPMONITORING' . $metnum} &&  !empty(${'LIVECOMMAND' . $metnum}) ) {
Not sure why this does not seem to affect all other users .....

I am running PHP 7.3.0 on Arch-ARMv7

Thanks,
Robin Clipsham

jeanmarc
Posts: 2057
Joined: Thu Aug 29, 2013 7:16 am

Re: meterN 1.0

Post by jeanmarc » Fri Jan 17, 2020 4:51 pm

Hi Robin,
Thanks for the tips :) I guess it's a bug and i will change that. Oddly it work for me if i have an empty command like $LIVECOMMANDx="";

robinc
Posts: 18
Joined: Wed Jul 13, 2016 2:07 pm

Re: meterN 1.0

Post by robinc » Sun Jan 19, 2020 8:13 am

Hi JM,

I am afraid my PHP skills are very limited, but the following link http://docs.php.net/manual/en/types.comparisons.php seems to confirm that 'isset()' returns true for an empty string, so yes I think it is a genuine bug.

Now to another issue -
meterN 1.2 displays a long list of unused live values in the 'livetable' on the index page ( as reported by fabio on 24Aug 2019 )
I am keen to get rid of this table of unused values and have been attempting to develop a fix ( with little success :roll: )....

I added code to index php line 678 as follows :

Code: Select all

if ($livetab) {
        echo "<br>
<table border=1 class='table' cellspacing=0 cellpadding=5 align='center' width=>
        for ($i = 1; $i <= $NUMMETER; $i++) {
           if ( !empty(${'LIVECOMMAND' . $metnum}) )    // line added
                        echo "<tr align='center'><td width='50%'><b>${'METNAME'>
          }  //line added
        }
        echo '
</table>';
This correctly reduces the size of the 'livetable', but for some reason the indicator values in the following table are no longer displayed.
I am really struggling to figure out why this occurs.
Just to prove a point, I changed the code to :-

Code: Select all

if ($livetab) {
        echo "<br>
<table border=1 class='table' cellspacing=0 cellpadding=5 align='center' width=>
        for ($i = 1; $i <= 2; $i++) {
                        echo "<tr align='center'><td width='50%'><b>${'METNAME'>
        }
        echo '
</table>';
This produces the same result ie the indicator values are no longer displayed.
Image
The only way to get the indicator values to display correctly, is if all eleven of the livetable values are displayed.
Image
Even if 10 of the 11 livetable entries are displayed, then the indicator values no longer work.
Image

I am at a loss to understand why this is so ....

I wondered if you had any ideas or whether you had looked into this since the problem has been reported before ...

Thanks & Regards,
Robin Clipsham

jeanmarc
Posts: 2057
Joined: Thu Aug 29, 2013 7:16 am

Re: meterN 1.0

Post by jeanmarc » Sun Jan 19, 2020 11:07 am

Hi Robin,
I wasn't aware of that request, maybe i didn't understand or i pass over it.
Your code have few glitches, here's the correct index.php

Code: Select all

<?php
/**
 * /srv/http/metern/index.php
 *
 * @package default
 */

include 'styles/globalheader.php';
include 'config/memory.php';
if (!file_exists($MEMORY)) {
	header('Location: admin/');
}
include 'config/config_main.php';
include 'config/config_indicator.php';
include 'config/config_layout.php';

$graphlist = array();
$unitlist  = array();

echo "
<script type='text/javascript'>
function formatNum(num) {
if(!isNaN(num) && num != null){
  var str = num.toLocaleString('en-US');
  str = str.replace(/\./, 'x');
  str = str.replace(/,/g, '$THSEP');
  str = str.replace('x', '$DPOINT');
  return str;
} else {
  return num;
}
}
</script>
<script type='text/javascript'>
$(document).ready(function()
{
function updateit() {
$.getJSON('programs/programlive.php', function(json){
GRIDTOT=0;
CTOT=0;
PTOT=0;";

$housecons = false;
$houseprod = false;
$showlastd = false;
$livetab   = false;

for ($i = 1; $i <= $NUMMETER; $i++) {
	include "config/config_met$i.php";
	if (!isset(${'GRAPH_MET' . $i})) {
		${'GRAPH_MET' . $i} = 0;
	}
	if (!in_array(${'GRAPH_MET' . $i}, $graphlist) && ${'GRAPH_MET' . $i} != 0) {
		$graphlist[] = ${'GRAPH_MET' . $i};
	}
	if (${'LASTD_MET' . $i}) {
		$showlastd = true;
		$check[$i] = true; //detailed
	} else {
		${'LASTD_MET' . $i} = false;
		$check[$i] = false;
	}
	if (!empty(${'LIVECOMMAND' . $i})) {
		$livetab = true;
		echo "
val$i =json['${'METNAME'.$i}$i'];";
	}
	if (${'TYPE' . $i} == 'Elect' && !empty(${'LIVECOMMAND' . $i})) {
		echo "
if(isNaN(val$i)){
val$i = 0;
} else {
val$i = parseFloat(val$i);
}";
		if (${'PROD' . $i} == 2) {
			$housecons = true;
			echo "
CTOT+=val$i;";
		} elseif (${'PROD' . $i} == 1) {
			$houseprod = true;
			echo "
PTOT+=val$i;";
		}
	}
}

if ($houseprod && $housecons) {
	echo '
GRIDTOT=parseInt(CTOT-PTOT);
';
	$Yg2 = round(($POWER_MIN / 3), 0);
	$Yg1 = round($Yg2 * 2, 0);
	$Yg3 = 0;
	$Yg4 = round(($POWER_MAX / 3), 0);
	$Yg5 = round($Yg4 * 2, 0);

	$gcolor = array(
		'0DB44C',
		'2EC846',
		'94DE40',
		'F29D16',
		'F76415',
		'F10D17'
	);
} elseif ($houseprod && !$housecons) {
	echo '
GRIDTOT=parseInt(PTOT);
';
	$POWER_MIN = 0;
	$Yg1       = round(($POWER_MAX / 5), 0);
	$Yg2       = round($Yg1 * 2, 0);
	$Yg3       = round($Yg1 * 3, 0);
	$Yg4       = round($Yg1 * 4, 0);
	$Yg5       = round($Yg1 * 5, 0);

	$gcolor = array(
		'F10D17',
		'F76415',
		'F29D16',
		'94DE40',
		'2EC846',
		'0DB44C'
	);

} elseif (!$houseprod && $housecons) {
	echo '
GRIDTOT=parseInt(CTOT);
';
	$POWER_MIN = 0;
	$Yg1       = round(($POWER_MAX / 6), 0);
	$Yg2       = round($Yg1 * 2, 0);
	$Yg3       = round($Yg1 * 3, 0);
	$Yg4       = round($Yg1 * 4, 0);
	$Yg5       = round($Yg1 * 5, 0);

	$gcolor = array(
		'0DB44C',
		'2EC846',
		'94DE40',
		'F29D16',
		'F76415',
		'F10D17'
	);
}

for ($i = 1; $i <= $NUMMETER; $i++) {
	if (!empty(${'LIVECOMMAND' . $i}) && !${'SKIPMONITORING' . $i}) {
		echo "
if (typeof val$i === 'undefined') {
document.getElementById('rval$i').innerHTML = 'err';
} else {
	document.getElementById('rval$i').innerHTML = formatNum(val$i);
}";
	}
}
if ($NUMIND > 0) { // indicators
	echo "

$.getJSON('programs/programindicator.php', function(json){";
	for ($i = 1; $i <= $NUMIND; $i++) {
		if (!empty(${'INDCOMMAND' . $i})) {
			echo "
ival$i =json['${'INDNAME'.$i}$i'];
if (typeof ival$i === 'undefined') {
document.getElementById('rival$i').innerHTML = 'err';
} else {
	document.getElementById('rival$i').innerHTML = formatNum(ival$i);
}";
		}
	}
	echo '
	})';
} // indicators
echo '
})
}
updateit();
setInterval(updateit, 1000);
});
</script>';

sort($graphlist);
$cntgraph = count($graphlist);

echo "
<script type='text/javascript'>
$(document).ready(function()
{
Highcharts.setOptions({
global: {useUTC: true},
lang: {
decimalPoint: '$DPOINT',
thousandsSep: '$THSEP',
months: ['";
for ($i = 1; $i < 12; $i++) {
	echo "$lgMONTH[$i]','";
}
echo "$lgMONTH[12]'],
shortMonths: ['";
for ($i = 1; $i < 12; $i++) {
	echo "$lgSMONTH[$i]','";
}
echo "$lgSMONTH[12]'],
weekdays: ['";
for ($i = 1; $i < 7; $i++) {
	echo "$lgWEEKD[$i]','";
}
echo "$lgWEEKD[7]'],
drillUpText: '$lgDRILLUP',
loading: '$lgLOAD',
printChart: '$lgPRINT',
resetZoom: '$lgRESETZ'
}
});";

for ($i = 0; $i < $cntgraph; $i++) {
	$unitlist[$i] = array();
	echo "

var Mychart$i, options$i = {
chart: {
backgroundColor: null,
zoomType: 'xy',
         events: {
            load: function() {
              setInterval(function() {
               $.getJSON('programs/programmeter.php', function(JSONResponse){
        Mychart$i.setTitle({ text: JSONResponse.title[$i]});";
	$h = 0;
	for ($j = 0; $j < $NUMMETER; $j++) {
		$k = $j + 1;
		if (${'GRAPH_MET' . $k} == $graphlist[$i]) {
			echo "\n\t\tMychart$i.series[$h].update(JSONResponse.data[$j], true);";
			$h++;
		}
	}
	echo "\n\t\tMychart$i.redraw();
               });
               }, 60000);
            }
         }
},
loading: {
 labelStyle: { top: '45%'  },
  style: { backgroundColor: null }
},
title: {
text: 'loading..'
},
subtitle: {
},
credits: {enabled: false},
legend: {
align: 'left',
verticalAlign: 'top',
x: 70,
y: 40,
floating: true
},
plotOptions: {
areaspline: {
   threshold: null,
   softThreshold: true,
   marker: {
   enabled: false,
   symbol: 'circle',
   radius: 2,
   states: {hover: {enabled: true}}
   }
},
series: {
}
},
xAxis: {
type: 'datetime'
},
yAxis: [";
	for ($j = 1; $j <= $NUMMETER; $j++) {
		if (${'GRAPH_MET' . $j} == $graphlist[$i] && !in_array(${'UNIT' . $j}, $unitlist[$i])) {
			$unitlist[$i][] = ${'UNIT' . $j};
			$cnt            = count($unitlist[$i]);
			if ($cnt > 1) {
				echo ",";
			}
			echo "
{
title: {text: '${'UNIT'.$j}'}
}";

		}
	}
	echo "
],
tooltip: {
    crosshairs: {
        width: 1,
        color: 'gray',
        dashStyle: 'shortdot'
    },
formatter: function() {
";
	for ($j = 1; $j <= $NUMMETER; $j++) {
		if ($j == 1) {
			echo ' if';
		} else {
			echo ' else if';
		}
		echo "(this.series.name=='${'METNAME'.$j}') { return '<b>' + Highcharts.numberFormat(this.y,'${'PRECI'.$j}') + ' ${'UNIT'.$j}' + '</b>";
		if (${'TYPE' . $j} != 'Elect') {
			echo "<br>' + Highcharts.dateFormat('%a %e %b %H:%M', this.x) }";
		} else {
			echo " ~' + Highcharts.numberFormat(this.y*12,'0') + 'W $lgAVG<br>' + Highcharts.dateFormat('%a %e %b %H:%M', this.x)}";
		}
	}
	echo "
}
},
exporting: {enabled: false},
series: []
};

Mychart$i= Highcharts.chart('container$i',options$i);
Mychart$i.showLoading();
";
}
echo "
$.getJSON('programs/programmeter.php', function(JSONResponse) {";
for ($i = 0; $i < $cntgraph; $i++) {
	$sernum = 0;
	for ($k = 0; $k < $NUMMETER; $k++) {
		$j = $k + 1;
		if (${'GRAPH_MET' . $j} == $graphlist[$i]) {
			echo "
    options$i.series[$sernum] = JSONResponse.data[$k];";
			$sernum++;
		}
	}

	echo "
    Mychart$i= Highcharts.chart('container$i',options$i);
    Mychart$i.setTitle({text: JSONResponse.title[$i]});
    Mychart$i.xAxis[0].addPlotBand({from: JSONResponse.ystrtp, to: JSONResponse.ystpp, color: 'rgba(190,190,190,.3)'});
    Mychart$i.xAxis[0].addPlotBand({from: JSONResponse.tstrtp, to: JSONResponse.tstpp, color: 'rgba(190,190,190,.3)'});
    Mychart$i.xAxis[0].addPlotLine ({ color: '#848484', value: JSONResponse.plotline, width: 1, dashStyle: 'Solid'});
    Mychart$i.hideLoading();
    ";
}
echo "
});
";

if ($showlastd) {
	$unitlist = array();
	$getvalue = json_encode($check);
	echo "
/// Last days prod ///
var Mychart$i, options$i = {
chart: {
backgroundColor: null,
defaultSeriesType: 'column',
zoomType: 'xy'
},
loading: {
   labelStyle: { top: '45%'  },
   style: { backgroundColor: null }
},
credits: {enabled: false},
title: {
text: '$lgLAST 15 $lgDAYS'
},
subtitle: {text: '$lgLASTPRODSUBTITLE'},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {day: '%e %b'}
},
yAxis: [";
	for ($j = 1; $j <= $NUMMETER; $j++) {
		if (${'LASTD_MET' . $j} && !in_array(${'UNIT' . $j}, $unitlist)) {
			$unitlist[] = ${'UNIT' . $j};
			$cnt        = count($unitlist);
			if ($cnt > 1) {
				echo ',';
			}
			if (${'TYPE' . $j} != 'Elect') {
				echo "
{
title: {text: '${'UNIT'.$j}'}
}";
			} else {
				echo "
{
title: {text: 'kWh'}
}";
			}

		}
	}
	echo "
],
legend: {
},
tooltip: {
    formatter: function() {
";
	for ($j = 1; $j <= $NUMMETER; $j++) {
		if ($j == 1) {
			echo "     if";
		} else {
			echo " else if";
		}
		echo "(this.series.name=='${'METNAME'.$j}') {
      return Highcharts.dateFormat('%A %d %B', this.x) + '<br>'+ this.series.name + ' <b>' +";
		if (${'TYPE' . $j} == 'Elect') {
			echo "Highcharts.numberFormat(this.y,2) + ' k${'UNIT'.$j}' + '</b>'";
		} else {
			echo "Highcharts.numberFormat(this.y,'${'PRECI'.$j}') + ' ${'UNIT'.$j}' + '</b>'";
		}
		if (${'PRICE' . $j} > 0) {
			echo " + ' (' + Highcharts.numberFormat((this.y*${'PRICE'.$j}),1) + ' $CURS)'";
		}
		echo '
    }';
	}
	echo "
}
},
plotOptions: {
    series: {
    shadow: false,
    minPointLength: 3,
    pointWidth: 15,
        point:{
      events: {
        click: function(event) {
        window.location = 'detailed.php?meter=$getvalue&date2='+this.x;
        }
      }
    }
  }
},
exporting: {enabled: false},
series: []
};

Mychart$i= Highcharts.chart('container$i',options$i);
Mychart$i.showLoading();

    $.getJSON('programs/programlastdays.php', function(JSONResponse) {";
	$k = 0;
	for ($j = 1; $j <= $NUMMETER; $j++) {
		if (${'LASTD_MET' . $j}) {
			echo "
    options$i.series[$k] = JSONResponse.data[$k]";
			$k++;
		}
	}
	echo "
    Mychart$i= Highcharts.chart('container$i',options$i);
    Mychart$i.hideLoading();
    });
";
	$i++;
} // if showlastd

if ($housecons || $houseprod) {
	echo "
/// Gauge ///
var Mygauge, options$i = {
  chart: {
    type: 'gauge',
    backgroundColor: null,
    plotBackgroundColor: null,
    plotBackgroundImage: null,
    plotBorderWidth: 0,
    plotShadow: false,
    height: 225,
  events: {
        load: function() {
        setInterval(function () {
        var point = Mygauge.series[0].points[0];
        point.update(GRIDTOT);
        }, 1000);
            }
         }
  },
  loading: {
  labelStyle: { top: '45%'  },
  style: { backgroundColor: null }
  },
  title: {
    text: ''
  },
  plotOptions: {
  gauge: {
    pivot: {
      radius: 8,
      borderWidth: 1,
      borderColor: '#303030',
      backgroundColor: {
        linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
        stops: [
          [0, '#AAA'],
          [1, '#333']
        ]
      }
    },
    dial: {
      baseLength : 10,
      baseWidth: 8,
      backgroundColor: '#666',
      radius : 70,
      rearLength: 40
    }
  }},
  pane: {
    startAngle: -150,
    endAngle: 150,
            background: [{
                backgroundColor: {
                    linearGradient: { x1: 0, y1: 1, x2: 0, y2: 0 },
                    stops: [
                        [0, '#333'],
                        [1, '#AAA']
                    ]
                },
                borderWidth: 0,
                outerRadius: '115%'
            }, {
                backgroundColor: {
                    linearGradient: { x1: 0, y1: 1, x2: 0, y2:0 },
                    stops: [
                        [0, '#AAA'],
                        [1, '#FFF']
                    ]
                },
                borderWidth: 1,
                outerRadius: '113%'
            },{
                // default background
            }, {
                backgroundColor: Highcharts.svg ? {
                    radialGradient: {
                        cx: 0.5,
                        cy: -0.6,
                        r: 1.6
                    },
                    stops: [
                        [0.5, 'rgba(255, 255, 255, 0.1)'],
                        [0.3, 'rgba(200, 200, 200, 0.1)']
                    ]
                } : null },{
                backgroundColor: Highcharts.svg ? {
                    radialGradient: {
                        cx: 0.5,
                        cy: -0.9,
                        r: 2.6
                    },
                    stops: [
                        [0.5, 'rgba(255, 255, 255, 0.1)'],
                        [0.3, 'rgba(200, 200, 200, 0.1)']
                    ]
                } : null }
                        ]
  },
  yAxis: {
    min: $POWER_MIN,
    max: $POWER_MAX,

    minorTickInterval: 'auto',
    minorTickWidth: 1,
    minorTickLength: 5,
    minorTickPosition: 'inside',
    minorTickColor: '#666',

    tickPixelInterval: 50,
    tickWidth: 2,
    tickPosition: 'inside',
    tickLength: 15,
    tickColor: '#666',
    labels: {
      step: 2,
      rotation: 'auto'
    },
    title: {
      style: {
        color: '#555',
        fontSize: '18px'
      },
      y: 125,
      text: 'W'
    },
    plotBands: [{
      from: $POWER_MIN,
      to: $Yg1,
      color: '#$gcolor[0]'
    }, {
      from: $Yg1,
      to: $Yg2,
      color: '#$gcolor[1]'
    }, {
      from: $Yg2,
      to: $Yg3,
      color: '#$gcolor[2]'
    }, {
      from: $Yg3,
      to: $Yg4,
      color: '#$gcolor[3]'
    }, {
      from: $Yg4,
      to: $Yg5,
      color: '#$gcolor[4]'
    }, {
      from: $Yg5,
      to: $POWER_MAX,
      color: '#$gcolor[5]'
    }]
  },
  exporting: {enabled: false},
  credits: {enabled: false},
  series: [{
    name: 'power',
    data: [0],
    tooltip: {
      valueSuffix: 'W'
    },
    overshoot: 5,
    dataLabels: {
      enabled: true,
	  allowOverlap: true,
  formatter: function() {
        if (this.y>=1000 || this.y<=1000) {
        return Highcharts.numberFormat(this.y,0);
        } else {
        return Highcharts.numberFormat(this.y,1);
        }
  },
      color: '#666',
      x: 0,
      y: 40,
      style: {
      fontSize: '12px'
      }
    }
  }]
};

Mygauge = Highcharts.chart('gcontainer',options$i);
Mygauge.series[0].data[0].dataLabel.box.hide();
";
}

echo "
});
</script>
<table width='100%' border=0 align=center cellpadding=0 cellspacing=0>
<tr valign='top'><td>
<table width='100%' border=0 align=center cellpadding=0 cellspacing=0>";
for ($i = 0; $i < $cntgraph; $i++) {
	echo "<tr><td><div id='container$i' style='height: ${GRAPHH}px'></div></td></tr>";
}
if ($showlastd) {
	echo "<tr><td><div id='container$cntgraph' style='height: ${GRAPHH}px'></div></td></tr>";

}
echo '
</table>
</td>
<td width=225>';
if ($housecons || $houseprod) {
	echo "<div id='gcontainer' align='center'></div>";
}

if ($livetab) {
	echo "<br>
<table border=1 class='table' cellspacing=0 cellpadding=5 align='center' width='90%'>";
	for ($i = 1; $i <= $NUMMETER; $i++) {
		if (!empty(${'LIVECOMMAND' . $i})) {
			echo "<tr align='center'><td width='50%'><b>${'METNAME'.$i}</b></td><td><b><span id='rval$i'>...</span> ${'LIVEUNIT'.$i}</b></td></tr>";
		}
	}
	echo '
</table>';
}
if ($NUMIND > 0) { // indicators
	echo "
<br>
<table border=1 class='table' cellspacing=0 cellpadding=5 align='center' width='90%'>";
	for ($i = 1; $i <= $NUMIND; $i++) {
		if (!empty(${'INDCOMMAND' . $i})) {
			echo "<tr align='center'><td width='50%'><b>${'INDNAME'.$i}</b></td><td><b><span id='rival$i'>...</span> ${'INDUNIT'.$i}</b></td></tr>";
		}
	}
	echo '
</table>
<br>&nbsp;
';
} // indicators

echo '
</td></tr>
</table>';
include "styles/$STYLE/footer.php";
?>
and thanks for reporting

robinc
Posts: 18
Joined: Wed Jul 13, 2016 2:07 pm

Re: meterN 1.0

Post by robinc » Sun Jan 19, 2020 12:14 pm

Hi JM,

Yes, that fixes the issue ( don't quite understand how or why ... )

As always, many thanks for your work on 123Solar/meterN and for the rapid responses to issues.

RC

megamarco83
Posts: 108
Joined: Tue Apr 14, 2015 9:25 am

Re: meterN 1.0

Post by megamarco83 » Mon Jan 20, 2020 10:25 am

hi JM, i updated metern and inside admin page, at log debug i find this errors:
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Notice: Undefined variable: LIVEPOOL3 in /var/www/comapps/virtmeter.php on line 453
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Notice: Undefined variable: LIVEPOOL3 in /var/www/comapps/virtmeter.php on line 453
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Notice: Undefined variable: LIVEPOOL3 in /var/www/comapps/virtmeter.php on line 453
/var/www/metern/scripts/metern.php at line 23 and 24 are:
exec(${'LIVECOMMAND' . $metnum}, $datareturn);
$datareturn = trim(implode($datareturn));


/var/www/comapps/virtmeter.php at line 453 is:
if (isset(${'LIVECOMMAND' . $addnumlist[$i]}) == 1 && isset($livemem["${'METNAME'.$addnumlist[$i]}$addnumlist[$i]"])) {

i remember that in the past metern used LIVEPOOL instead of LIVECOMMAND, and you suggest to me to change it, and with the old versione it works without issue.

can you help me on this?
thanks as usual!


p.s.
i attach the complete virtmet.php, maybe is usefull for you

Code: Select all

#!/usr/bin/php
<?php
//
// This script will simulate a meter into a meterN compatible format. 
// This script will evaluate a meter's pool and/or calculate the meter only in time band.
// This script, also, calculates withdrawn energy (imported energy from grid), exported enery
// and self consumption energy.
// The virtmeter should be configured in meterN as 'Elect, Other' 
// If you use virtmeter to estimate house consumption, the virtmeter should be configured in 
// meterN as 'Elect, House consumption' 
//
// Usage: 
//     virtmeter {virtmeternum} {meternumlisttoadd|0} {meternumlisttosub|0} {energy|power} {F1|F2|F3|F23|0} 
//     virtmeter {virtmeternum} {impmeternum} {expmeternum} {housecenergy|housecpower} {F1|F2|F3|F23|0} 
//     virtmeter {virtmeternum} 0 0 {impenergy|expenergy|selfcenergy|imppower|exppower|selfcpower} {F1|F2|F3|F23|0} 
//
//     Where
//         virtmeternum       --> meterID of virtual meter
//         impmeternum        --> meterID of total meter
//         expmeternum        --> meterID of total meter
//         meternumlisttoadd  --> list of meterID to add (0 no add)
//         meternumlisttosub  --> list of meterID to sub (0 no sub)
//
//	
// Example:
//      virtmeter 14 9,11 8 energy 0    -> met14 = met9 + met11 - met8
//      virtmeter 15 12 0 energy F1     -> met15 = met12 (only if F1)
//      virtmeter 16 12 0 energy F23    -> met16 = met12 (only if F23)
//      virtmeter 18 0 0 impenergy 0    -> met18 = withdrawn energy (imported from grid)
//      virtmeter 19 0 0 expenergy F1   -> met19 = exported energy (only if F1)
//      virtmeter 20 0 0 selfcenergy F2 -> met20 = self consumption energy (only if F2)
//
//
// How to:
// 1) Copy the script in /var/www/comapps
//    change owner with command 'chown www-data.www-data virtmeter.php'
//    change permission with command 'chmod +x virtmeter.php'
//    make a link with command 'ln -s /var/www/comapps/virtmeter.php /usr/local/bin/virtmeter'
// 2) In meterN, set your real meters as 'Elect' 'House production | House consumption | Other' 
// 3) Set virtual meter in meterN. The type should be 'Elect Other'
//    Set the 'Main command' and 'Live command' as needed like examples
// 4) Configure the script if necessary ($pathtomn)
// 
//
// Known issues
// This script does not handle the passover (future feature)
//
//
// Copyright (C) 2017 by Garluk
//

/*
* This program 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 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// Path to metern (edit if necessary)
$pathtomn = '/var/www/metern';

//
// No edit should be needed bellow
//
// -----------------------------------------------------------------------------
$version = "0.4.0";

if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}

if (!isset($argv[1], $argv[2], $argv[3], $argv[4], $argv[5])) {
	echo(usage($version));
	die("\nAbording: no valid argument given.\n");
}

//
// function usage: write help screen
//
function usage($version)
{
	$txt = "virtmeter v$version\n"
		. "This script will simulate a meter into a meterN compatible format. \n"
		. "This script will evaluate a meter's pool and/or calculate the meter only in time band.\n"
		. "This script, also, calculates withdrawn energy (imported energy from grid), \n"
		. "exported enery and self consumption energy.\n\n"
		. "Usage:\n"
		. "   virtmeter {virtmeternum} {meternumlisttoadd|0} {meternumlisttosub|0} {energy|power} {<fascia>}\n"
		. "   virtmeter {virtmeternum} {impmeternum} {expmeternum} {housecenergy|housecpower} {<fascia>}\n"
		. "   virtmeter {virtmeternum} 0 0 {impenergy|expenergy|selfcenergy|imppower|exppower|selfcpower} {<fascia>}\n" 
		. "\nWhere:\n"
		. "   virtmeternum\tmeterID of virtual meter\n"
		. "   impmeternum\tmeterID of total meter\n"
		. "   expmeternum\tmeterID of total meter\n"
		. "   meternumlisttoadd\tlist of meterID to add (0 no add)\n"
		. "   meternumlisttosub\tlist of meterID to sub (0 no sub)\n"
		. "   energy\tEstimates virtual meter energy\n"
		. "   impenergy\tWithdrawn energy (imported energy from grid)\n"
		. "   expenergy\tExported energy (exported energy to grid)\n"
		. "   selfcenergy\tSelf consumption energy\n"
		. "   housecenergy\tHouse consumption energy (if you have a own a total import/export and production meter)\n"
		. "   power\t\n"
		. "   imppower\t\n"
		. "   exppower\t\n"
		. "   selfcpower\t\n"
		. "   housecpower\t\n"
		. "   <fascia>\t{F1 | F2 | F3 | F23 | 0}\n\n"
		. "Example:\n"
		. "   virtmeter 14 9,11 8 energy 0    -> met14 = met9 + met11 - met8\n"
		. "   virtmeter 15 12 0 energy F1     -> met15 = met12 (only if F1)\n"
		. "   virtmeter 16 12 0 energy F23    -> met16 = met12 (only if F23)\n"
		. "   virtmeter 18 0 0 impenergy 0    -> met18 = withdrawn energy (imported from grid)\n"
		. "   virtmeter 19 0 0 expenergy F1   -> met19 = exported energy (only if F1)\n"
		. "   virtmeter 20 0 0 selfcenergy F2 -> met20 = self consumption energy (only if F2)\n"
		;

	return $txt;
}


//
// function isFesta: ritorna true se il giorno è festivo 
//
//		I giorni di festa sono:
//			- 1 e 6 gennaio;
//			- lunedì dell'Angelo;
//			- 25 aprile;
//			- 1 maggio;
//			- 2 giugno;
//			- 15 agosto;
//			- 1 novembre;
//			- 8, 25 e 26 dicembre.
//
function isFesta($tsTime) 
{
	$feste = Array(101, 106, 425, 501, 602, 815, 1101, 1208, 1225, 1226);
	
	// Controllo il giorno di Pasquetta
	if (date('Y-m-d', strtotime('+1 day', easter_date())) == date('Y-m-d', $tsTime))
		return (true);
	
	// Controllo le altre feste
	$data100 = (date('n', $tsTime) * 100) + date('d', $tsTime);
	foreach ($feste as $festa) {
		if ($festa == $data100)
			return (true);
	}
	
	return false;
}


//
// function fascia: ritorna la fascia tariffaria 
//
// Fasce tariffarie: F1, F2, F3
//
// Le fasce sono:
// F1 (ore di punta):    dalle ore 8.00 alle ore 19.00 dal lunedì al venerdì
// F2 (ore intermedie):  dalle ore 7.00 alle ore 8.00 e dalle ore 19.00 alle
//                       ore 23.00 dal lunedì al venerdì e dalle ore 7.00 alle
//                       ore 23.00 del sabato;
// F3 (ore fuori punta): dalle ore 00.00 alle ore 7.00 e dalle ore 23.00 alle
//                       ore 24.00 dal lunedì al sabato e tutte le ore della
//                       domenica e dei giorni:
//                              1 e 6 gennaio;
//                              lunedì dell'Angelo;
//                              25 aprile;
//                              1 maggio;
//                              2 giugno;
//                              15 agosto;
//                              1 novembre;
//                              8, 25 e 26 dicembre.
//
function fascia($tsTime) 
{
	$giorno = date("w", $tsTime);	// 0 (dom) -> 6 (sab)
	$ora = date('Hi', $tsTime);		// 23:35 -> 2335
	// Il confronto orario tiene conto del ritardo di metern ad acquisire il dato
	// e considera un possibile ritardo di misura fino a 60 secondi rispetto alle
	// ore "intere". Le letture al termine della fascia oraria vengono
	// considerate appartenenti alla fascia oraria precedente.
	// La prima lettura nella nuova fascia oraria avviene dopo 5 minuti, quindi
	// risulta sempre nell'intervallo temporale di spettanza ed il suo incremento
	// viene aggiunto naturalmente alla fascia oraria corretta.

	// Festivo o domenica -> Fascia F3
	if (isfesta($tsTime) || $giorno == 0)
		return 'F3';

	// se al di fuori della fascia "07:00 - 23:00" --> Fascia F3
	if (!(($ora > "0700") && ($ora <= "2300")))
		return 'F3';

	// se è sabato nella fascia "07:00 - 23:00" --> Fascia F2
	if (($giorno == 6) && ($ora > "0700") && ($ora <= "2300"))
		return 'F2';

	// se si è nella fascia "07:00 - 08:00" oppure nella fascia "19:00 - 23:00" --> Fascia F2
	if ((($ora > "0700") && ($ora <= "0800")) || (($ora > "1900") && ($ora <= "2300")))
		return 'F2';

	// Tutto il resto F1
	return 'F1';
}


//
// function isFascia: restituisce true se l'ora è nella fascia
//
function isFascia($tsTime, $F) 
{
	$result = fascia($tsTime);
	if ($result == $F)
		return true;
	if ($F == '0')
		return true;
	if (($F == 'F23') && (($result == 'F2') || ($result == 'F3')))
		return true;

	return false;
}


//
// function getvalue: Get data and validate with IEC 62056 data set structure
//
function getvalue($id, $cmd)
{
	$datareturn = null;
	$giveup = 0;
	$regexp = "/^$id\(-?[0-9\.]+\*[A-z0-9³²%°]+\)$/i"; //ID(VALUE*UNIT)
    
	while (!isset($datareturn) && $giveup < 3) { // Try 3 times
		exec($cmd, $datareturn);
		$datareturn = trim(implode($datareturn));

		if (preg_match($regexp, $datareturn)) {
			$datareturn = preg_replace("/^$id\(/i", '', $datareturn, 1); // VALUE*UNIT)
			$datareturn = preg_replace("/\*[A-z0-9³²%°]+\)$/i", '', $datareturn, 1); // VALUE
			settype($datareturn, 'int');
		} else {
			$datareturn = null;
		}
		$giveup++;
	}
	
	return $datareturn;
}


//
// function retrievecsv: Retrieve last know value in latest csv
//
function retrievecsv($meternum, $csvarray, $passo, $datareturn) 
{
	$datareturn = null;
	$contalines = count($csvarray);
	$j = 0;
	while (!isset($datareturn)) {
		$j++;
		$array = preg_split('/,/', $csvarray[$contalines - $j]);
		if (count($array) > $meternum) {
			$datareturn = (int) trim($array[$meternum]);
		} else {
			$datareturn = 0;
		}
		if ($datareturn == '') {
			$datareturn = null;
		}
		if ($j == $contalines) {
			$datareturn = 0;
		}
	}
	if ($datareturn > $passo) {
		$datareturn -= $passo;
	}
	return $datareturn;
}



if (($argv[1] != NULL) && ($argv[2] != NULL) && ($argv[3] != NULL) 
	&& ($argv[4] != NULL) && ($argv[5] != NULL)
	&& ($argv[4] == 'power' || $argv[4] == 'energy' ||
		$argv[4] == 'housecpower' || $argv[4] == 'housecenergy' ||
		$argv[4] == 'imppower' || $argv[4] == 'exppower' || $argv[4] == 'selfcpower' ||
		$argv[4] == 'impenergy' || $argv[4] == 'expenergy' || $argv[4] == 'selfcenergy')
	&& ($argv[5] == 'F1' || $argv[5] == 'F2' || $argv[5] == 'F3' || 
		$argv[5] == 'F23' || $argv[5]=='0')
	) {
	// Init variables
	$metnumtoadd  = array();
	$metnumtosub  = array();
	$val = 0.0;
	$toadd = 0.0;
	$tosub = 0.0;
	$prod = 0.0;
	$cons = 0.0;
	$addnumlist = array();
	$subnumlist = array();
	$prodlist = array();
	$conslist = array();

	// Virtual meter
    $metnum = $argv[1];
	// Get Meter Numbers to Add into an Array of int
	$metnumtoadd = json_decode('[' . $argv[2] . ']', true);
	// Get Meter Numbers to Sub into an Array of int
	$metnumtosub = json_decode('[' . $argv[3] . ']', true);
	// Fascia
    $fascia = $argv[5];
	
	// Set call time
	$calltime = time();

	define('checkaccess', true);
	include("$pathtomn/config/config_main.php");
	include("$pathtomn/config/memory.php");
	date_default_timezone_set($DTZ);
	
	// Read MeterN meters types and config
	for ($i = 1; $i <= $NUMMETER; $i++) {
		include("$pathtomn/config/config_met$i.php");
		if (in_array($i, $metnumtoadd, true) && !${"SKIPMONITORING$i"}) 
			$addnumlist[] = $i;
		if (in_array ($i, $metnumtosub, true) && !${"SKIPMONITORING$i"})
			$subnumlist[] = $i;
		if (${'PROD' . $i} == 1) {
			$prodlist[] = $i;
		}
		if (${'PROD' . $i} == 2) {
			$conslist[] = $i;
		}
	}

	// open mN shm memory
	$data = file_get_contents($MEMORY);
	$memarray = json_decode($data, true);

	// open mN shm live memory
	$data = file_get_contents($LIVEMEMORY);
	$livemem = json_decode($data, true);

	$nowUTC  = strtotime(date("Ymd H:i:s"));
	if ($nowUTC - $livemem['UTC'] > 40) {
		die("Abording: Too late mN live values\n");
	}

	// Retrive previus value
	$ok = true;
	$prevvalue = array();
	for ($i = 0; $i < count($addnumlist); $i++) {
		if (isset($memarray["Totalcounter$addnumlist[$i]"])) {
			$prevvalue["Totalcounter$addnumlist[$i]"] = $memarray["Totalcounter$addnumlist[$i]"];
		} else {
			$ok = false;
		}
	}
	for ($i = 0; $i < count($subnumlist); $i++) {
		if (isset($memarray["Totalcounter$subnumlist[$i]"])) {
			$prevvalue["Totalcounter$subnumlist[$i]"] = $memarray["Totalcounter$subnumlist[$i]"];
		} else {
			$ok = false;
		}
	}
	for ($i = 0; $i < count($prodlist); $i++) {
		if (isset($memarray["Totalcounter$prodlist[$i]"])) {
			$prevvalue["Totalcounter$prodlist[$i]"] = $memarray["Totalcounter$prodlist[$i]"];
		} else {
			$ok = false;
		}
	}
	for ($i = 0; $i < count($conslist); $i++) {
		if (isset($memarray["Totalcounter$conslist[$i]"])) {
			$prevvalue["Totalcounter$conslist[$i]"] = $memarray["Totalcounter$conslist[$i]"];
		} else {
			$ok = false;
		}
	}
	if (isset($memarray["Totalcounter$metnum"])) {
		$prevvalue["Totalcounter$metnum"] = $memarray["Totalcounter$metnum"];
	} else {
		$ok = false;
	}
	if ($ok == false) {
		$output = array();
		$output = glob($pathtomn . '/data/csv/*.csv');
		sort($output);
		$cnt = count($output);
	
		if ($cnt > 0) {
			$lines = file($output[$cnt - 1]);
			$contalines = count($lines);
			if ($contalines > 1) {
				$lastarray = preg_split("/,/", $lines[$contalines - 1]);
			} elseif ($contalines == 1 && file_exists($output[$cnt - 2])) {
				// yesterday, if current only header
				$lines = file($output[$cnt - 2]);
				$contalines = count($lines);
				$prevarray = preg_split("/,/", $lines[$contalines - 2]);
			}

			$prevvalue = array();
			for ($i = 0; $i < count($addnumlist); $i++) {
				$datareturn = null;
				$prevvalue["Totalcounter$addnumlist[$i]"] = retrievecsv($addnumlist[$i], $lines, ${'PASSO' . $addnumlist[$i]}, $datareturn);
			}
			for ($i = 0; $i < count($subnumlist); $i++) {
				$datareturn = null;
				$prevvalue["Totalcounter$subnumlist[$i]"] = retrievecsv($subnumlist[$i], $lines, ${'PASSO' . $subnumlist[$i]}, $datareturn);
			}
			for ($i = 0; $i < count($prodlist); $i++) {
				$datareturn = null;
				$prevvalue["Totalcounter$prodlist[$i]"] = retrievecsv($prodlist[$i], $lines, ${'PASSO' . $prodlist[$i]}, $datareturn);
			}
			for ($i = 0; $i < count($conslist); $i++) {
				$datareturn = null;
				$prevvalue["Totalcounter$conslist[$i]"] = retrievecsv($conslist[$i], $lines, ${'PASSO' . $conslist[$i]}, $datareturn);
			}
			$datareturn = null;
			$prevvalue["Totalcounter$metnum"] = retrievecsv($metnum, $lines, ${'PASSO' . $metnum}, $datareturn);
		} else {
			// no csv, starting from scratch !
			$prevvalue = array();
			for ($i = 0; $i < count($addnumlist); $i++) {
				$prevvalue["Totalcounter$addnumlist[$i]"] = 0.0;
			}
			for ($i = 0; $i < count($subnumlist); $i++) {
				$prevvalue["Totalcounter$subnumlist[$i]"] = 0.0;
			}
			for ($i = 0; $i < count($prodlist); $i++) {
				$prevvalue["Totalcounter$prodlist[$i]"] = 0.0;
			}
			for ($i = 0; $i < count($conslist); $i++) {
				$prevvalue["Totalcounter$conslist[$i]"] = 0.0;
			}
			$prevvalue["Totalcounter$metnum"] = 0.0;
		}
	}
	
	if (($argv[4] == 'power') && isFascia($calltime, $fascia)) {
		$cnt = count($addnumlist);
        for ($i = 0; $i < $cnt; $i++) {
			if (isset(${'LIVECOMMAND' . $addnumlist[$i]}) == 1 && isset($livemem["${'METNAME'.$addnumlist[$i]}$addnumlist[$i]"])) {
				$toadd += $livemem["${'METNAME'.$addnumlist[$i]}$addnumlist[$i]"];
			}
		}
        $cnt = count($subnumlist);
        for ($i = 0; $i < $cnt; $i++) {
			if (isset(${'LIVECOMMAND' . $subnumlist[$i]}) == 1 && isset($livemem["${'METNAME'.$subnumlist[$i]}$subnumlist[$i]"])) {
				$tosub += $livemem["${'METNAME'.$subnumlist[$i]}$subnumlist[$i]"];
			}
		}
		
		$val = $toadd - $tosub;
	} elseif (($argv[4] == 'imppower') && (isFascia($calltime, $fascia))) {
        for ($i = 0; $i < count($prodlist); $i++) {
			if (isset(${'LIVECOMMAND' . $prodlist[$i]}) == 1 && isset($livemem["${'METNAME'.$prodlist[$i]}$prodlist[$i]"])) {
				$prod += $livemem["${'METNAME'.$prodlist[$i]}$prodlist[$i]"];
			}
		}
        for ($i = 0; $i < count($conslist); $i++) {
			if (isset(${'LIVECOMMAND' . $conslist[$i]}) == 1 && isset($livemem["${'METNAME'.$conslist[$i]}$conslist[$i]"])) {
				$cons += $livemem["${'METNAME'.$conslist[$i]}$conslist[$i]"];
			}
		}
		
		$val = $cons - $prod;
		if ($val < 0) {
			$val = 0.0;
		}
	} elseif (($argv[4] == 'exppower') && (isFascia($calltime, $fascia))) {
        for ($i = 0; $i < count($prodlist); $i++) {
			if (isset(${'LIVECOMMAND' . $prodlist[$i]}) == 1 && isset($livemem["${'METNAME'.$prodlist[$i]}$prodlist[$i]"])) {
				$prod += $livemem["${'METNAME'.$prodlist[$i]}$prodlist[$i]"];
			}
		}
        for ($i = 0; $i < count($conslist); $i++) {
			if (isset(${'LIVECOMMAND' . $conslist[$i]}) == 1 && isset($livemem["${'METNAME'.$conslist[$i]}$conslist[$i]"])) {
				$cons += $livemem["${'METNAME'.$conslist[$i]}$conslist[$i]"];
			}
		}
		
		$val = $prod - $cons;
		if ($val < 0) {
			$val = 0.0;
		}
	} elseif (($argv[4] == 'selfcpower') && (isFascia($calltime, $fascia))) {
        for ($i = 0; $i < count($prodlist); $i++) {
			if (isset(${'LIVECOMMAND' . $prodlist[$i]}) == 1 && isset($livemem["${'METNAME'.$prodlist[$i]}$prodlist[$i]"])) {
				$prod += $livemem["${'METNAME'.$prodlist[$i]}$prodlist[$i]"];
			}
		}
        for ($i = 0; $i < count($conslist); $i++) {
			if (isset(${'LIVECOMMAND' . $conslist[$i]}) == 1 && isset($livemem["${'METNAME'.$conslist[$i]}$conslist[$i]"])) {
				$cons += $livemem["${'METNAME'.$conslist[$i]}$conslist[$i]"];
			}
		}
		
		if ($prod > $cons) {
			$val = $cons;
		} else {
			$val = $prod;
		}
	} elseif (($argv[4] == 'housecpower') && (isFascia($calltime, $fascia))) {
		// HouseConsumation = Prod + Tot
		// Production
        for ($i = 0; $i < count($prodlist); $i++) {
			if (isset(${'LIVECOMMAND' . $prodlist[$i]}) == 1 && isset($livemem["${'METNAME'.$prodlist[$i]}$prodlist[$i]"])) {
				$prod += $livemem["${'METNAME'.$prodlist[$i]}$prodlist[$i]"];
			}
		}

		$toadd = $livemem["${'METNAME'.$addnumlist[0]}$addnumlist[0]"];
		$tosub = $livemem["${'METNAME'.$subnumlist[0]}$subnumlist[0]"];
		$val = $prod + $toadd - $tosub;
	} elseif (($argv[4] == 'energy') && (isFascia($calltime, $fascia))) {
		$cnt = count($addnumlist);
		for ($i = 0; $i < $cnt; $i++) {
			$value = getvalue(${'ID' . $addnumlist[$i]}, ${'COMMAND' . $addnumlist[$i]});
			$toadd += ($value - $prevvalue["Totalcounter$addnumlist[$i]"]);
		}
		$cnt = count($subnumlist);
		for ($i = 0; $i < $cnt; $i++) {
			$value = getvalue(${'ID' . $subnumlist[$i]}, ${'COMMAND' . $subnumlist[$i]});
			$tosub += ($value - $prevvalue["Totalcounter$subnumlist[$i]"]);
		}
		
		if (isset($prevvalue["Totalcounter$metnum"])) {
			$val = $prevvalue["Totalcounter$metnum"] + $toadd - $tosub;
		} else {
			$val = $toadd - $tosub;
		}
		if ($val >= ${'PASSO' . $metnum}) {
			$val -= ${'PASSO' . $metnum};
		}
	} elseif (($argv[4] == 'energy') && (!isFascia($calltime, $fascia))) {
		if (isset($prevvalue["Totalcounter$metnum"])) {
			$val = $prevvalue["Totalcounter$metnum"];
		} else {
			$val = 0.0;
		}
	} elseif (($argv[4] == 'impenergy') && (isFascia($calltime, $fascia))) {
		for ($i = 0; $i < count($prodlist); $i++) {
			$value = getvalue(${'ID' . $prodlist[$i]}, ${'COMMAND' . $prodlist[$i]});
			if ($value != null) {
				$prod += ($value - $prevvalue["Totalcounter$prodlist[$i]"]);
			}
		}
		if ($prod < 0) {
			$prod = 0;
		}
		for ($i = 0; $i < count($conslist); $i++) {
			$value = getvalue(${'ID' . $conslist[$i]}, ${'COMMAND' . $conslist[$i]});
			$cons += ($value - $prevvalue["Totalcounter$conslist[$i]"]);
		}
		
		$val = $cons - $prod;
		if ($val < 0) {
			$val = 0.0;
		}
		if (isset($prevvalue["Totalcounter$metnum"])) {
			$val += $prevvalue["Totalcounter$metnum"];
		}
		if ($val >= ${'PASSO' . $metnum}) {
			$val -= ${'PASSO' . $metnum};
		}
	} elseif (($argv[4] == 'impenergy') && (!isFascia($calltime, $fascia))) {
		if (isset($prevvalue["Totalcounter$metnum"])) {
			$val = $prevvalue["Totalcounter$metnum"];
		} else {
			$val = 0.0;
		}
	} elseif (($argv[4] == 'expenergy') && (isFascia($calltime, $fascia))) {
		for ($i = 0; $i < count($prodlist); $i++) {
			$value = getvalue(${'ID' . $prodlist[$i]}, ${'COMMAND' . $prodlist[$i]});
			if ($value != null) {
				$prod += ($value - $prevvalue["Totalcounter$prodlist[$i]"]);
			}
		}
		if ($prod < 0) {
			$prod = 0;
		}
		for ($i = 0; $i < count($conslist); $i++) {
			$value = getvalue(${'ID' . $conslist[$i]}, ${'COMMAND' . $conslist[$i]});
			$cons += ($value - $prevvalue["Totalcounter$conslist[$i]"]);
		}
		
		$val = $prod - $cons;
		if ($val < 0) {
			$val = 0.0;
		}
		if (isset($prevvalue["Totalcounter$metnum"])) {
			$val += $prevvalue["Totalcounter$metnum"];
		}
		if ($val >= ${'PASSO' . $metnum}) {
			$val -= ${'PASSO' . $metnum};
		}
	} elseif (($argv[4] == 'expenergy') && (!isFascia($calltime, $fascia))) {
		if (isset($prevvalue["Totalcounter$metnum"])) {
			$val = $prevvalue["Totalcounter$metnum"];
		} else {
			$val = 0.0;
		}
	} elseif (($argv[4] == 'selfcenergy') && (isFascia($calltime, $fascia))) {
		for ($i = 0; $i < count($prodlist); $i++) {
			$value = getvalue(${'ID' . $prodlist[$i]}, ${'COMMAND' . $prodlist[$i]});
			if ($value != null) {
				$prod += ($value - $prevvalue["Totalcounter$prodlist[$i]"]);
			}
		}
		if ($prod < 0) {
			$prod = 0;
		}
		for ($i = 0; $i < count($conslist); $i++) {
			$value = getvalue(${'ID' . $conslist[$i]}, ${'COMMAND' . $conslist[$i]});
			$cons += ($value - $prevvalue["Totalcounter$conslist[$i]"]);
		}
		
		if ($prod > $cons) {
			$val = $cons;
		} else {
			$val = $prod;
		}
		if (isset($prevvalue["Totalcounter$metnum"])) {
			$val += $prevvalue["Totalcounter$metnum"];
		}
		if ($val >= ${'PASSO' . $metnum}) {
			$val -= ${'PASSO' . $metnum};
		}
	} elseif (($argv[4] == 'selfcenergy') && (!isFascia($calltime, $fascia))) {
		if (isset($prevvalue["Totalcounter$metnum"])) {
			$val = $prevvalue["Totalcounter$metnum"];
		} else {
			$val = 0.0;
		}
	} elseif (($argv[4] == 'housecenergy') && (isFascia($calltime, $fascia))) {
		for ($i = 0; $i < count($prodlist); $i++) {
			$value = getvalue(${'ID' . $prodlist[$i]}, ${'COMMAND' . $prodlist[$i]});
			if ($value != null) {
				if ($value >= $prevvalue["Totalcounter$prodlist[$i]"]) {
					$prod += ($value - $prevvalue["Totalcounter$prodlist[$i]"]);
				} else {
					$prod += ($value + ${'PASSO' . $prodlist[0]} - $prevvalue["Totalcounter$prodlist[$i]"]);
				}
			}
		}
		if ($prod < 0) {
			$prod = 0;
		}
		
		$value = getvalue(${'ID' . $addnumlist[0]}, ${'COMMAND' . $addnumlist[0]});
		if ($value >= $prevvalue["Totalcounter$subnumlist[0]"]) {
			$imp = ($value - $prevvalue["Totalcounter$addnumlist[0]"]);
		} else {
			$imp = ($value + ${'PASSO' . $addnumlist[0]} - $prevvalue["Totalcounter$addnumlist[0]"]);
		}
		
		$value = getvalue(${'ID' . $subnumlist[0]}, ${'COMMAND' . $subnumlist[0]});
		if ($value >= $prevvalue["Totalcounter$subnumlist[0]"]) {
			$exp = ($value - $prevvalue["Totalcounter$subnumlist[0]"]);
		} else {
			$exp = ($value + ${'PASSO' . $subnumlist[0]} - $prevvalue["Totalcounter$subnumlist[0]"]);
		}
		
		$val = $prod + $imp - $exp;
		if ($val < 0) {
			$val = 0.0;
		}
		if (isset($prevvalue["Totalcounter$metnum"])) {
			$val += $prevvalue["Totalcounter$metnum"];
		}
		if ($val >= ${'PASSO' . $metnum}) {
			$val -= ${'PASSO' . $metnum};
		}
	} elseif (($argv[4] == 'housecenergy') && (!isFascia($calltime, $fascia))) {
		if (isset($prevvalue["Totalcounter$metnum"])) {
			$val = $prevvalue["Totalcounter$metnum"];
		} else {
			$val = 0.0;
		}
	}
	
	// Set precision
	settype($val, 'float');
	$val = round($val, ${'PRECI' . $metnum});

	// Output
	switch ($argv[4]) {
		case 'power' :
			$str = utf8_decode("${'LID'.$metnum}($val*${'LIVEUNIT'.$metnum})");
			break;
		case 'imppower' :
			$str = utf8_decode("${'LID'.$metnum}($val*${'LIVEUNIT'.$metnum})");
			break;
		case 'exppower' :
			$str = utf8_decode("${'LID'.$metnum}($val*${'LIVEUNIT'.$metnum})");
			break;
		case 'selfcpower' :
			$str = utf8_decode("${'LID'.$metnum}($val*${'LIVEUNIT'.$metnum})");
			break;
		case 'energy' :
			$str = utf8_decode("${"ID$metnum"}($val*${'UNIT'.$metnum})");
			break;
		case 'impenergy' :
			$str = utf8_decode("${"ID$metnum"}($val*${'UNIT'.$metnum})");
			break;
		case 'expenergy' :
			$str = utf8_decode("${"ID$metnum"}($val*${'UNIT'.$metnum})");
			break;
		case 'selfcenergy' :
			$str = utf8_decode("${"ID$metnum"}($val*${'UNIT'.$metnum})");
			break;
		default:
			$str = '';
	}
	echo "$str\n";
} else {
	echo(usage($version));
	die("\nAbording: no valid argument given.\n");
}
?>

jeanmarc
Posts: 2057
Joined: Thu Aug 29, 2013 7:16 am

Re: meterN 1.0

Post by jeanmarc » Mon Jan 20, 2020 10:51 am

Hi Marco,
I guess it's old errors in debug as i don't see LIVEPOOL in your virtmet.php app. Is there a problem ?

megamarco83
Posts: 108
Joined: Tue Apr 14, 2015 9:25 am

Re: meterN 1.0

Post by megamarco83 » Mon Jan 20, 2020 11:12 am

Hi JM, sorry, you are right, i forgot to turn on the debug.
i write because i find some issue with virtmet on "detail" page, about graphics.
https://ibb.co/hd8WwsZ
https://ibb.co/qRf1YZ2
with all meters as you can see the graphics are correct

with virtmet i see some blanks
https://ibb.co/qRf1YZ2

inside log debug now i see:
20/01/2020 11:06:22 Starting meterN debug (19379)

PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
PHP Warning: exec(): Cannot execute a blank command in /var/www/metern/scripts/metern.php on line 23
PHP Warning: implode(): Argument must be an array in /var/www/metern/scripts/metern.php on line 24
not sure if the issue are connected.

i see also that in main page some negative value:
https://ibb.co/qBMWxL4

but if i look at total value splitted every day, i do not see any problem:
https://ibb.co/NCwn9Q6

thanks

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests