Der Fehler tritt aufgrund der folgenden Zeile im Code auf: (Zeile: 47)
$content = Sys_GetURLContent("https://monitoringapi.solaredge.com/site/$id/overview?api_key=$apikey");
Wenn der Link direkt eingegeben wird mit ohne Variable mit API-Key + ID direkt funktioniert der Abruf:
$content = Sys_GetURLContent("https://monitoringapi.solaredge.com/site/id12345/overview?api_key=apikey12345");
Die angegeben Variablen im Sys_GetURLContent verursachen das Problem, er sagt dann immer er erwarted einen String hat aber hat einen bool-Wert erkannt, wenn ich das richtig verstehe.
Was ist an der Syntax faslch, hat jemand einen tipp?
Code:
<?php
declare(strict_types=1);
class Wechselrichter extends IPSModule
{
public function Create()
{
//Never delete this line!
parent::Create();
$this->RegisterVariableFloat("Actual", $this->Translate("Actual"),"",0);
$this->RegisterVariableFloat("Today", $this->Translate("Today"),"",1);
$this->RegisterVariableFloat("Month", $this->Translate("Month"),"",2);
$this->RegisterVariableFloat("Year", $this->Translate("Year"),"",3);
$this->RegisterVariableFloat("Total", $this->Translate("Total"),"",4);
$this->RegisterPropertyInteger("Aktualisierungsinvertall", 9000000);
$this->RegisterPropertyString("ApiKey", "");
$this->RegisterPropertyString("Id", "");
//Create the timer for the updateintervall
$this->RegisterTimer("Update", 9000000, 'A_UpdateAuswertung(' . $this->InstanceID . ', "Id","ApiKey");');
}
public function Destroy()
{
//Never delete this line!
parent::Destroy();
}
public function ApplyChanges()
{
//Never delete this line!
parent::ApplyChanges();
$this->SetTimerInterval("Update", $this->ReadPropertyInteger("Aktualisierungsinvertall") * 1000);
$this->UpdateAuswertung($this->ReadPropertyString("Id"),$this->ReadPropertyString("ApiKey"));
}
public function UpdateAuswertung (string $id, string $apikey) {
if ($id != "")
{
$content = Sys_GetURLContent("https://monitoringapi.solaredge.com/site/$id/overview?api_key=$apikey");
//$content = Sys_GetURLContent("https://monitoringapi.solaredge.com/site/ID123/overview?api_key=APIkey12345");
$json=json_decode($content);
$cache = $json->overview->currentPower->power / 1000;
$this->SetValue("Actual", $cache);
# Generated day
$cache = $json->overview->lastDayData->energy / 1000;
$this->SetValue("Today", $cache);
# Generated month
$cache = $json->overview->lastMonthData->energy / 1000;
$this->SetValue("Month", $cache);
# Generated year
$cache = $json->overview->lastYearData->energy / 1000;
$this->SetValue("Year", $cache);
# Generated all
$cache = $json->overview->lifeTimeData->energy / 1000;
$this->SetValue("Total", $cache);
}
}
}
Fehlermeldung:
29.10.2021, 21:30:14 | TimerPool | Wechselrichter (Update):
Warning: Error 403, {„String“:„Invalid token“} in C:\ProgramData\Symcon\modules\Solaredge\Wechselrichter\module.php on line 47
Fatal error: Uncaught TypeError: json_decode() expects parameter 1 to be string, bool given in C:\ProgramData\Symcon\modules\Solaredge\Wechselrichter\module.php:49
Stack trace:
#0 C:\ProgramData\Symcon\modules\Solaredge\Wechselrichter\module.php(49): json_decode(false)
#1 C:\ProgramData\Symcon\scripts__generated.inc.php(7207): Wechselrichter->UpdateAuswertung(‚Id‘, ‚ApiKey‘)
#2 C:\Windows\System32-(1): A_UpdateAuswertung(28157, ‚Id‘, ‚ApiKey‘)
#3 {main}
thrown in C:\ProgramData\Symcon\modules\Solaredge\Wechselrichter\module.php on line 49