diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f0be71f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.cfg +*config*.php diff --git a/general.php b/general.php index 07a7e9e..7982b1e 100644 --- a/general.php +++ b/general.php @@ -1,21 +1,23 @@ '; - //API User Trådfri Gateway - const USER = ''; - //API Key for User - const SECRETKEY = ''; + private $gateway; + + function __construct($user, $secret, $gwip){ + + $this->gateway['user'] = $user; + $this->gateway['secretkey'] = $secret; + $this->gateway['ip'] = $gwip; + + } function query($path){ - $cmd = "coap-client -m get -u '".self::USER."' -k '".self::SECRETKEY."' 'coaps://".self::TRADFRIIP.":5684/$path'"; + $cmd = "coap-client -m get -u '{$this->gateway['user']}' -k '{$this->gateway['secretkey']}' 'coaps://{$this->gateway['ip']}:5684/{$path}'"; $process = proc_open($cmd, [STDOUT => ['pipe', 'w'], STDERR => ['pipe', 'w']], $output); //read the outputs @@ -36,7 +38,7 @@ function query($path){ } function action($method, $payload, $path){ - $cmd = "coap-client -m {$method} -u '".self::USER."' -k '".self::SECRETKEY."' -e '{$payload}' 'coaps://".self::TRADFRIIP.":5684/$path'"; + $cmd = "coap-client -m {$method} -u '{$this->gateway['user']}' -k '{$this->gateway['secretkey']}' -e '{$payload}' 'coaps://{$this->gateway['ip']}:5684/{$path}'"; exec($cmd); }