<?php
class fb_soap
{
private $ip;
private $user;
private $password;
public function __construct($password = false, $ip = 'fritz.box', $user = 'dslf-config') {
$this->ip = $ip;
$this->user = $user;
$this->password = $password;
}
public function getSOAPclient() {
$client = new \SoapClient(
null,
array(
'location' => "http://".$this->ip.":49000/upnp/control/x_homeauto",
'uri' => "urn:dslforum-org:service:X_AVM-DE_Homeauto:1",
'noroot' => true,
'login' => $this->user,
'password' => $this->password,
'trace' => true,
'exceptions' => true
)
);
return $client;
}
public function getGenericDeviceInfos ($id) {
$client = $this->getSoapClient();
$result = $client->GetGenericDeviceInfos (new \SoapParam($id,"NewIndex"));
return $result;
}
public function setSwitch ($ain, $state = "TOGGLE") { // optional parameters are: OFF, ON, TOGGLE, UNDEFINED
$client = $this->getSoapClient();
$client->SetSwitch (new \SoapParam($ain,"NewAIN"), new \SoapParam($state,"NewSwitchState"));
}
}
$switch = new fb_soap ('PASSWORT');
$result = $switch->getGenericDeviceInfos (1);
PHP_EOL;
echo "Generic Device Infos:" . PHP_EOL;
print_r ($result) . PHP_EOL;
$switch->setSwitch ($result['NewAIN']);
$result = $switch->getGenericDeviceInfos (1);
PHP_EOL;
echo 'Schaltstatus für ' . $result['NewDeviceName'] . ' ist: ' . $result['NewSwitchState'] . PHP_EOL;
?>