PHP code example of rohsyl / salto

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

    

rohsyl / salto example snippets


$client = new SaltoClient('5.tcp.eu.ngrok.io', 14072);

$client->openSocketConnection();

while (!$client->isReady()) {
    // wait some seconds and try again
    // or exit program
}

$response = $client->sendMessage($message);

$message = (new CheckInMobileMessage())
    ->forRoom('W10011')
    ->phone('+41774539943')
    ->from(Carbon::create(2022, 12, 21, 10, 30))
    ->to(Carbon::create(2022, 12, 30, 10, 30))
    ;

$message = (new CheckInMobileMessage())
    // ...
    ->by('Firstname Lastname')
    ;

$message = (new CheckInMobileMessage())
    // ...
    ->withMessage('Lorem impsum')
    ;

$message = (new CheckInMobileMessage())
    // ...
    ->withAuthorizations(['1' => true])
    ;

$message = (new ModifyMessage())
    ->fromRoom('W10011')
    ->expireAt(Carbon::create(2022, 12, 12, 11,0));

$message = (new CheckoutMessage(+))
    ->forRoom('W10011');

$response = $client->sendMessage($message);

$response->toString();
$response->getRequest()->toString();

try {

}
catch(SaltoException $e) {
    if($e instanceof ConnectionFailedException) {
        // ...
    }
    else if($e instanceof NakException) {
        // ...
    }
    else if($e instanceof WrongChecksumException) {
        // ...
    }
    else if($e instanceof SaltoErrorException) {
        // ...
    }
}