meterN 0.8

Talks about metering
flane
Posts: 69
Joined: Mon Aug 11, 2014 7:22 am

Re: meterN 0.8

Post by flane » Sun Jul 30, 2017 10:15 pm

Great work Jeanmarc :D

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

Re: meterN 0.8

Post by jeanmarc » Mon Jul 31, 2017 6:58 am

thanks for the encouragement :)

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

Re: meterN 0.8

Post by jeanmarc » Thu Aug 17, 2017 5:42 pm

Hello,

meterN0.8.4 is released :

- Remove daily report
- Config version with check, you'll need to save the configuration for each of your meters
- Complete rewrite of notification
- Added rpinotify notification
- Update is now fully automatic with backup and in one click !
- Bug start/stop daemon (beware to update com_daemon if you use it from comapps_examples)
- Bug bootmn
- Others clean up and bug fixes

Have fun

flane
Posts: 69
Joined: Mon Aug 11, 2014 7:22 am

Re: meterN 0.8

Post by flane » Wed Aug 30, 2017 12:13 pm

Hi jeanmarc,
I've updated to MeterN 0.8.4 and 123Solar 1.7.0.

I have two issues with MeterN.

1) pool123s.php

I used the new pool123s.php of comapps_examples20170817
At night, when the inverter is off, the 123s_LIVEMEMORY file does not contain "KWHT1" and I have in debug, the following error:

Code: Select all

PHP Notice: Undefined index: KWHT1 in /var/www/comapps/pool123s.php on line 43
To this line:

Code: Select all

 $ KWHT = round ($ memarray ["KWHT $ invtnum"] * 1000); // Wh
With the inverter switched on, all OK.
In fact, during the day, the 123s_LIVEMEMORY file contains KWHT1


2) config_daemon.php

I used the new config_daemon of comapps_examples20170817.
This is my config_daemon:

Code: Select all

<?php
if(!defined('checkaccess')){die('Direct access not permitted');}
// Manage com. apps daemon as 'http' user if needed

if (is_null($PID)) { // Stop Daemon
	exec("pkill -f pooler485 > /dev/null 2>&1 &");
        exec("pkill -f boiler > /dev/null 2>&1 &"); 
} else { //Start
	exec("pooler485 2,7 9600 /dev/ttyUSB0 > /dev/null 2>/dev/null &");
        exec("boiler > /dev/null 2>/dev/null &");
}
?>
When manually switches MeterN on and off, it's all OK.
pooler485 and boiler, start up and shut off regularly.

If I reboot the Raspberry, pooler485 and boiler do not start at MeterN startup. :?

I hope you can help me.
Thanks :)

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

Re: meterN 0.8

Post by jeanmarc » Wed Aug 30, 2017 1:44 pm

Hi,
1) I'll look later on when it's night.. What is your protocol ?
2) Yup, that a bug, $pid is now $PID (caps), you can use this as bootmn.php

Code: Select all

<?php
if ($_SERVER['SERVER_ADDR'] != '127.0.0.1' && $_SERVER['SERVER_ADDR'] != '::1') {
    die('Direct access not permitted');
}

define('checkaccess', TRUE);
include('../config/config_main.php');
date_default_timezone_set($DTZ);
$SCRDIR = dirname(__FILE__);
$PID    = null;
$now    = date($DATEFORMAT . ' H:i:s');

if (file_exists('metern.pid')) {
    exec('pkill -f metern.php> /dev/null 2>&1 &'); //make sure there is only one instance
    usleep(500000);
    unlink('metern.pid');
}

if ($DEBUG) {
    $command = 'php metern.php' . ' >> ../data/metern.err 2>&1 & echo $!; ';
    $PID     = exec($command);
    file_put_contents('metern.pid', $PID);
    $stringData = "$now\tStarting meterN on boot debug ($PID)\n\n";
    $myFile     = dirname($SCRDIR) . '/data/metern.err';
    file_put_contents($myFile, $stringData, FILE_APPEND);
} else {
    $command    = 'php metern.php' . ' > /dev/null 2>&1 & echo $!;';
    $PID        = exec($command);
    file_put_contents('metern.pid', $PID);
    $stringData = "$now\tStarting meterN on boot ($PID)\n\n";
}
include('../config/config_daemon.php');

$DATADIR = dirname($SCRDIR) . '/data';
$stringData .= file_get_contents($DATADIR . '/events.txt');
file_put_contents($DATADIR . '/events.txt', $stringData);
?>

flane
Posts: 69
Joined: Mon Aug 11, 2014 7:22 am

Re: meterN 0.8

Post by flane » Wed Aug 30, 2017 3:10 pm

1) My protocol is Aurora
2) OK . I saw the new variable $PID, but I did not think about the bootmn file... ;)

