diff --git a/README.md b/README.md
index ccc5edd..2d555b4 100644
--- a/README.md
+++ b/README.md
@@ -6,41 +6,68 @@ It`s PHP class to authorize, get and set data for Nibe devices using [Nibe myUpl
### What is needed?
-- PHP version 7.4+ (with lib php-curl)
-- Account and application created on [myUplink](https://dev.myuplink.com/login)
+- [x] PHP version 7.4+ (with lib php-curl - should be installed by default)
+- [x] Account and application created on [myUplink](https://dev.myuplink.com/login)
### What is not needed?
-- any other dependencies nor composers or packages
+- [ ] any other dependencies nor composers or packages
### What is a goal of this project? And can I contribute?
-Goal is to have easy, non dependent class which will be cron ready to fetch all heat-pump data into json and in case of premium subscription - also set some parameters. And of course everyone can contribute to this repo.
+Goal is to have *easy, non dependent* class which will be cron ready to fetch all heat-pump data into json and in case of premium subscription - also set some parameters. And of course everyone can contribute to this repo.
-### Example
+---
-Current state: class can authorize, refresh authorization token and save ALL device parameters to jSON. See [example output](https://pastebin.pl/view/raw/dbd66f2e)
+### Installation steps
+
+1. Visit [**MyUplink**](https://myuplink.com/register) and sign up for a user account.
+2. Go to [**Applications**](https://dev.myuplink.com/apps), and register a new App
+3. Download released version and paste it into your web directory
+4. Open **config.php** and fill below settings as written in comments:
```php
-/*
-That is an index and an example at once. Can be used in a browser, or as an event file like cronjob.
-*/
+'clientID' => 'xxxxxxxxx', //from dev.myuplink.com
+'clientSecret' => 'xxxxxxxxxxx', //from dev.myuplink.com
+'redirectUri' => 'https://xxxxx/myuplink/', // from dev.myuplink.com - your absolute path where index.php is stored
+'jsonOutPath' => '/xxxx/xxxx/myuplink/json/', //your absolute path when you will store json files as well as token.json
-//include autoloader for classes
-include('src/autoloader.php');
+```
+
+* redirectUri is a web directory on which you pasted **myuplink class** - please make sure it is the same web URL as you saved in your Myuplink app.
+
+5. Save config.php and open browser with **redirectUri** address. And see example below.
+## Example
+
+Below example is exactly the content of **index.php**
+**Outcome**: will fetch all possible data and save into jSON (location in config.php -> 'jsonOutPath')
+
+```php
+//include autoloader for classes
+include(__DIR__.'/src/autoloader.php');
//start main class and fetch config
-$nibe = new myuplink('config.php'); //best practise - use absolute path
+$nibe = new myuplink(__DIR__.'/config.php');
-
//authorization, getting token and its status
if($nibe->authorizeAPI() == TRUE)
-
{
//if authorized switching to class which get data
$nibeGet = new myuplinkGet($nibe);
-
//get all parameters from device and save to jSON
- $nibeGet->getDevicePoints();
+ $nibeGet->getAll();
}
+
+```
+
+If you doesn`t want to get all data everytime, look at **/src/myuplinkGet.php** for single methods.
+For methods description you can look at [**API documentation**](https://api.myuplink.com/swagger/index.html).
+
+---
+
+### Short roadmap
+
+- [x] v.1.0.0 - Class can authorize and get all data from Nibe device
+- [ ] v.1.x.x - Additional class with parsing all jSon to strings to have easy access to every Nibe variable
+- [ ] v.2.x.x - Class can change the parameters (f.e run water heating on demand)
diff --git a/config.php b/config.php
index 1f6bbb2..402be15 100644
--- a/config.php
+++ b/config.php
@@ -7,11 +7,11 @@
[
'clientID' => 'xxxxxx', //from dev.myuplink.com
'clientSecret' => 'xxxxxxx', //from dev.myuplink.com
- 'redirectUri' => 'https://xxxxxxxx', //your absolute path where index.php is stored
- 'jsonOutPath' => '/www/xxxxxxxx/json/', //your absolute path when you will store json files
+ 'redirectUri' => 'https://xxxxxxxx', // from dev.myuplink.com - your absolute path where index.php is stored
+ 'jsonOutPath' => '/www/xxxxxxxx/json/', //your absolute path when you will store json files as well as token.json
'scope' => 'READSYSTEM WRITESYSTEM offline_access', //dont change
'curl_http_version' => '\CURL_HTTP_VERSION_1_1', //dont change
- 'debug' => TRUE //TRUE = dump of information of received data
+ 'debug' => FALSE //TRUE = var_dump of inputs and outputs, set to TRUE if your app is not working
];
@@ -34,7 +34,7 @@
'all-alerts' => '/v2/systems/{systemId}/notifications',
'all-alerts' => '/v2/systems/{systemId}/notifications',
'ping' => '/v2/ping', //success when HTTPCODE == 204
- 'premium' => '/v2/systems/{systemId}/substrciptions'
+ 'premium' => '/v2/systems/{systemId}/subscriptions' //will return 204 if subscription is not available
];
?>
\ No newline at end of file
diff --git a/index.php b/index.php
index 5fd980b..18cc148 100644
--- a/index.php
+++ b/index.php
@@ -1,7 +1,7 @@
authorizeAPI() == TRUE)
-
{
//if authorized switching to class which get data
$nibeGet = new myuplinkGet($nibe);
//get all parameters from device and save to jSON
- $nibeGet->getDevice();
+ $nibeGet->getAll();
}
diff --git a/src/myuplink.php b/src/myuplink.php
index 4b03025..a3c580e 100644
--- a/src/myuplink.php
+++ b/src/myuplink.php
@@ -1,7 +1,7 @@
tokenExpiry() == 'Token expired') {
//expired
- if ($this->config['debug'] == TRUE) {
- echo 'DEBUG: Token have expired. Refreshing token...';
- }
+ $this->msg('Token have expired. Refreshing token...');
//clear old token
$this->clearToken();
@@ -344,7 +342,7 @@ public function checkTokenStatus()
if ($this->refreshToken() == TRUE) {
if ($this->config['debug'] == TRUE) {
- echo 'DEBUG: Token have been refreshed!';
+ $this->msg('Token succesfully refreshed!');
}
$this->tokenStatus = json_decode(file_get_contents($this->config['jsonOutPath'].'token.json'), TRUE);
@@ -403,10 +401,10 @@ public function getData(string $endpoint, int $successHTTP = 200, int $save = 1)
//we didnt received answer
if (curl_error($c) != NULL)
{
- $this->msg('Error resolving answer: ' . curl_error($c));
+ $this->msg('Error resolving answer from GET [' . $endpoint . ']: ' . curl_error($c));
$this->redirectMe($this->config['redirectUri'], 3);
} else {
- $this->msg('Error resolving answer: '.curl_getinfo($c, CURLINFO_HTTP_CODE). $c_answer);
+ $this->msg('Empty answer from GET [' . $endpoint . ']: '.curl_getinfo($c, CURLINFO_HTTP_CODE). $c_answer);
if (isset($c)) {
curl_close($c);
diff --git a/src/myuplinkGet.php b/src/myuplinkGet.php
index a572ce0..a99fa51 100644
--- a/src/myuplinkGet.php
+++ b/src/myuplinkGet.php
@@ -1,7 +1,7 @@
systemInfo['serialNumber'] = strval($this->system['systems'][0]['devices'][0]['product']['serialNumber']);
$this->systemInfo['deviceName'] = strval($this->system['systems'][0]['devices'][0]['product']['name']); //device name
+ //show landing page
+ $this->landingPage();
+
$this->myuplink->debugMsg('DEBUG: Nibe Systems: ', $this->systemInfo);
- //rewrite endpoints and take values from this function
- $this->newEndpoints();
+ //rewrite endpoints and take values from this function
+ $this->newEndpoints();
return $this->systemInfo;
+ }
+
+ /*
+ Internal function to display connection status
+ returns string
+ */
+ protected function landingPage()
+
+ {
+ $this->myuplink->msg('Hi, '.$this->systemInfo['name'].'
+ Your SystemId: '.$this->systemInfo['systemId'].'
+ Your DeviceId: '.$this->systemInfo['deviceId'].'
+ Your Device S/N: '.$this->systemInfo['serialNumber'].'
+ You firmware version: '.$this->systemInfo['currentFwVersion'].'
+ Myuplink class version: '.constant('myuplink::VERSION').'
+ ');
+
+
}
/*
@@ -147,7 +173,7 @@ public function getDevicePoints()
/*
Get additional heater status
save to json
- returns int 1?0 as an object
+ returns object of array
*/
public function getAidMode()
@@ -165,7 +191,7 @@ public function getAidMode()
/*
Get device status
save to json
- returns int 1?0 as an object
+ returns object of array
*/
public function getDevice()
@@ -182,13 +208,13 @@ public function getDevice()
/*
Get smart home categories
save to json
- returns int 1?0 as an object
+ returns object of array
*/
public function getSmartHomeCat()
{
//send request to API
- $this->device = $this->myuplink->getData($this->newEndpoints['smart-home-cat']);
+ $this->smartHomeCat = $this->myuplink->getData($this->newEndpoints['smart-home-cat']);
//return object
return $this->smartHomeCat;
@@ -198,13 +224,13 @@ public function getSmartHomeCat()
/*
Get smart-home-zones
save to json
- returns int 1?0 as an object
+ returns object of array
*/
public function getSmartHomeZones()
{
//send request to API
- $this->device = $this->myuplink->getData($this->newEndpoints['smart-home-zones']);
+ $this->smartHomeZones = $this->myuplink->getData($this->newEndpoints['smart-home-zones']);
//return object
return $this->smartHomeZones;
@@ -215,19 +241,115 @@ public function getSmartHomeZones()
/*
Get smart-home-mode
save to json
- returns int 1?0 as an object
+ returns object of array
*/
public function getSmartHomeMode()
{
//send request to API
- $this->device = $this->myuplink->getData($this->newEndpoints['smart-home-mode']);
+ $this->smartHomeMode = $this->myuplink->getData($this->newEndpoints['smart-home-mode']);
//return object
return $this->smartHomeMode;
}
+
+ /*
+ Get actual and newest firmware
+ save to json
+ returns object of array
+ */
+ public function getFirmware()
+
+ {
+ //send request to API
+ $this->firmware = $this->myuplink->getData($this->newEndpoints['firmware']);
+ //return object
+ return $this->firmware;
+
+
+ }
+
+ /*
+ Get active alerts from device
+ save to json
+ returns object of array with active alerts
+ */
+ public function getActiveAlerts()
+
+ {
+ //send request to API
+ $this->activeAlerts = $this->myuplink->getData($this->newEndpoints['active-alerts']);
+ //return object
+ return $this->activeAlerts;
+
+
+ }
+
+
+ /*
+ Get all alerts from device
+ save to json
+ returns object of array of all historical alerts (only first page)
+ */
+ public function getAllAlerts()
+
+ {
+ //send request to API
+ $this->allAlerts = $this->myuplink->getData($this->newEndpoints['all-alerts']);
+ //return object
+ return $this->allAlerts;
+
+
+ }
+
+ /*
+ Get information about premium subscription
+ save to json
+ returns either 204 == no subscription
+ returns expire time if valid subscription
+ */
+ public function getPremium()
+
+ {
+ //send request to API
+ $this->premium = $this->myuplink->getData($this->newEndpoints['premium']);
+ //return object
+ return $this->premium;
+
+
+ }
+
+
+ /*
+ Get all data which can be get :) all methods together
+ save to json
+ returns array of all parameters and save to /json
+ */
+ public function getAll()
+
+ {
+ //send requests to API
+ $this->all[] = $this->pingAPI();
+ $this->all[] = $this->getDevicePoints();
+ $this->all[] = $this->getDevice();
+ $this->all[] = $this->getSmartHomeMode();
+ $this->all[] = $this->getSmartHomeCat();
+ $this->all[] = $this->getSmartHomeZones();
+ $this->all[] = $this->getFirmware();
+ $this->all[] = $this->getActiveAlerts();
+ $this->all[] = $this->getAllAlerts();
+ $this->all[] = $this->getPremium();
+
+ //return object
+ return $this->all;
+
+
+ }
+
+
+
} //end of class