-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
It is first example. It will get you all data without getting deep into the class methods (but it can be time consuming (2-20 seconds) depending on your machine and authorization validity).
//include autoloader for classes
include(__DIR__.'/src/autoloader.php');
//start main class and fetch config
$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 possible endpoints, put to array and save to jSON
$data = $nibeGet->getAll();
}Return of this example will be data saved to json files in json dir which you specyfied in the config.php
In addition this function will also return an array if you doesnt want to work with json.
Let`s assume you want to get your current firmware version, so lets add one line to make it easier:
//get all possible endpoints, put to array and save to jSON
$data = $nibeGet->getALL();
echo $data['firmware']['currentFwVersion'];
But how do you know how to get value from $data? See below:
Change this variable to TRUE inside config.php
'debug' => TRUE //TRUE = var_dump of inputs and outputs, set to TRUE if your app is not workingAfter this you will get the json output that can be accessed, for our example it will be displayed like this:
DEBUG [READ]: MyUplink.com answer:object(stdClass)#21 (5) {
["deviceId"]=>
string(45) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
["firmwareId"]=>
string(6) "nibe-n"
["currentFwVersion"]=>
string(6) "2.27.5"
["pendingFwVersion"]=>
string(6) "3.0.10"
["desiredFwVersion"]=>
string(6) "3.0.10"
}And you can use var_dump function which is a game changer in php :)
So the syntax in the index file should look like this:
//get all possible endpoints, put to array and save to jSON
$data = $nibeGet->getALL();
var_dump($data['firmware']);And output:
array(5) {
["deviceId"]=> string(45) "xxx"
["firmwareId"]=> string(6) "nibe-n"
["currentFwVersion"]=> string(6) "2.27.5"
["pendingFwVersion"]=> string(6) "3.0.10"
["desiredFwVersion"]=> string(6) "3.0.10"
}Available var_dump arguments are equal enpoint names in config.php:
'system'
'devicePoints'
'aidMode'
'device'
'smart-home-cat'
'smart-home-zones'
'smart-home-mode'
'firmware'
'active-alerts'
'all-alerts'
'ping'
'premium'-----myuplinkapi - last release-----