Hi Squeezer, darf ich dich mal um Hilfe bitten?
Ich habe dein Script mit meinem Benutzernamen und dem Passwort (im Post hier geändert) so ausgeführt und erhalte offensichtlich bei der Abfrage keinen Zugang. Über den Browser aufgerufen geht es aber mit den Login-Daten.
Kannst du mir sagen was ich falsch mache?
Fehler:
Warning: Trying to access array offset on null in C:\ProgramData\Symcon\scripts\37299.ips.php on line 16
Warning: foreach() argument must be of type array|object, null given in C:\ProgramData\Symcon\scripts\37299.ips.php on line 37
Warning: Undefined variable $deviceState in C:\ProgramData\Symcon\scripts\37299.ips.php on line 53
Warning: Undefined variable $deviceState in C:\ProgramData\Symcon\scripts\37299.ips.php on line 72
Warning: Undefined variable $deviceState in C:\ProgramData\Symcon\scripts\37299.ips.php on line 72
Warning: Undefined variable $deviceState in C:\ProgramData\Symcon\scripts\37299.ips.php on line 72
Warning: Variable #57346 existiert nicht in C:\ProgramData\Symcon\scripts\37299.ips.php on line 75
Warning: Variable #58954 existiert nicht in C:\ProgramData\Symcon\scripts\37299.ips.php on line 76
Warning: Variable #22187 existiert nicht in C:\ProgramData\Symcon\scripts\37299.ips.php on line 77
Warning: Variable #18339 existiert nicht in C:\ProgramData\Symcon\scripts\37299.ips.php on line 78
Warning: Undefined variable $chargingState in C:\ProgramData\Symcon\scripts\37299.ips.php on line 82
Warning: Ereignis #18698 existiert nicht in C:\ProgramData\Symcon\scripts\37299.ips.php on line 82
Ausgabe (Text)
Ausgabe (HTML)
vG Timmy
<?
//API CURL Token
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"http://10.0.40.223/api/v1/token");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,"grant_type=password&username=TW&password=tiwqu9-h7Zxe-L0Rsq");
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
$result = curl_exec($ch);
if (curl_errno($ch)) print("CURL-Error:".curl_error($ch));
curl_close($ch);
//Access Token aus Ergebnis extrahieren
$accessToken = json_decode($result,true)["access_token"];
IPS_Sleep(1000);
//API CURL Daten
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"http://10.0.40.223/api/v1/measurements/live/");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,"[{\"componentId\":\"IGULD:SELF\"}]");
$headers = array();
$headers[] = "Authorization: Bearer ".$accessToken;
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
$result = curl_exec($ch);
if (curl_errno($ch)) print("CURL-Error:".curl_error($ch));
curl_close($ch);
//Daten aus Ergebnis extrahieren
$data = json_decode($result,true);
//Werte durchlaufen
foreach($data as $row)
{
//Parameter auslesen
if($row["channelId"] == "Measurement.Operation.EVeh.ChaStt") $chargingState = $row["values"][0]["value"]; //Status Ladevorgang { 200111 = nicht verbunden, 200112 = schlafend, 200113 = lädt }
if($row["channelId"] == "Measurement.Chrg.ModSw") $chargingMode = $row["values"][0]["value"]; //Status Drehschalter {4950 = Intelligente Ladung, 4718 = Schnellladen}
if($row["channelId"] == "Measurement.Metering.GridMs.TotWIn.ChaSta") $powerLoading = $row["values"][0]["value"]; //Leistung Ladestation in W
if($row["channelId"] == "Measurement.ChaSess.WhIn") $energyLoading = $row["values"][0]["value"]; //Aktueller Ladevorgang in Wh
if($row["channelId"] == "Measurement.Metering.GridMs.TotWhIn.ChaSta") $counterLoading = $row["values"][0]["value"]; //Zählerstand Ladestation in Wh
if($row["channelId"] == "Measurement.GridMs.A.phsA") $electricityP1 = $row["values"][0]["value"]; //Strom an P1 in A
if($row["channelId"] == "Measurement.GridMs.A.phsB") $electricityP2 = $row["values"][0]["value"]; //Strom an P2 in A
if($row["channelId"] == "Measurement.GridMs.A.phsC") $electricityP3 = $row["values"][0]["value"]; //Strom an P3 in A
if($row["channelId"] == "Measurement.Operation.Health") $deviceState = $row["values"][0]["value"]; //Status Ladestation { 307 = OK, 455 = Warnung, 35 = Alarm, 303 = Aus }
if($row["channelId"] == "Measurement.Operation.EVeh.Health") $vehicleState = $row["values"][0]["value"]; //Status Fahrzeug { 307 = OK, 455 = Warnung, 35 = Alarm, 303 = Aus }
}
//Prüfen, ob Ladestation OK ist
if($deviceState == 307)
{
//Variablen schreiben
SetValue(57346,$chargingState);
SetValue(58954,$chargingMode);
SetValue(44613,round($powerLoading / 10) * 10);
SetValue(44172,round($energyLoading / 1000,3));
SetValue(27947,round($counterLoading / 1000,3));
SetValue(31310,abs(round($electricityP1,1)));
SetValue(55048,abs(round($electricityP2,1)));
SetValue(48330,abs(round($electricityP3,1)));
SetValue(22187,$deviceState);
SetValue(18339,$vehicleState);
}
//Ladestation ist nicht okay
else
{
//Bei unbekanntem Zustand auf Reset festlegen
if($deviceState != 455 and $deviceState != 35 and $deviceState != 303) $deviceState = 16777700;
//Variablen schreiben
SetValue(57346,0);
SetValue(58954,0);
SetValue(22187,$deviceState);
SetValue(18339,0);
}
//Timer abhängig vom Ladestatus setzen
if($chargingState == 200113) IPS_SetEventCyclic(18698,0,0,0,0,1,10); else IPS_SetEventCyclic(18698,0,0,0,0,1,30);
?>