Page 9 of 21

Re: meterN 0.8

Posted: Fri Jul 01, 2016 4:57 pm
by a_p_o
ups_bat = Sensor
ups_tl = Sensor
ups_lo = Sensor
ups_v = Sensor
ups_s = Other

Re: meterN 0.8

Posted: Wed Jul 13, 2016 2:58 pm
by robinc
Hi Jeanmarc,

I have been running meterN successfully for several months - thanks for a great project .....

Yesterday I upgraded from release 0.8.2.1 to 0.8.2.7.1 and I am now seeing a problem whereby certain meters are no longer graphed on the 'Details' page.
All meters graph correctly on the 'Index' page and all readings are recorded in the CSV files.

I have four meters configured :
1 - 'Electricity Consumption' ( derived from a pulse meter )
2 - 'Solar Production' ( derived from 123Solar )
3 - 'Internal Temperature' ( type 'Sensor' )
4 - 'External Temperature' ( type 'Sensor' )

All four meters are graphed on the Index page, but only meters 1 & 2 are graphed on the 'Detail' page.
When meters 3 & 4 are selected on the Detail page no graph is displayed ( ie no axes ).

Raspberry Pi is running Arch distro.
PHP version is 7.0.2-1

Any ideas ??

Re: meterN 0.8

Posted: Wed Jul 13, 2016 8:04 pm
by jeanmarc
Hi,
I will look at that in few days. I am abroad in holiday.
Bye

Re: meterN 0.8

Posted: Thu Jul 14, 2016 9:46 am
by robinc
OK, thanks jeanmarc - enjoy your holiday .....

In the meantime I thought I would see what I could figure out ...

I have very little understanding of the code, but looking at the changes to programdetailed.php between the two versions, I removed the condition

Code: Select all

&& ${'TYPE' . $i} != 'Sensor'
from line 126 of programdetailed.php

This has resolved my problem.

line 126 Before :

Code: Select all

