sems portal
Solar output
// Code written in a night by Roeland Kindt for SEMS portal retrieval
// PVoutput portion copied from older Goodwe2PVoutput script, thanks Antonboonstra!
// Below portion is for PVOUTput site
// Retrieve API key from PVOutput, you can create it on http://pvoutput.org/account.jsp under API settings
//$keyPVO = "af2df240fc4d2f367866cf7cee1280ad8a1dd4cc";
// Fill in your System ID, you can retrieve it from http://pvoutput.org/account.jsp (at the bottom)
//$sidPVO = "64399";
// SEMS portal portion
//You can retriev powerstation id from URL if you visit website, or run the script once, it will provide the ID to you.
//$powerstation_id="442e67e1-9af0-48db-9cd0-b403a53fa362"; // not mandatory first run
// Login SEMS portal website
$email="";
// Password SEMS portal website.
$password="";
//enable+/disable debug/test mode
$test=true; // if true shows pvoutput url but does not submit it, set to false if working.
$debug=false; // prints var_dump of vars, set to true to var_dump
// below code does not need modifications.
//$vars = "{"account":"$email","pwd":"$password"}";
//logic retrieved from original script by antonboostra
//echo "<pre>n";
// determine if it is night or day, to prevent retrieval of data (reduce API calls)
//$day = date_sunrise(time(), SUNFUNCS_RET_TIMESTAMP, 52, 5.5);
//$night = date_sunset(time(), SUNFUNCS_RET_TIMESTAMP, 52, 5.5);
//$now = time();
//if($now < ($day-600) || $now > ($night+600)) // 600 seconds (=10 minutes) margin
{
//echo "It is before dusk (".date("H:i",$day)." hour) or after sunset (".date("H:i",$night)." hour) n";
//if(!$test) exit(); // exit so we don't run the rest of the code
}
//basic setup for logging into SEMS portal
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://globalapi.sems.com.cn/api/v1/Common/CrossLogin");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding: gzip, deflate',
'Accept: */*',
'Connect: Keep-alive',
'Content-Type: application/json',
'Host: globalapi.sems.com.cn',
'Token: {"version":"v2.1.0","client":"ios","language":"en"}',
'User-Agent: PVMaster/2.1.0 (iPhone; iOS 12.0; Scale/2.00)',
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
//retrieved basic login details
$server_output = json_decode($server_output, true);
if($debug) echo var_dump($server_output);
$uid="";
$timestamp="";
$token="";
$retrieval=false;
if($server_output["msg"]=="success"){
//echo "<br/>retrieval ok <br/>";
$uid=$server_output["data"]["uid"];
$timestamp=$server_output["data"]["timestamp"];
$token=$server_output["data"]["token"];
$retrieval=true;
}else{
echo "<br/>Basic SEMS portal login failed. Enable debug mode <br/>";
curl_close ($ch);
exit();
}
if($retrieval && trim($powerstation_id)==""){
//$vars="{"page_size":"5","orderby":"","powerstation_status":"","key":"","page_index":"1","powerstation_id":"","powerstation_type":""}";
$headers = [
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding: gzip, deflate',
'Accept: */*',
'Connect: Keep-alive',
'Content-Type: application/json',
'Host: globalapi.sems.com.cn',
'Token: {"version":"v2.1.0","client":"ios","language":"en","timestamp":'.$timestamp.',"uid":"'.$uid.'","token":"'.$token.'"}',
'User-Agent: PVMaster/2.1.0 (iPhone; iOS 12.0; Scale/2.00)',
];
curl_setopt($ch, CURLOPT_URL,"https://euapi.sems.com.cn/api/PowerStationMonitor/QueryPowerStationMonitorForApp");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output2 = curl_exec ($ch);
$server_output2 = json_decode($server_output2, true);
if($server_output2["msg"]=="success"){
if($debug) var_dump($server_output2);
//echo "<br/>retrieval powerstation ok <br/>";
$powerstation_id=$server_output2["data"][0]["powerstation_id"];
//echo "retrieved ".$powerstation_id."<br/>";
}
}else{
echo "Powerstation id is provided: ".$powerstation_id."<br/>";
}
$retrieval3=false;
if($retrieval&& !trim($powerstation_id)==""){
//echo "retrieval 3 ok <br/>";
//$vars="{"powerStationId":"$powerstation_id"}";
$headers = [
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding: gzip, deflate',
'Accept: */*',
'Connect: Keep-alive',
'Content-Type: application/json',
'Host: globalapi.sems.com.cn',
'Token: {"version":"v2.1.0","client":"ios","language":"en","timestamp":'.$timestamp.',"uid":"'.$uid.'","token":"'.$token.'"}',
'User-Agent: PVMaster/2.1.0 (iPhone; iOS 12.0; Scale/3.00)',
];
curl_setopt($ch, CURLOPT_URL,"https://euapi.sems.com.cn/api/v1/PowerStation/GetMonitorDetailByPowerstationId");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output3 = curl_exec ($ch);
$server_output3 = json_decode($server_output3, true);
if($debug) var_dump($server_output3);
$retrieval3=true;
$pac=$server_output3["data"]["kpi"]["pac"];
$powerpki=$server_output3["data"]["kpi"]["power"];
//$powerpki=$server_output3["data"]["kpi"]["total-power"];
$temp=$server_output3["data"]["inverter"][0]["tempperature"];
$vpv1=$server_output3["data"]["inverter"][0]["d"]["vpv1"];
$vpv2=$server_output3["data"]["inverter"][0]["d"]["vpv2"];
$vpv3=$server_output3["data"]["inverter"][0]["d"]["vpv3"];
$vpv4=$server_output3["data"]["inverter"][0]["d"]["vpv4"];
$vpv5=$server_output3["data"]["inverter"][0]["d"]["vpv5"];
$vpv6=$server_output3["data"]["inverter"][0]["d"]["vpv6"];
$vpv7=$server_output3["data"]["inverter"][0]["d"]["vpv7"];
$vpv8=$server_output3["data"]["inverter"][0]["d"]["vpv8"];
$vpv9=$server_output3["data"]["inverter"][0]["d"]["vpv9"];
$vpv10=$server_output3["data"]["inverter"][0]["d"]["vpv10"];
$power = intval($pac);
$energy_cum = round(floatval($powerpki)*1.000,4);
//$vdc = round(floatval($vpv1),1); // v6 = Voltage DC van MPP1
//$temperature = round(floatval($temp),1);
//echo "<h1>Totaal = $total-power kWh </h1>";
echo "<h1>Vandaag is er $energy_cum kWh geproduceerd</h1>";
echo "<h1>De panelen leveren nu $pac Wh</h1>";
//echo "<h1>DC voltage 1 = $vdc, DC voltage 2 = $vpv2 </h1>";
//echo "<h1>Totaal is er 24711.70 kWh geproduceerd </h1>";
}else{
echo "<br/>Advanced SEMS portal data retrieval failed. Enable debug mode <br/>";
curl_close ($ch);
exit();
}
curl_close ($ch);
if($retrieval && $retrieval3){
// Combine the RUL to call PVoutpout and submit data Stel
//$url = 'https://pvoutput.org/service/r2/addstatus.jsp?key='.$keyPVO.'&sid='.$sidPVO.'&d='.date("Ymd").'&t='.date("H:i").'&v1='.$energy_cum.'&v2='.$power.'&v5='.$temperature.'&v6='.$vdc.'&c1=0';
// if $test is true, only show url otherwise submit
if($test){
//echo "URL = $url n";
}else{
$responds = file_get_contents($url);
echo "Responds PVOutput was: $responds n";
if($responds == "OK 200: Added Status")
{
echo "The values were succesfully retrieved and submitted to PVOutput n";
}
else
{
echo "Issue submitting to PVOutput, let's try again...<br>n";
sleep(4); // wacht 4 seconden
$responds = file_get_contents($url);
if($responds == "OK 200: Added Status")
{
echo "The values were succesfully retrieved and submitted to PVOutput n";
}
else
{
echo "PVOutput submit failed for a second time, please verify if settings are correct.n";
echo "Responds PVOutput was: $responds n";
}
}
}
}
echo '</pre>';