meterN and 123solar on different computers

Talks about metering
Post Reply
fabix68
Posts: 3
Joined: Tue Jun 30, 2015 6:43 am

meterN and 123solar on different computers

Post by fabix68 » Tue Jun 30, 2015 6:48 am

Hi,
I would use 123solar installed on Pogoplug (Arch linux) with meterN installed on raspberry .
Can I send data from 123solar at MeterN?
123solar manages 9 converters but my interest is only one of the 9

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

Re: meterN and 123solar on different computers

Post by jeanmarc » Tue Jun 30, 2015 9:47 am

Hello,
Sure, that would be possible and easy. Just write a simple com app that request http://hostname/123solar/programs/progr ... ?invtnum=1 and retrieve the KWHT value.
Then put it into the appropriate format.

If you have trouble i could write the script later on.
Bye

fabix68
Posts: 3
Joined: Tue Jun 30, 2015 6:43 am

Re: meterN and 123solar on different computers

Post by fabix68 » Tue Jun 30, 2015 11:49 am

thanks jean , always available .
Salvatore

nicolbe
Posts: 2
Joined: Mon Oct 12, 2015 6:56 am

Re: meterN and 123solar on different computers

Post by nicolbe » Wed Nov 11, 2015 12:51 pm

Hi,

i've modified the 123solar pooler in order to retrieve data from 123solar application installed in another machine.
If anyone has the same need, just copy/paste the attached code into a new file in comapps/ dir named 123solar.php.

Of course feel free to post any suggestion/error correction in case.

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
// You'll need to setup the path to 123, your inverter number and your meter id
// Then ln -s /srv/http/metern/comapps/123solar.php /usr/bin/123solar
// Request Main command with '123solar energy' and live command '123solar power'

// 123solar config
$invtnum    = 1;
$pathto123s = 'http://hostname/123solar/programs/programlive.php?invtnum='.$invtnum;

// meterN config
$METERID    = 'solar';
$INVTmetnum = 1; // meter number

//
// Do not make changes beyond this line
//
// Global variables
$KWHT_tot = 0;
$GP = 0;

// No edit is needed below
if (isset($argv[1]))
{
    if ($argv[1] == 'power')
        {
            // create curl resource
            $ch = curl_init();

            // set url
            curl_setopt($ch, CURLOPT_URL, $pathto123s);

			//return the transfer as a string
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

            //decode the JSON into an array if hte second param is set to true otherwise the JSON will be decoded into an object
            $arrayDecodedFromJSON = json_decode(curl_exec($ch), true);

            // close curl resource to free up system resources
            curl_close($ch);

            $GP = $arrayDecodedFromJSON['G1P'] + $arrayDecodedFromJSON['G2P'] + $arrayDecodedFromJSON['G3P'];
			if ($GP > 1000)
			{
			   $GP = round($GP, 0);
			}
			else
			{
				$GP = round($GP, 1);
			}
		}
    elseif ($argv[1] == 'energy')
        {
            // create curl resource
            $ch = curl_init();

            // set url
            curl_setopt($ch, CURLOPT_URL, $pathto123s);

            //return the transfer as a string
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

            //decode the JSON into an array if hte second param is set to true otherwise the JSON will be decoded into an object
            $arrayDecodedFromJSON = json_decode(curl_exec($ch), true);

            // close curl resource to free up system resources
            curl_close($ch);

			$awdate = $arrayDecodedFromJSON['awdate']; //test if inverter is up or not
			if ($awdate == "--:--")
			{
			   $KWHT_tot = 0; // Inverter is off
			}
			else
			{
				$KWHT_tot = round(($arrayDecodedFromJSON['KWHT'] * 1000), 0); //in Wh
			}
		}

    if ($argv[1] == 'energy' && $KWHT_tot == 0)
        { // 123s ain't running at night retrieve the value in meterN csv
        $dir    = '../data/csv/';
        $output = array();
        $output = glob($dir . '*.csv');
        sort($output);
        $cnt = count($output);

        if ($cnt > 0)
        {
            $lines      = file($output[$cnt - 1]);
            $contalines = count($lines);

            $KWHT_tot = null;
            $j    = 0;
            while (!isset($KWHT_tot))
            {
                $j++;
                $array = preg_split('/,/', $lines[$contalines - $j]);
                $KWHT_tot  = trim($array[$INVTmetnum]);
                if ($KWHT_tot == '')
                {
                    $KWHT_tot = null;
                }
                if ($j == $contalines)
                {
                    $KWHT_tot = null; // No value found
                }
            }
        }
        else
        {
            die("Abording:no csv found\n");
        }
    }

    if ($argv[1] == 'power' && $GP == 0)
    { // 123s ain't running
        $GP = 0;
    }

    if ($argv[1] == 'power')
    {
        echo "$METERID($GP*W)\n";
    }
    elseif ($argv[1] == 'energy')
    {
        echo "$METERID($KWHT_tot*Wh)\n";
    } 
	else
    {
        die("Abording: no valid argument given\n");
    }
}
else
{
    die("Usage: 123solar { power | energy }\n");
}
?>

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest