PHP code example of k-ko / discovergy-oauth1

1. Go to this page and download the library: Download k-ko/discovergy-oauth1 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

k-ko / discovergy-oauth1 example snippets


use Exception;
use Discovergy\API1 as DiscovergyAPI;

try {
    $api = new DiscovergyAPI(
        // Required parameters
        $client,     // Your own application identifier
        $identifier, // Login for the Discovergy portal, mostly your email address
        $secret
    );

    // Use cache, system temp dir.
    $api->setCache(true);
    // Use your own cache dir.
    $api->setCache('/path/to/your/cache/dir');
    // If cache is used, default TTL is 1 day

    // Cache for 1 hour
    $api->setTTL(3600);

    // Authorize
    $api->init();
} catch (Exception $e) {
    die($e->getMessage());
}

$last_reading = $api->getMeter('YOUR-METER-ID')->getLastReading();

$readings = $api->getMeter('YOUR-METER-ID')->getReadings([ 'resolution' => $resolution, 'from' => $from ]);