Get the Devices List - PJanisio/ewelinkApiPhp GitHub Wiki

Devices list with deviceId

Next step after authorization is to get the list of devices connected to your account.

And most important - to know the deviceId of each device - this unique number will be used in almost all methods.

To do it, we need to initialize the Devices class and run function getDevicesList()

Example

$devices = $http->getDevices();
$devicesList = $devices->getDevicesList();
echo '<pre>';
print_r($devicesList);
echo '</pre>';

With initializing devices class - devices.json will be stored in your project folder covering all data and parameters from your all devices.

Output in browser

    [device_name1] => Array
        (
            [deviceid] => 1000xxxxx
            [productModel] => Touch EU
            [online] => 1
            [isSupportChannelSplit] => 
            [switch] => off
        )

    [device_name2] => Array
        (
            [deviceid] => 1000xxxxxx
            [productModel] => 4CH Pro
            [online] => 1
            [isSupportChannelSplit] => 1
            [switches] => Array
                (
                    [0] => Array
                        (
                            [switch] => off
                            [outlet] => 0
                        )

                    [1] => Array
                        (
                            [switch] => off
                            [outlet] => 1
                        )

                    [2] => Array
                        (
                            [switch] => off
                            [outlet] => 2
                        )

                    [3] => Array
                        (
                            [switch] => off
                            [outlet] => 3
                        )

                )

        )

Full Example

<?php
//load all classes
require_once __DIR__ . '/autoloader.php';

//initialize core classes
$httpClient = new HttpClient();
$token = $http->getToken();

    if ($token->checkAndRefreshToken()) {
        $devices = $http->getDevices();
        $devicesList= $devs->getDevicesList();

        echo '<pre>';
        print_r($devicesList);
        echo '</pre>';
    } else {

        //if we have no token, or we are not authorized paste link to authorization
        $loginUrl = $httpClient->getLoginUrl();
        echo '<a href="' . htmlspecialchars($loginUrl) . '">Authorize ewelinkApiPhp</a>';
    }    
    ?>

Next step:

With list of devices and their deviceId you can directly go to the next step:

Device Manipulation

⚠️ **GitHub.com Fallback** ⚠️