Fronius Inverter Solar API V1

others protocols
Lore_
Posts: 11
Joined: Wed May 17, 2017 3:46 pm

Fronius Inverter Solar API V1

Post by Lore_ » Wed May 17, 2017 4:14 pm

Hello jeanmarc.

I would ask you if it's possible to write a protocol file for the Fronius inverters.
I found a script (https://github.com/edent/Fronius-DataMa ... lar-Logger) that can extract data from this inverter and create a daily file csv.
In practice this API is a http request to the inverter address that returns the json format data
Do you think it's possible to do a protocol file for this kind of inverters ?
I saw that in the 123solar folder "scripts/protocols" there are various protocol files for different inverters, but i am not able to do this file. I would therefore ask you, if possible, if You can do a protocol file for this inverter.
There is also the manual of the Fronius Solar API v1
(https://www.fronius.com/cps/rde/xbcr/SI ... apshot.pdf)

Thanks in advance.

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

Re: Fronius Inverter Solar API V1

Post by jeanmarc » Wed May 17, 2017 6:59 pm

Hi lore,
I'am not sure it's the good tool, you need a communication app that return values.
I haven't looked thoroughly but fslurp seem more appropriate.
I'am surely ok to help but i need data output ;)

Lore_
Posts: 11
Joined: Wed May 17, 2017 3:46 pm

Re: Fronius Inverter Solar API V1

Post by Lore_ » Wed May 17, 2017 11:58 pm

Hi jeanmarc,

first of all thanks for the answer.

fslurp pull the data from a Fronius inverter systems via a serial port connection, while this one by running this Internet address (IP address inverter):

Code: Select all

http://192.168.1.7/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData 
this page is returned:

Code: Select all

{
	"Head" : {
		"RequestArguments" : {
			"DataCollection" : "CommonInverterData",
			"DeviceClass" : "Inverter",
			"DeviceId" : "1",
			"Scope" : "Device"
		},
		"Status" : {
			"Code" : 0,
			"Reason" : "",
			"UserMessage" : ""
		},
		"Timestamp" : "2014-12-10T11:15:43+01:00"
	},
	"Body" : {
		"Data" : {
			"DAY_ENERGY" : {
				"Value" : 238,
				"Unit" : "Wh"
			},
			"FAC" : {
				"Value" : 49.96,
				"Unit" : "Hz"
			},
			"IAC" : {
				"Value" : 0.98,
				"Unit" : "A"
			},
			"IDC" : {
				"Value" : 0.86,
				"Unit" : "A"
			},
			"PAC" : {
				"Value" : 225,
				"Unit" : "W"
			},
			"TOTAL_ENERGY" : {
				"Value" : 5862967,
				"Unit" : "Wh"
			},
			"UAC" : {
				"Value" : 224.7,
				"Unit" : "V"
			},
			"UDC" : {
				"Value" : 293.7,
				"Unit" : "V"
			},
			"YEAR_ENERGY" : {
				"Value" : 2386642,
				"Unit" : "Wh"
			},
			"DeviceStatus" : {
				"StatusCode" : 7,
				"MgmtTimerRemainingTime" : -1,
				"ErrorCode" : 0,
				"LEDColor" : 2,
				"LEDState" : 0,
				"StateToReset" : false
			}
		}
	}
}
where
DAY_ENERGY - unsigned integer - Energy generated on current day
FAC - floating point - AC frequency
IAC - floating point - AC current
IDC - floating point - DC current
PAC - unsigned integer - AC power
TOTAL_ENERGY - unsigned integer - Energy generated overall
UAC - floating point - AC voltage
UDC - floating point - DC voltage
IDC - floating point - DC current
YEAR_ENERGY - unsigned integer - Energy generated in current year
DeviceStatus - object Status information about inverter

Thanks in advance.

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

Re: Fronius Inverter Solar API V1

Post by jeanmarc » Thu May 18, 2017 9:47 am

Hi Lore,

Try this as scripts/protocols/fronius.php, I guess it's a good start ;)

Code: Select all

<?php
if (!defined('checkaccess')) {
    die('Direct access not permitted');
}
// For Fronius https://github.com/victronenergy/dbus-fronius
$CMD_RETURN = ''; // Always initialize

function is_json($string, $return_data = false)
{
    $data = json_decode($string);
    return (json_last_error() == JSON_ERROR_NONE) ? ($return_data ? $data : TRUE) : FALSE;
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData');
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$CMD_RETURN = strip_tags(curl_exec($ch));
curl_close($ch);

$dataarray = is_json($CMD_RETURN, TRUE);
if ($dataarray) {
    //print_r($dataarray);
    
    // Grid values
    $G1V = $dataarray->Body->Data->UAC->Value;
    settype($G1V, 'float');
    $G1A = $dataarray->Body->Data->IAC->Value;
    settype($G1A, 'float');
    $G1P = $dataarray->Body->Data->PAC->Value;
    settype($G1P, 'float');
    $G2V = null;
    $G2A = null;
    $G2P = null;
    $G3V = null;
    $G3A = null;
    $G3P = null;
    $FRQ = $dataarray->Body->Data->FAC->Value;
    settype($FRQ, 'float');
    
    // Strings
    $I1V = $dataarray->Body->Data->UDC->Value;
    settype($I1V, 'float');
    $I1A = $dataarray->Body->Data->IDC->Value;
    settype($I1A, 'float');
    $I1P = round($I1V * $I1A, 2);
    settype($I1P, 'float');
    $I3V = null;
    $I3A = null;
    $I3P = null;
    $I4V = null;
    $I4A = null;
    $I4P = null;
    
    
    // Inverter
    $EFF = round(($G1P / $I1P) * 100, 2);
    $INVT = null;
    $BOOT = null;
    $KWHT = $dataarray->Body->Data->TOTAL_ENERGY->Value;
    $KWHT /= 1000;
    settype($KWHT, 'float');
    
    $RET = 'OK';
} else {
    $RET = 'NOK';
}
?>

Lore_
Posts: 11
Joined: Wed May 17, 2017 3:46 pm

Re: Fronius Inverter Solar API V1

Post by Lore_ » Thu May 18, 2017 11:00 am

Hi jeanmarc,

thanks very much :D

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

Re: Fronius Inverter Solar API V1

Post by jeanmarc » Thu May 18, 2017 11:48 am

So, it works ? :geek:

Lore_
Posts: 11
Joined: Wed May 17, 2017 3:46 pm

Re: Fronius Inverter Solar API V1

Post by Lore_ » Thu May 18, 2017 1:10 pm

Hi jeanmarc,

i have a problem, in configuration inverters, protocol is fronius, but port ? , rs485 ?, with protocol fronius 123solar don't restart and "test comunication" don't running

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

Re: Fronius Inverter Solar API V1

Post by jeanmarc » Thu May 18, 2017 1:30 pm

You may leave Port and Adress empty, it's not used.
What do you got as test com return ?

Lore_
Posts: 11
Joined: Wed May 17, 2017 3:46 pm

Re: Fronius Inverter Solar API V1

Post by Lore_ » Thu May 18, 2017 1:59 pm

Hi jeanmarc,

Nothing happens, the configuration page disappears, and 123solar don't start.

I also tested this script, copied from solar.php

Code: Select all

/*    Global variables    */
//    IP Address of the Inverter
$dataManagerIP = "192.168.1.5";


//    Latitude and Longitude of where the solar panels are installed. Serve per trovare alba e tramonto, così di notte non funziona
$latitude  = 45.748021;
$longitude = 9.845357;


//    Path of the script - to ensure we're reading and writing the correct directory
$currentPath = dirname(__FILE__) . DIRECTORY_SEPARATOR;


//    Today's date - used for writing .csv and .png files.
$today = date('Y-m-d', time());
//    Path of the script - to ensure we're reading and writing the correct directory
$currentPath = dirname(__FILE__) . DIRECTORY_SEPARATOR;


//    Calculate the timezone offset
$this_timezone = new DateTimeZone(date_default_timezone_get());
$now = new DateTime("now", $this_timezone);
$offset = $this_timezone->getOffset($now);
//    Sunrise and Sunset times.
$sunriseTimestamp = date_sunrise(time(), SUNFUNCS_RET_TIMESTAMP, 
                                 $latitude, $longitude, 
                                 ini_get("date.sunrise_zenith"), $offset);
$sunsetTimestamp = date_sunset(time(), SUNFUNCS_RET_TIMESTAMP, 
                               $latitude, $longitude, 
                               ini_get("date.sunset_zenith"), $offset);


//    Are we between sunrise and set?
//    If so, start reading from the solar panels
if (time() >= $sunriseTimestamp && time() <= $sunsetTimestamp)
{
    //    API call for Fronius
    //    Documentation:
    //    https://www.fronius.com/cps/rde/xbcr/SID-539A9068-7638796D/fronius_international/42_0410_2012_318486_snapshot.pdf


    $apiURL = "http://".$dataManagerIP."/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData";


    //    Get the raw JSON
    $jsonData = file_get_contents($apiURL);


    //    Decode into an object
    $solar = json_decode($jsonData, true);


    //    Is the inverter up and running?
    if (7 == $solar["Body"]["Data"]["DeviceStatus"]["StatusCode"])
    {
        //    Get the variables in which we're interested
        $solarTimestamp   = $solar["Head"]["Timestamp"];                  //    Time according to the DataManager
        $solarPower       = $solar["Body"]["Data"]["PAC"]["Value"];       //    Real time AC being fed into the mains
        $solarACCurrent   = $solar["Body"]["Data"]["IAC"]["Value"];       //    Real time Ampere AC current
        $solarACVoltage   = $solar["Body"]["Data"]["UAC"]["Value"];       //    Real time Volt AC voltage
        $solarACFrequency = $solar["Body"]["Data"]["FAC"]["Value"];       //    Real time Hz AC frequency
        $solarDCCurrent   = $solar["Body"]["Data"]["IDC"]["Value"];       //    Real time Ampere AD current
        $solarDCVoltage   = $solar["Body"]["Data"]["UDC"]["Value"];       //    Real time Volt AD voltage
        $solarDayEnergy   = $solar["Body"]["Data"]["DAY_ENERGY"]["Value"];//    Total amount generated today


        //    Format for writing to CSV file - Da rivedere per 123solar
        //    Time,Energy,Total
        $solarArray = array($solarTimestamp, $solarPower, $solarACCurrent, $solarACVoltage, $solarACFrequency, $solarDCCurrent, $solarDCVoltage, $solarDayEnergy);
        //    Append the data to a CSV file named YYYY-MM-DD.csv
        $solarCSV = fopen($currentPath . $today . ".csv", 'a');
        fputcsv($solarCSV, $solarArray);
        fclose($solarCSV);




    }    
}
and it works, it creates a csv file with all the required data, it is slightly different from your script in the syntax of some commands

Thanks in advance.

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

Re: Fronius Inverter Solar API V1

Post by jeanmarc » Thu May 18, 2017 2:07 pm

hmm.. you need to edit the file, you may need to change :
http://localhost/solar_api/ to http://192.168.1.5/solar_api/

If it still don't work, please uncomment the //print_r($dataarray); and comment die('Direct access not permitted');

Then request from the terminal php 123solar/scripts/protocols/fronius.php

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest