Relaunching @edent_solar. Part 5 - Getting data out of Fronius Solarweb
Mostly notes to myself. My solar panels have an open API. But it's only available if I'm on the same network as the Fronius inverter. I can connect my system to https://www.solarweb.com/ so I can access it anywhere in the world - if I have the right password.
SolarWeb has an (optional) guest mode. You can view the panels' performance if you know the secret URl. It looks something like this:
https://www.solarweb.com/Home/GuestLogOn?pvSystemid=123-456-789
Visiting that URl sets some cookies and then redirects you to something like this:
https://www.solarweb.com/PvSystems/PvSystem?pvSystemId=abc-def-hij
And the live performance data is at:
https://www.solarweb.com/ActualData/GetCompareDataForPvSystem?pvSystemId=abc-def-hij
In order to make a request to the data URl, you need the cookies from the first URl. Here's some horrible PHP which will do just that.
PHP
<?php
$ch = curl_init();
// Get the loging URl
curl_setopt($ch, CURLOPT_URL, "https://www.solarweb.com/Home/GuestLogOn?pvSystemid=123-456-789");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // It redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Store and use cookies
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');
// Get the page
curl_exec($ch);
// Find redirect URL
$redirect_url = curl_getinfo($ch)["url"];
// It is in the form https://www.solarweb.com/PvSystems/PvSystem?pvSystemId=abc-def-hij
// Get the System ID
$system_id_query = parse_url($redirect_url, PHP_URL_QUERY);
parse_str($system_id_query, $params);
$system_id = $params["pvSystemId"];
// Finish up this request
curl_close($ch);
// 2nd request
$ch = curl_init();
// URl of the data
curl_setopt($ch, CURLOPT_URL, "https://www.solarweb.com/ActualData/GetCompareDataForPvSystem?pvSystemId={$system_id}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Use cookies
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');
$output = curl_exec($ch);
// Output JSON
// header("Content-Type: application/json");
echo $output;
// Clean up
curl_close($ch);
And, hey presto, out pops a scrap of JSON:
JSON
{
"Datasources":"n/a",
"IsOnline":true,
"P_PV":402.0
}
Kaden says:
Michael says:
Thanks, you saved my day (and some grey hair) - could not figure out to properly calculate the current consumption between 2 inverters and a battery, now I do have a somehow good value to go with.