Kann mir vielleicht jemand weiterhelfen?
Aktuell habe ich drei Schripte:
Script 1: pass
$user = "meine Mail Adresse";
$pw = "Mein Passwort";
Script 2 ist die Abfrage:
<?php
error_reporting(E_ALL);
include IPS_GetKernelDir()."scripts\\59757.ips.php";
include IPS_GetKernelDir()."scripts\\45657.ips.php";
$gardena = new gardena_sensor($user, $pw);
$mower = $gardena -> getFirstDeviceOfCategory($gardena::CATEGORY_SENSOR);
print_r($gardena);
und Script 3 ist die Class: „php_gardena_senor_class“
<?php
// -----------------------------------------------------------------------------
class gardena_sensor
{
var $user_id, $token, $locations;
var $devices = array();
const LOGINURL = "https://sg-api.dss.husqvarnagroup.net/sg-1/sessions";
const LOCATIONSURL = "https://sg-api.dss.husqvarnagroup.net/sg-1/locations/?user_id=";
const DEVICESURL = "https://sg-api.dss.husqvarnagroup.net/sg-1/devices?locationId=";
const CMDURL = "https://sg-api.dss.husqvarnagroup.net/sg-1/devices/|DEVICEID|/abilities/sensor/command?locationId=";
//-----------------------------------------------------------------------------
// Sensor
const CATEGORY_DEVICE_INFO = "device_info";
const CATEGORY_SENSOR = "sensor";
// Sensor Batterie
const CATEGORY_BATTERY = "battery";
// Sensor Radio - Funksignal
const CATEGORY_RADIO = "radio";
// Sensor Temperatur
const CATEGORY_AMBIENT_TEMPERATURE = "ambient_temperature";
// Sensor Boden_Temperatur
const CATEGORY_SOIL_TEMPERATURE = "soil_temperature";
// Sensor Luftfeuchtigkeit
const CATEGORY_HUMIDITY= "humidity";
// Sensor Helligkeit
const CATEGORY_LIGHT= "light";
//-----------------------------------------------------------------------------
function gardena_sensorauslesen($user, $pw)
{
$data = array(
"sessions" => array(
"email" => "$user", "password" => "$pw")
);
$data_string = json_encode($data);
$ch = curl_init(self::LOGINURL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
$data = json_decode($result);
$this -> token = $data -> sessions -> token;
$this -> user_id = $data -> sessions -> user_id;
$this -> loadLocations();
$this -> loadDevices();
}
// -----------------------------------------------------------------------------
function loadLocations()
{
$url = self::LOCATIONSURL . $this -> user_id;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:application/json',
'X-Session:' . $this -> token)
);
$this -> locations = json_decode(curl_exec($ch)) -> locations;
}
// -----------------------------------------------------------------------------
function loadDevices()
{
foreach($this->locations as $location)
{
$url = self::DEVICESURL . $location -> id;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:application/json',
'X-Session:' . $this -> token)
);
$this -> devices[$location -> id] = json_decode(curl_exec($ch)) -> devices;
}
}
// -----------------------------------------------------------------------------
/*
* Finds the first occurrence of a certain category type.
* Example: You want to find your only mower, having one or more gardens.
* @param constant $category
*/
function getFirstDeviceOfCategory($category)
{
foreach($this -> devices as $locationId => $devices)
{
foreach($devices as $device)
if ($device -> category == $category)
return $device;
}
}
// -----------------------------------------------------------------------------
function getDeviceLocation($device)
{
foreach($this -> locations as $location)
foreach($location -> devices as $d)
if ($d == $device -> id)
return $location;
}
// -----------------------------------------------------------------------------
function getInfo($device, $category_name, $proberty_name)
{
foreach ($device -> abilities as $ability)
if ($ability -> name == $category_name)
foreach($ability -> properties as $property)
if ($property -> name == $proberty_name)
return $property -> value;
}
}
?>
Wenn ich die Abfrage starte bekomme ich folgende Ausgabe:
gardena_sensor Object ( [user_id] => [token] => [locations] => [devices] => Array ( ) )
Kann mir jemand helfen, wo mein Fehler liegt?
VG Alex
Update: Fehler gefunden.
Ich habe in der Klasse folgende Zeile geändert und schon kamen die Daten:
function gardena_sensorauslesen($user, $pw)
in
function __construct($user, $pw)