meterN 0.8

Talks about metering
Locked
megamarco83
Posts: 104
Joined: Tue Apr 14, 2015 9:25 am

Re: meterN 0.8

Post by megamarco83 » Mon Aug 01, 2016 12:31 pm

hi, thanks for support
mmmm strange, i'm sure that i reloaded the webpage, but i try for sure your suggestio!
how i can reimport the link to 123solar?
thanks so much!

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

Re: meterN 0.8

Post by megamarco83 » Mon Aug 01, 2016 11:45 pm

hi, this evening i try your suggestion, now i have update metern from 0.8.1 to latest version, apparently successful.
i try to explain, all is working fine with new version, with any problem...i run the new metern for 30minutes, and as i said all work well, live meters and total meters
after 30minutes of works well, i try to reboot my raspberry.
since i have rebooted i'm not able to see the meter of consumption because it retuns zero as value :(
but before rebooting it was working and live updated !
i try test the live comand in admin mode:

Code: Select all

poolerconsumi 1 power
and the respons is:
1(0*W)
is a valid entry !
so the problem is that metern is not able to measure the live consumption....but before rebooting raspberry it works :(
if i test the command (not live, but the total one) :

Code: Select all

poolerconsumi 1 energy
the respond is correct:
1(4931688*W)
is a valid entry !
so it's correct
what i have to do?
why before rebooting metern works and after reboot not?where i'm wrong or what i'm missing?
thanks for your support again!!!!

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

Re: meterN 0.8

Post by jeanmarc » Tue Aug 02, 2016 7:08 am

Hi,
Well, the issue is not related to meterN but to your communication app. I don't know the one you are using, i give few examples in /downloads/metern/comapps :roll:

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

Re: meterN 0.8

Post by megamarco83 » Tue Aug 02, 2016 11:52 am

hi jeanmarc, yes you are right....the problem seams not related to metern, but what i find strange is that if i run the update all is working fine till i reboot
today i try again....and all is working well changing from 0.8.1 to 0.8.2.7.2 but if i reboot the raspberry i found that problem on comunication :(
i use the sdm120c with the rs485 script: pooler485.sh
for sure i copy my last comapps config and script from my old version

this is my communication app that is named poolerconsumi.php that works fine with 0.8.1 version

Code: Select all

#!/usr/bin/php
<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}
// This script will output a meterN compatible format for the main command
// You'll need to setup the path to meterN ($pathtomn). Put the meters numbers ($metnum) and the corresponding command ($cmd) :
// ln -s /var/www/metern/comapps/poolerconsumi.php /usr/bin/poolerconsumi
// poolerconsumi [MeterID] [energy | power]

// No edit is needed below
if (!isset($argv[1],$argv[2])) {
$argv[1]=null;
}

if ($argv[1]!= null && ($argv[2]== 'power' || $argv[2]== 'energy')) {
    
	$pathtomn = '/var/www/metern';
	$prevcount = 0; // Inserire qui il totale del contatore precedente
	$metnum = $argv[1]; // Meter ID Consumi

	$cmd = "more /run/shm/metern$metnum.txt | egrep \"^$metnum\(\" | grep \"*Wh)\""; // Request Energy values
	$cmd1 = "more /run/shm/metern$metnum.txt | egrep \"^$metnum\(\" | grep \"*W)\""; // Request Power values
    #echo "$cmd\n";
    #echo "$cmd1\n";

	// End of setup

	define('checkaccess', TRUE);
	include("$pathtomn/config/config_main.php");
	include("$pathtomn/config/config_met$metnum.php");
    
    if ($argv[2]== 'energy') {
        // acquisisce il valore precedente dal csv
        $dir    = '/var/www/metern/data/csv';
        $output = array();
        $output = glob($dir . '/*.csv');
        sort($output);
        $cnt = count($output);
            
        if (file_exists($output[$cnt - 1])) {
            $file       = file($output[$cnt - 1]); // today
            $contalines = count($file);

            if ($contalines > 1) {
                $prevarray = preg_split("/,/", $file[$contalines - 1]);
                
            } elseif ($contalines == 1 && file_exists($output[$cnt - 2])) { // yesterday, only header
                $file       = file($output[$cnt - 2]);
                $contalines = count($file);
                $prevarray = preg_split("/,/", $file[$contalines - 1]);
            }
            $cons_val_first = trim($prevarray[$metnum]);
        } else {
            $cons_val_first = null;
        }      

        #sleep(1); // oh why ?
        // Now retrieve the current value
        $datareturn = shell_exec($cmd);
        $datareturn = trim($datareturn);
        $datareturn = preg_replace("/^${'ID'.$metnum}\(/i", '', $datareturn); // VALUE*UNIT)
        $lastval    = preg_replace("/\*[a-z0-9]+\)$/i", '', $datareturn); // VALUE
        #echo "$lastval\n";

        settype($lastval, 'float');
        settype($prevcount, 'float');
        settype($cons_val_first, 'float');

        $lastval += $prevcount; // aggiunge il correttore del totale

        if ($lastval < $cons_val_first) { // controlla se il contatore segna meno del valore precedente
            $lastval = $cons_val_first;
        }
        $lastval = round($lastval, ${'PRECI' . $metnum});
        $str     = utf8_decode("${'ID'.$metnum}($lastval*${'UNIT'.$metnum})\n");
        file_put_contents("/run/shm/consumi$metnum.txt", $str);
        echo "$str";
    
    }elseif ($argv[2]== 'power') {
        #sleep(1); // oh why ?
        // Now retrieve the current value
        $datareturn = shell_exec($cmd1);
        $datareturn = trim($datareturn);
        $datareturn = preg_replace("/^${'ID'.$metnum}\(/i", '', $datareturn); // VALUE*UNIT)
        $powerval   = preg_replace("/\*[a-z0-9]+\)$/i", '', $datareturn); // VALUE
        #echo "$powerval\n";

        settype($powerval, 'float');

        $powerval = round($powerval, ${'PRECI' . $metnum});
        $str     = utf8_decode("${'ID'.$metnum}($powerval*${'LIVEUNIT'.$metnum})\n");
        echo "$str";
    }
    
} else {
    die("Usage: poolerconsumi {MeterID} {energy | power}\n");
}
?>
i also copy the config_daemon.php in config folder:

Code: Select all

<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}
// Startup of the com apps daemon as 'http' user if needed

