From f0d9c1d5c7700a3deebc2c7e7021ee0cd9c93202 Mon Sep 17 00:00:00 2001 From: Bubelbub Date: Sat, 29 Mar 2014 17:22:19 +0100 Subject: [PATCH] Added configuration file for the session of SmartHome --- example.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/example.php b/example.php index ee83995..66119cf 100644 --- a/example.php +++ b/example.php @@ -18,10 +18,31 @@ require_once 'Request/GetAllPhysicalDeviceStatesRequest.php'; require_once 'Request/GetMessageListRequest.php'; -$newLine = php_sapi_name() == 'cli' ? "\n" : '
'; +use \Bubelbub\SmartHomePHP\Request\SetActuatorStatesRequest; + +$newLine = php_sapi_name() == 'cli' ? PHP_EOL : '
'; + +$config = new SimpleXMLElement(''); +$configFile = __FILE__ . '.config'; +if(file_exists($configFile)) +{ + try{$config = new SimpleXMLElement($configFile, 0, true);}catch(Exception $ex){} +} $sh = new \Bubelbub\SmartHomePHP\SmartHome('Hostname or IP address', 'Username', 'Password'); +if(!file_exists($configFile)) +{ + $config->addChild('SessionId', $sh->getSessionId()); + $config->addChild('Version', $sh->getVersion()); + $config->addChild('ConfigurationVersion', $sh->getConfigVersion()); + $config->saveXML($configFile); +} + +$sh->setSessionId((string) $config->SessionId); +$sh->setVersion((string) $config->Version); +$sh->setConfigVersion((string) $config->ConfigurationVersion); + // get your current session id echo 'Your session id is ' . $sh->getSessionId() . $newLine;