PHP code example of thephpguys / broadlink

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

    

thephpguys / broadlink example snippets


use TPG\Broadlink\Device\AbstractDevice;
use TPG\Broadlink\Device\HasTemperatureSensorInterface;
use TPG\Broadlink\Device\RMDevice;

$devices = AbstractDevice::discover();
$response=[];
foreach ($devices as $device){
    
    $device->authenticate();
    
    $deviceResponse = [
        'model' => $device->getModel(),
        'name' => $device->getName(),
        'ip' => $device->getIP(),
        'mac' => $device->getMac(),
    ];
    
    if($device instanceof HasTemperatureSensorInterface){
        $deviceResponse['temperature'] = sprintf("%01.1f",$device->getTemperature());
    }
    
    $response[] = $deviceResponse;
}

echo json_encode($response);

use TPG\Broadlink\Device\RMDevice;

$device = new RMDevice('192.168.88.15','34:ea:cc:cc:cc:bc');
$device->authenticate();
echo $device->getTemperature();

use TPG\Broadlink\Cloud\Catalog;

$catalog = new Catalog('/path/where/you/want/to/save/remotes');
$remotes = $catalog->search('Samsung');

//Download first remote
print_r($remotes[0]->download());

//Or download all found remotes
foreach($remotes as $remote){
    $remote->download();
}