//$output = shell_exec('pkill -f poolSDM485 > /dev/null 2>&1 &');
//$output = shell_exec('poolSDM485 1 9600 /dev/sdm > /dev/null 2>/dev/null &');

//$output = shell_exec('/usr/bin/curl http://192.168.1.12/startsdm.php');
//$output = shell_exec("/srv/http/metern/comapps/poolmeters.py live > /dev/null 2>&1 &");

// Startup of the com apps daemon as 'http' user if needed
$output = shell_exec('pkill -f pooler485 > /dev/null 2>&1 &');
sleep(1);
$output = shell_exec('pooler485 1 9600 /dev/ttymetern > /dev/null 2>/dev/null &');
?>
and this is my script comappsdaemon.php

Code: Select all

// Startup of the com apps daemon as 'http' user if needed
// $output = shell_exec('pkill -f pooler485 > /dev/null 2>&1 &');
// sleep(1);
// $output = shell_exec('pooler485 1 9600 /dev/ttymetern > /dev/null 2>/dev/null &');
could you please have a look on it?
for sure you are much better than me, and maybe knowing the differences between 0.8.1 and 0.8.2.7.2 you could where is the issue
thanks a lot for your big effort!!!!

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

Re: meterN 0.8

Post by jeanmarc » Tue Aug 02, 2016 11:58 am

config_daemon has been reviewed in mN0.8.2.5 to allow stop 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)) { // Start Daemon
$output = shell_exec('pooler485 1 9600 /dev/ttymetern > /dev/null 2>/dev/null &');
} else { //Stop
$output = shell_exec('pkill -f pooler485 > /dev/null 2>&1 &');
}
?>

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

Re: meterN 0.8

Post by megamarco83 » Tue Aug 02, 2016 1:27 pm

wow you are great jeanmarc!
so maybe that's the trick!
now...on metern 0.8.1 to work with my communication i need to edit the config_daemon.php and insert on bottom of the file this line:

Code: Select all

// Startup of the com apps daemon as 'http' user if needed
$output = shell_exec('pkill -f pooler485 > /dev/null 2>&1 &');
sleep(1);
$output = shell_exec('pooler485 1 9600 /dev/ttymetern > /dev/null 2>/dev/null &');
now, if i understand well, since metern 0.8.2.5 i have to modify the config_daemon.php and changing it like this:

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)) { // Start Daemon
$output = shell_exec('pooler485 1 9600 /dev/ttymetern > /dev/null 2>/dev/null &');
} else { //Stop
$output = shell_exec('pkill -f pooler485 > /dev/null 2>&1 &');
}
?>
correct?
this evening i will try, thanks again!

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

Re: meterN 0.8

Post by jeanmarc » Tue Aug 02, 2016 2:04 pm

I bet.. give it a try, it work for me ;)

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

Re: meterN 0.8

Post by megamarco83 » Tue Aug 02, 2016 7:30 pm

hi that's perfect!!
now works great! thanks!!!!
but i fund a problem, when i close my browser
if i go to metern website, and then click on "admin"
i see this message:
Thanks for using meterN !

Please, define a login and password
:
and it ask to me to inser a password....why it has not in memory my old password?
if i insert my passwork, and click "ok"
and after that i try to ho in homepage metern and then click on admin
i receive this message:
Your webserver don't currently allow HTTP authentication. It is vulnerable !

Please configure your webserver : 192.168.0.105 (Apache/2.2.22 (Debian)) and then, refresh your browser.
Credentials have been created as config/.htpasswd
why this happen? i use raspberry wheezy...

but this happened only when i close my brower and reopen it to go in admin, because, for example during the procedure automatic to update metern, i still remain on page of metern, and if i go in admin, it works correctly
this problem is come out only when i close the browser and try again to go in admin
i try to go in admin also with smartphone and it's the same, it's no possible to enter...
thanks a lot again for help!

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

Re: meterN 0.8

Post by megamarco83 » Tue Aug 02, 2016 7:36 pm

ok, i solved with this command:

Code: Select all

 cp -v /var/www/metern/config/.ht* /var/www/metern/admin
maybe it could help someone else....

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

Re: meterN 0.8

Post by jeanmarc » Tue Aug 02, 2016 8:33 pm

:idea: No ! don't put config files in admin/, you won't survive with the updates. That should be in config/
Please rather change your webserver's configuration and read the release's notes.

Locked

Who is online

Users browsing this forum: No registered users and 3 guests