PHP code example of azurre / php-broadlink

1. Go to this page and download the library: Download azurre/php-broadlink 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/ */

    

azurre / php-broadlink example snippets


$loader = e>';
$devices = \Azurre\Component\SmartDevice\Broadlink\Transport::discover();
print_r($devices);

$loader = e>';
$device = new \Azurre\Component\SmartDevice\Broadlink\Device\SP3S;
$response = $device
    ->setHost('192.168.0.190')
    ->setMac('17:5e:be:34:ec:14')
    ->auth();

print_r($response);
$storage->saveAuthData('mydevice', $response); // Save auth data

$loader = e>';
$device = new \Azurre\Component\SmartDevice\Broadlink\Device\SP3S;
list($id, $key, $time) = $storage->getAuthData('mydevice'); // Get auth data
$device
    ->setHost('192.168.0.190')
    ->setMac('17:5e:be:34:ec:14')
if (time() - $time >= \Azurre\Component\SmartDevice\Broadlink\Transport::AUTH_KEY_EXPIRE) {
    $device->auth();
    // Save auth data
} else {
    // Authorize using saved credentials
    $device->auth($id, $key);
}
print_r( $device->getPowerState() );

$loader = e>';
$device = new \Azurre\Component\SmartDevice\Broadlink\Device\SP3S;
list($id, $key, $time) = $storage->getAuthData('mydevice'); // Get auth data
$device
    ->setHost('192.168.0.190')
    ->setMac('17:5e:be:34:ec:14')
if (time() - $time >= \Azurre\Component\SmartDevice\Broadlink\Transport::AUTH_KEY_EXPIRE) {
    $device->auth();
    // Save auth data
} else {
    // Authorize using saved credentials
    $device->auth($id, $key);
}
var_dump( $device->getCurrentPower() )

$loader = e>';
$device = new \Azurre\Component\SmartDevice\Broadlink\Device\SP3S;
list($id, $key, $time) = $storage->getAuthData('mydevice'); // Get auth data
$device
    ->setHost('192.168.0.190')
    ->setMac('17:5e:be:34:ec:14')
if (time() - $time >= \Azurre\Component\SmartDevice\Broadlink\Transport::AUTH_KEY_EXPIRE) {
    $device->auth();
    // Save auth data
} else {
    // Authorize using saved credentials
    $device->auth($id, $key);
}
$turnOn = true;
$device->setPowerState($turnOn);