Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
- first release
- changed debug to FALSE as default
- fixed typo in premium endpoint :)
- fixed debug info in myuplink class
- created simple landing page
- added endpoints: getActiveAlerts, getAllAlerts, getFirmware, getPremium and getAll
- added overwriting endpoints in __construct of myuplinkGet class
  • Loading branch information
PJanisio committed May 26, 2024
1 parent 3264531 commit 92e5b35
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 44 deletions.
59 changes: 43 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
```

<sub>* 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.</sub>

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)
8 changes: 4 additions & 4 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
];


Expand All @@ -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
];

?>
5 changes: 2 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
myuplinkphp - class to connect and fetch data from Nibe heat pump
Version: 0.16.12
Version: 1.0.0
Author: Pawel 'Pavlus' Janisio
License: GPL v3
github: https://github.com/PJanisio/myuplinkapi
Expand All @@ -22,12 +22,11 @@

//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->getDevice();
$nibeGet->getAll();
}


Expand Down
14 changes: 6 additions & 8 deletions src/myuplink.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
myuplinkphp - class to connect and fetch data from Nibe heat pump
Version: 0.16.12
Version: 1.0.0
Author: Pawel 'Pavlus' Janisio
License: GPL v3
github: https://github.com/PJanisio/myuplinkapi
Expand All @@ -14,7 +14,7 @@ class myuplink
{

//define main variables
const VERSION = '0.16.12';
const VERSION = '1.0.0';

public $config = array();
private $authorized = FALSE;
Expand Down Expand Up @@ -333,9 +333,7 @@ public function checkTokenStatus()
//lets check if our token didnt expired
else if ($this->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();
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 92e5b35

Please sign in to comment.