apanicker/hekr-cloud-api-client

HEKR IOT API Client for PHP

v1.0.1 2020-06-15 16:18 UTC

This package is auto-updated.

Last update: 2024-05-19 23:57:46 UTC


README

A simple PHP API Client for HEKR IoT Cloud.

use Hekr\User;
use Hekr\Device;
use Hekr\Client;

//Initialize the client
$client = new Client();

//Setup user value object
$user = new User('user@test.com', 'password');

//Generate Access Token for the user
$auth = $client->auth($user);

//Fetch all IoT devices associated with the user account
$response = $client->setAccessToken($auth['access_token'])->getAllDevices();

$devices = $response['data'];

//Set up the device value object
$device = new Device(
    $devices[0]['ctrlKey'], 
    $devices[0]['devTid'], 
    $devices[0]['productPublicKey']
);

//Fetch latest device snapshot
$snapshot = $client->setAccessToken($this->accessToken)
                ->setDevice($device)
                ->getDeviceSnapshot();

Installation

With Composer

composer require apanicker/hekr-cloud-api-client
{
    "require": {
        "apanicker/hekr-cloud-api-client": "^1.0.0"
    }
}

Testing

In order to use the test suite, make sure you update your hekr username and password in tests/ClientTest.php

$ phpunit
PHPUnit 8.5.5 by Sebastian Bergmann and contributors.

....                                                                4 / 4 (100%)

Time: 14.95 seconds, Memory: 6.00 MB

OK (4 tests, 8 assertions)