PHP code example of xtend / smart-relay-sdk

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

    

xtend / smart-relay-sdk example snippets


$host = '192.168.100.18';
$port = 50000;
$smartRelay = new \Xtend\Device\SmartRelay($host, $port);
try {
    $smartRelay->open();                                   // open connection to socket
    var_dump($smartRelay->isConnect());                    // check device status
    var_dump($smartRelay->push(3, SmartRelay::PIN_ON));    // turn on 3rd pin
    var_dump($smartRelay->push(3, SmartRelay::PIN_OFF));   // turn off 3rd pin
    $smartRelay->close();                                  // close cocket connection
} catch (\RuntimeException $e) {
    echo $e->getMessage();
}