Skip to content

Commit

Permalink
Merge pull request #3 from strfl89/testing
Browse files Browse the repository at this point in the history
Update to Version 2.1
  • Loading branch information
strfl89 authored Sep 13, 2019
2 parents 4306727 + 26faabb commit 1cdd381
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 6 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ This project is a set of PHP Classes working with [libcoap](https://github.com/o
* Remote Controls
* Motion Sensors
* Groups
* Moods / Scenes
* Querying the status of the items
* On/Off
* Brightness
* Battery level
* Names
* Turning lights and groups on and off
* Setting their brightness
* Activating moods
* Gateway Functions
* Querying the Status informations
* Reboot
## Requirements
* IKEA Trådfri Gateway
* PHP7 (with minor adjustments older versions can also be used)
* libcoap (only supports Linux unfortunately)
## Installation
1. Install coap-client with DTLS support. Preferrably, debug output from [tinydtls](https://projects.eclipse.org/projects/iot.tinydtls) should be disabled (otherwise adjustments in the scripts are required, see inside list.php for details on this). The script [install-coap-client.sh](https://github.com/ggravlingen/pytradfri/blob/master/script/install-coap-client.sh) from the [pytradfri](https://github.com/ggravlingen/pytradfri) repository automates this.
2. Place the scripts in a web server directory accessible to web browsers. Ensure executing processes on the command line is allowed in your PHP installation.
3. Provide a configuration file with IP address of the gateway, identity and key ("username and password") to use when communicating with the gateway.
## Configuration
Configure Tradfri Gateway IP, User, Key in general.php
While creating an object in your code, you must provide the parameters for user, secretkey and IP Address
Example:
```
$groups = new tradfrigroups("<user>", "<secret>", "<ip>");
```
28 changes: 28 additions & 0 deletions Release-Notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# phpTradfri - Version History
## Version 2.1
* Add Subclass for Trådfri Gateway
* defines.php
+ defines for gateway
* general.php
* extend function action() for Gateway Class (reboot command has no payload to transmit)
* include.php
+ add gateway.php for including gateway Sublcass
* ReadMe
+ Gateway functions
* Release Notes
* create Release Notes
## Version 2.0 - 11th Sep 2019
* general.php
* Move from Constants to Parameters for Gateway Config
* to initialize new object parameters User, Secret and Gateway IP must enterd. Example:
```
$groups = new tradfrigroups("<user>", "<secret>", "<ip>");
```
* cleaning up file
* Update ReadMe File
## Version 1.1 - 09th Sep 2019
* devices
+ Output of Firmware Version at statusremotecontrol()
+ Add Motion Sensor to statusremotecontrol()
## Version 1.0 - 30th Aug 2019
* Initial Commit
5 changes: 5 additions & 0 deletions defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
define('TYPE_MOTION_SENSOR', 4); //5750 = 4 => Motion Sensor
define('GATEWAY', 15011);
define('GATEWAY_NTP', 9023);
define('GATEWAY_FIRMWARE', 9029);
define('GATEWAY_ALEXA_STATUS', 9093)
define('GATEWAY_GOOGLE_STATUS', 9105);
define('GATEWAY_TIME_UNIX', 9059);
define('GATEWAY_SETUP_TIME', 9069)

?>
28 changes: 28 additions & 0 deletions gateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

require_once('general.php');

class tradfrigateway extends tradfri
{

function reboot(){

$this->action("post", "", "15011/9030");

// Response
// v:1 t:CON c:POST i:3bb9 {} [ ]
// decrypt_verify(): found 24 bytes cleartext
// decrypt_verify(): found 4 bytes cleartext

}

function statusgateway(){

$details = $this->getDetails(GATEWAY."/15012");

$output = array('setup' => $details[GATEWAY_SETUP_TIME], 'ntp' => $details['GATEWAY_NTP'], 'time' => $details[GATEWAY_TIME_UNIX], 'firmware' => $details[GATEWAY_FIRMWARE], 'alexa' => $details[GATEWAY_ALEXA_STATUS], 'google' => $details[GATEWAY_GOOGLE_STATUS]);
}

}

?>
6 changes: 5 additions & 1 deletion general.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ function query($path){
}

function action($method, $payload, $path){
$cmd = "coap-client -m {$method} -u '{$this->gateway['user']}' -k '{$this->gateway['secretkey']}' -e '{$payload}' 'coaps://{$this->gateway['ip']}:5684/{$path}'";
if($payload != "")
$cmd = "coap-client -m {$method} -u '{$this->gateway['user']}' -k '{$this->gateway['secretkey']}' -e '{$payload}' 'coaps://{$this->gateway['ip']}:5684/{$path}'";
else
$cmd = "coap-client -m {$method} -u '{$this->gateway['user']}' -k '{$this->gateway['secretkey']}' 'coaps://{$this->gateway['ip']}:5684/{$path}'";

exec($cmd);

}
Expand Down
1 change: 1 addition & 0 deletions include.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

require_once('devices.php');
require_once('gateway.php');
require_once('groups.php');

?>

0 comments on commit 1cdd381

Please sign in to comment.