Skip to content

Commit

Permalink
Merge pull request #2 from strfl89/testing
Browse files Browse the repository at this point in the history
Move from Constants to parameters in constructor for Trådfri Gateway Config
  • Loading branch information
strfl89 authored Sep 11, 2019
2 parents e98282e + 80c6576 commit 4306727
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.cfg
*config*.php
22 changes: 12 additions & 10 deletions general.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<?php

//require_once('ikea-smart-home.config.php');
require_once('define.php');
require_once('defines.php');

class tradfri
{

//IP Address of Trådfri Gateway
const TRADFRIIP = '<IP-Address>';
//API User Trådfri Gateway
const USER = '<User>';
//API Key for User
const SECRETKEY = '<Key>';
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
Expand All @@ -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);

}
Expand Down

0 comments on commit 4306727

Please sign in to comment.