Thanks

EDIT:
The problem with LIVEMEMORY is when stop and start 123solar or reboot Raspberry with inverter Power off.
In this case, KWHT1 is not present

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

Re: meterN 0.8

Post by jeanmarc » Thu Aug 31, 2017 4:51 am

For sure /dev/shm is RAM memory :lol:

flane
Posts: 69
Joined: Mon Aug 11, 2014 7:22 am

Re: meterN 0.8

Post by flane » Thu Aug 31, 2017 7:12 am

I have an automatic weekly reboot at 00:02 and this creates the problems described.
On reboot, with inverter switched off, 123solar (Aurora protocol) recreates the LIVEMEMORY file but without KWHT1.

For now, I solved with these changes at pool123s.php.
Changes recovered from the old pool123s file ;)

pool123s.php

Code: Select all

#!/usr/bin/php
<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}
// This script will output a 123solar counter into a meterN compatible format
// Configure, then ln -s /var/www/comapps/pool123s.php /usr/bin/pool123s
// Request Main command with 'pool123s energy' and live command 'pool123s power'

// 123solar config
$pathto123s = '/var/www/123solar';
$invtnum    = 1; //123solar inverter number

// meterN config
$pathtomn   = '/var/www/metern';
$METERID    = '1';
$KWHTC      = 0; // Initial counter in case of resetting or replacing inverter
$INVTmetnum = 1; // meter number

// No edit is needed below
if (isset($argv[1])) {
    define('checkaccess', TRUE);
    include("$pathto123s/config/config_main.php");
    include("$pathto123s/config/config_invt$invtnum.php");
    include("$pathto123s/config/memory.php");
    date_default_timezone_set($DTZ);
    
    $KWHT = null;
    if (file_exists($LIVEMEMORY)) {
        $data     = file_get_contents($LIVEMEMORY);
        $memarray = json_decode($data, true);
        $nowUTC   = strtotime(date("Ymd H:i:s"));
        if ($argv[1] == 'power') {
            if ($nowUTC - $memarray["SDTE$invtnum"] < 30) {
                $GP = $memarray["G1P$invtnum"] + $memarray["G2P$invtnum"] + $memarray["G3P$invtnum"];
                $GP = round($GP, 0);
            } else { // Too old
                $GP = 0;
            }
            echo "$METERID($GP*W)\n";
        } elseif ($argv[1] == 'energy') {
            if ($nowUTC - $memarray["SDTE$invtnum"] < 600) {
                $KWHT = round($memarray["KWHT$invtnum"] * 1000); // Wh
                if ($argv[1] == 'energy' && (empty($KWHT) || $KWHT == 0)) { // 123s ain't running at night retrieve the value in csv
					$dir    = $pathto123s . '/data/invt' . $invtnum . '/csv';
					$output = glob($dir . '/*.csv');
					sort($output);
					$xdays = count($output);
					if ($xdays > 0) {
						$lastlog    = $output[$xdays - 1];
						$lines      = file($lastlog);
						$contalines = count($lines);
						$array_last = preg_split('/,/', $lines[$contalines - 1]);
						$KWHT       = round(($array_last[27] * ${'CORRECTFACTOR' . $invtnum} * 1000), 0); //in Wh
					} else {
						$KWHT = null;
					}
				}
					
				$KWHT += $KWHTC;
				if (!empty($KWHT)) {
				file_put_contents("/dev/shm/produzione$METERID.txt", "$METERID($KWHT*Wh)\n");
				echo "$METERID($KWHT*Wh)\n";
                }
            } else {
                die("Abording: Too late value\n");
            }
        } else {
            die("Abording: no valid argument given\n");
        }
    } else { // 123s ain't running
        die("Abording: Empty SHM\n");
    }
} else {
    die("Usage: pool123s { power | energy }\n");
}
?>

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

Re: meterN 0.8

Post by jeanmarc » Thu Aug 31, 2017 10:17 am

Mind that is is not an issue for meterN to get no value. It's not a big deal to have missing data, i don't see the problem, you could have empty space in the csv.
I could slightly change pool123s to avoid the PHP Notice though.

flane
Posts: 69
Joined: Mon Aug 11, 2014 7:22 am

Re: meterN 0.8

Post by flane » Thu Aug 31, 2017 3:03 pm

jeanmarc wrote:
Thu Aug 31, 2017 10:17 am
Mind that is is not an issue for meterN to get no value. It's not a big deal to have missing data, i don't see the problem, you could have empty space in the csv.
Sure, but I do not like missing data :D
jeanmarc wrote:
Thu Aug 31, 2017 10:17 am
I could slightly change pool123s to avoid the PHP Notice though.
Great ;)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest