From 11c681b9cfca114cf274289c7a4ed619f9c14ce6 Mon Sep 17 00:00:00 2001 From: Florian Strunk Date: Wed, 11 Sep 2019 09:44:28 +0200 Subject: [PATCH 1/4] Move Konstants to Variables in Constructor Gateway Data has no longer set in general.php and must be set when creating the object --- .gitignore | 2 ++ general.php | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 .gitignore 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..3d1035f 100644 --- a/general.php +++ b/general.php @@ -6,16 +6,19 @@ class tradfri { - //IP Address of Trådfri Gateway - const TRADFRIIP = ''; - //API User Trådfri Gateway - const USER = ''; - //API Key for User - const SECRETKEY = ''; + privat $gateway; + + function __construct($user, $secret, $gwip){ + + $gateway['user'] = $user; + $gateway['secretkey'] = $secret; + $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 '{$gateway['user']}' -k '{$gateway['secretkey']}' 'coaps://{$gateway['ip']}:5684/{$path}'"; $process = proc_open($cmd, [STDOUT => ['pipe', 'w'], STDERR => ['pipe', 'w']], $output); //read the outputs @@ -36,7 +39,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 '{$gateway['user']}' -k '{$gateway['secretkey']}' -e '{$payload}' 'coaps://{$gateway['ip']}:5684/{$path}'"; exec($cmd); } From 517bb61fd52721e1af2d74beebc8196087d0240e Mon Sep 17 00:00:00 2001 From: Florian Strunk Date: Wed, 11 Sep 2019 09:46:32 +0200 Subject: [PATCH 2/4] Update general.php --- general.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/general.php b/general.php index 3d1035f..e05aa0b 100644 --- a/general.php +++ b/general.php @@ -10,9 +10,9 @@ class tradfri function __construct($user, $secret, $gwip){ - $gateway['user'] = $user; - $gateway['secretkey'] = $secret; - $gateway['ip'] = $gwip; + $this->gateway['user'] = $user; + $this->gateway['secretkey'] = $secret; + $this->gateway['ip'] = $gwip; } From e91da76418b22e6a4ba131622c1257618fb05ce7 Mon Sep 17 00:00:00 2001 From: Florian Strunk Date: Wed, 11 Sep 2019 10:07:18 +0200 Subject: [PATCH 3/4] Bugfixing general.php --- general.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/general.php b/general.php index e05aa0b..5d71d6e 100644 --- a/general.php +++ b/general.php @@ -1,12 +1,12 @@ 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 @@ -39,7 +39,7 @@ function query($path){ } function action($method, $payload, $path){ - $cmd = "coap-client -m {$method} -u '{$gateway['user']}' -k '{$gateway['secretkey']}' -e '{$payload}' 'coaps://{$gateway['ip']}: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); } From 80c6576ee3cd38a944a9cc533376d2c904d8fd76 Mon Sep 17 00:00:00 2001 From: Florian Strunk Date: Wed, 11 Sep 2019 10:20:31 +0200 Subject: [PATCH 4/4] Clean Up general.php --- general.php | 1 - 1 file changed, 1 deletion(-) diff --git a/general.php b/general.php index 5d71d6e..7982b1e 100644 --- a/general.php +++ b/general.php @@ -1,6 +1,5 @@