PHP code example of summergeorge / laravel-mqttx

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

    

summergeorge / laravel-mqttx example snippets


$ composer san vendor:publish

return [
    'host'     => env('mqtt_host','127.0.0.1'),
    'password' => env('mqtt_password',''),
    'username' => env('mqtt_username',''),
    'certfile' => env('mqtt_cert_file',''),
    'port'     => env('mqtt_port','1883'),
    'debug'    => env('mqtt_debug',false),
    'qos'      => env('mqtt_qos', 0),
    'retain'   => env('mqtt_retain', 0)
];



$mqtt = new Mqttx();

// Post news to test/topic topic
$mqtt->Publish('test/topic', sprintf("mqtt message: %d", mt_rand(10,9999)));
   
   
// Subscribe to test/topic topic       
$mqtt->Subscribe('test/topic', function ($topic, $message) {
    dump($topic);
    dump($message);
});