if (!empty($val_first) && !empty($val_last) && ${'TYPE' . $i} != 'Sensor' && $line_num > 1 && $epochdate - $prevUTCdate == 300000) {
line 126 After:

Code: Select all

if (!empty($val_first) && !empty($val_last) && $line_num > 1 && $epochdate - $prevUTCdate == 300000) {

Re: meterN 0.8

Posted: Sun Jul 17, 2016 7:53 am
by jeanmarc
Hi,
Sorry for the delay. Could you try this as programdetailed ? I changed it a while ago, it think it is ok.

Code: Select all

<?php
define('checkaccess', TRUE);
include('../config/config_main.php');
date_default_timezone_set($DTZ);

if (isset($_COOKIE['user_lang'])) {
    $user_lang = $_COOKIE['user_lang'];
} else {
    $user_lang = 'English';
}
include('../languages/' . $user_lang . '.php');

if (!empty($_GET['date1'])) {
    $date1 = $_GET['date1'];
} else {
    $date1 = FALSE;
}
$grid = array();

for ($i = 1; $i <= $NUMMETER; $i++) {
    include("../config/config_met$i.php");
    $check[$i] = $_GET["check$i"];
    if (${'TYPE' . $i} == 'Elect' && ${'PROD' . $i} != 0 && !isset($grid[${'PHASE' . $i}])) {
        $grid[${'PHASE' . $i}] = ${'PHASE' . $i};
    }
}

sort($grid);
$cnt   = count($grid);
$sscnt = 0;
$efcnt = 0;

for ($i = 0; $i < $cnt; $i++) {
    if (!empty($_GET["ss$i"])) { // Self-sufficiency
        $ss[$i] = $_GET["ss$i"];
        if ($ss[$i] != 0) {
            $selfsuff[$sscnt] = $ss[$i];
            $sscnt++;
        }
    }
    if (!empty($_GET["ef$i"])) { // Energy-flow
        $ef[$i] = $_GET["ef$i"];
        if ($ef[$i] != 0) {
            $energf[$efcnt] = $ef[$i];
            $efcnt++;
        }
    }
}

$log = "../data/csv/$date1";
if (file_exists($log)) {
    $file       = file($log);
    $contalines = count($file);
    
    $year  = substr($date1, 0, 4);
    $month = substr($date1, 4, 2);
    $day   = substr($date1, 6, 2);
    
    $unitlist = array();
    $metlist  = array();
    $nbrstack = 0;
    
    for ($i = 1; $i <= $NUMMETER; $i++) {
        if ($check[$i] == 'on') {
            array_push($metlist, $i);
            $stackname[$nbrstack] = "${'METNAME'.$i}";
            $color[$nbrstack]     = "#${'COLOR'.$i}";
            if (!in_array(${'UNIT' . $i}, $unitlist)) {
                array_push($unitlist, ${'UNIT' . $i});
            }
            $nbrstack++;
        }
    }
    
    if ($sscnt > 0 && !in_array('%', $unitlist)) {
        array_push($unitlist, '%');
    }
    if ($efcnt > 0 && !in_array('Wh', $unitlist)) {
        array_push($unitlist, 'Wh');
    }
    
    $stack  = array(
        array()
    );
    $EPtot  = array(
        array()
    );
    $ECtot  = array(
        array()
    );
    $ESStot = 0;
    
    for ($line_num = 2; $line_num < $contalines; $line_num++) {
        $pastline_num = $line_num - 1;
        $prevarray    = preg_split("/,/", $file[$pastline_num]);
        $array        = preg_split("/,/", $file[$line_num]);
        
        $prevhour    = substr($prevarray[0], 0, 2);
        $prevmin     = substr($prevarray[0], 3, 2);
        $prevUTCdate = strtotime($year . '-' . $month . '-' . $day . ' ' . $prevhour . ':' . $prevmin);
        $prevUTCdate *= 1000;
        
        $SDTE   = $array[0];
        $hour   = substr($SDTE, 0, 2);
        $minute = substr($SDTE, 3, 2);
        
        if ($line_num == ($contalines - 1) && $minute == '00' && $hour == '00') {
            $epochdate = strtotime(date("$year$month$day")) + 86400;
        } else {
            $epochdate = strtotime($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute);
        }
        $epochdate *= 1000;
        
        $nbrstack = 0;
        for ($i = 1; $i <= $NUMMETER; $i++) {
            if ($check[$i] == 'on') {
                $val_first = null;
                $val_last  = null;
                
                if (isset($array[$i])) {
                    $val_first = trim($prevarray[$i]);
                }
                if (isset($prevarray[$i])) {
                    $val_last = trim($array[$i]);
                }
                if (${'TYPE' . $i} != 'Sensor' && !empty($val_first) && !empty($val_last) && $line_num > 1 && $epochdate - $prevUTCdate == 300000) { // meter
                    settype($val_first, 'float');
                    settype($val_last, 'float');
                    if ($val_first <= $val_last) {
                        $val_last -= $val_first;
                    } else { // counter pass over
                        $val_last += ${'PASSO' . $i} - $val_first;
                    }
                    
                    $val_last                    = round($val_last, ${'PRECI' . $i});
                    $stack[$nbrstack][$line_num] = array(
                        $epochdate,
                        $val_last
                    );
                    $nbrstack++;
                } elseif (${'TYPE' . $i} == 'Sensor' && $line_num > 1 && !empty($val_last)) { // sensor
                    settype($val_last, 'float');
                    $val_last                    = round($val_last, ${'PRECI' . $i});
                    $stack[$nbrstack][$line_num] = array(
                        $epochdate,
                        $val_last
                    );
                    $nbrstack++;
                }
                
            }
            if ($sscnt > 0 || $efcnt > 0 && ${'TYPE' . $i} == 'Elect' && ${'PROD' . $i} != 0 && $epochdate - $prevUTCdate == 300000) {
                if (!empty($array[$i]) && !empty($prevarray[$i])) {
                    if ($prevarray[$i] > $array[$i]) {
                        $value = $array[$i] + ${'PASSO' . $i} - $prevarray[$i];
                    } else {
                        $value = $array[$i] - $prevarray[$i];
                    }
                } else {
                    $value = 0;
                }
                $ph = ${'PHASE' . $i}; // ?
                if (${'PROD' . $i} == 1) {
                    if (!isset($EPtot[$ph][$line_num])) {
                        $EPtot[$ph][$line_num] = 0;
                    }
                    $EPtot[$ph][$line_num] += $value;
                } else {
                    if (!isset($ECtot[$ph][$line_num])) {
                        $ECtot[$ph][$line_num] = 0;
                    }
                    $ECtot[$ph][$line_num] += $value;
                }
            }
        } // each meters
        
        $ssstack = 0;
        $efstack = 0;
        if ($sscnt > 0 || $efcnt > 0 && $line_num > 1) {
            for ($i = 0; $i < $sscnt; $i++) { // Self-sufficiency
                $ph   = (int) $selfsuff[$i];
                $EP5m = $EPtot[$ph][$line_num];
                $EC5m = $ECtot[$ph][$line_num];
                if (!isset($CONSOtot)) {
                    $CONSOtot = 0;
                }
                $CONSOtot += $EC5m;
                if ($EP5m > 0 && $EC5m > 0) {
                    $EGR5tot = round((($EP5m / $EC5m) * 100), 1);
                } else {
                    $EGR5tot = 0;
                }
                if ($EGR5tot > 100) {
                    $EGR5tot = 100;
                }
                
                if ($EP5m > 0) {
                    if ($EP5m > $EC5m) {
                        $ESStot += $EC5m;
                    } else {
                        $ESStot += $EP5m;
                    }
                }
                
                $stack[$ssstack + $nbrstack][$line_num] = array(
                    $epochdate,
                    $EGR5tot
                );
                
                $stackname[$ssstack + $nbrstack] = "$lgSELFS$selfsuff[$i]";
                $color[$ssstack + $nbrstack]     = "#AA4643";
                $ssstack++;
                
            } // each phase
            
            for ($i = 0; $i < $efcnt; $i++) { // Energy-flow
                $ph                                                = (int) $energf[$i];
                $flow                                              = $EPtot[$ph][$line_num] - $ECtot[$ph][$line_num];
                $stack[$efstack + $ssstack + $nbrstack][$line_num] = array(
                    $epochdate,
                    $flow
                );
                
                $stackname[$efstack + $ssstack + $nbrstack] = "$lgENERGYF$energf[$i]";
                $color[$efstack + $ssstack + $nbrstack]     = "#AA4643";
                $efstack++;
            }
        }
    } // End of foreach
    
    $dday = date($DATEFORMAT, mktime(0, 0, 0, $month, $day, $year));
    
    settype($titledate, "string");
    $title = "$lgDETAILEDOFTITLE $dday $titledate";
    
    if ($sscnt > 0) {
        $CONSOtot = round($CONSOtot / 1000, 3);
        $ESStot   = round($ESStot / 1000, 3);
        $ESSratio = round((($ESStot / $CONSOtot) * 100), 1);
        
        $title .= "($ESSratio% $lgAUTONOM $ESStot/$CONSOtot kWh)";
    }
    
    $data    = array();
    $cntunit = count($unitlist);
    
    # // Return datas via json
    $j = 0;
    for ($i = 1; $i <= $NUMMETER; $i++) {
        if ($check[$i] == 'on') {
            sort($stack[$j]);
            for ($h = 0; $h < $cntunit; $h++) {
                if ($unitlist[$h] == ${'UNIT' . $i}) {
                    $thisyaxis = $h;
                }
            }
            $data[$j] = array(
                'name' => $stackname[$j],
                'data' => $stack[$j],
                'yAxis' => $thisyaxis,
                'type' => 'areaspline',
                'color' => $color[$j],
                'dashStyle' => 'Solid'
            );
            $j++;
        }
    }
    
    $cnttotstck = $nbrstack + $ssstack;
    if ($sscnt > 0) {
        for ($h = 0; $h < $cntunit; $h++) {
            if ($unitlist[$h] == '%') {
                $thisyaxis = $h;
            }
        }
        
        for ($i = $nbrstack; $i < $cnttotstck; $i++) {
            sort($stack[$i]);
            $data[$i] = array(
                'name' => $stackname[$i],
                'data' => $stack[$i],
                'yAxis' => $thisyaxis,
                'type' => 'spline',
                'color' => '#0B610B',
                'dashStyle' => 'Dash'
            );
        }
    }
    
    $cnttotstck2 = $cnttotstck + $efstack;
    
    if ($efcnt > 0) {
        for ($h = 0; $h < $cntunit; $h++) {
            if ($unitlist[$h] == 'Wh') {
                $thisyaxis = $h;
            }
        }
        
        for ($i = $cnttotstck; $i < $cnttotstck2; $i++) {
            sort($stack[$i]);
            $data[$i] = array(
                'name' => $stackname[$i],
                'data' => $stack[$i],
                'yAxis' => $thisyaxis,
                'type' => 'spline',
                'color' => '#BBAA00',
                'dashStyle' => 'Dash'
            );
        }
    }
    
    $jsonreturn = array(
        'data' => $data,
        'title' => $title
    );
} else {
    $jsonreturn = array(
        'data' => null,
        'title' => 'No Data'
    );
    
}
header("Content-type: text/json");
echo json_encode($jsonreturn);
?>

Re: meterN 0.8

Posted: Sun Jul 17, 2016 9:00 am
by robinc
jeanmarc wrote:Hi,
Sorry for the delay. Could you try this as programdetailed ? I changed it a while ago, it think it is ok.
Yes, the posted code works for me also.

Thanks a lot.

Re: meterN 0.8

Posted: Tue Jul 19, 2016 8:52 pm
by a_p_o
jeanmarc wrote:Hi,
Sorry for the delay. Could you try this as programdetailed ? I changed it a while ago, it think it is ok.
Yes, the posted code is ok.
Many thanks!

Re: meterN 0.8

Posted: Wed Jul 20, 2016 4:35 pm
by jeanmarc
Hi,

mN 0.8.2.7.2 is out to correct some bugs :

- Bug with Push Over test
- Bug with deailled bug sensors
- Bug indicators command may return null value

Happy summer

Re: meterN 0.8

Posted: Sun Jul 31, 2016 8:45 pm
by megamarco83
hi, i'm coming from metern 0.8.1 and i update automatically to 0.8.2.7.2, but i found some problems.
if i go in my metern webpage with firefox, mobile phone, tablet i'm not able to see the graph, i see all gray without nothing, but i'm able to see the right meters
if i use internet explorer i'm able to see the graph...
i attach two pictures to show differences
why it's happen?
with metern 0.8.1 i could use whatever brower / smartphone....
last question...in metern 0.8.1 in left bottom i could select "123solar" to have on top the link to 123solar, but this option is not present in metern 0.8.2.7.2
thanks!!!!

http://it.tinypic.com/r/316vigp/9
http://it.tinypic.com/r/1hw5g8/9

p.s. i'm using raspberr pi 2 with raspberry wheezy OS

Re: meterN 0.8

Posted: Mon Aug 01, 2016 6:32 am
by jeanmarc
Hi,
make sure you make a clear refresh : CTRL + F5.
I remove the '123solar' theme a while ago, you can still import it.