PHP code example of bowens-h / laravel-mqtt

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

    

bowens-h / laravel-mqtt example snippets


'aliases' => [

       'Mqtt' => \Bowens\Mqtt\Facades\Mqtt::class,
];

php artisan vendor:publish --provider="Bowens\Mqtt\MqttServiceProvider"

use Bowens\Mqtt\MqttClass\Mqtt;

public function SendMsgViaMqtt($topic, $message)
{
        $mqtt = new Mqtt();
        $output = $mqtt->ConnectAndPublish($topic, $message);

        if ($output === true)
        {
            return true;
        }

        return false;
}

use Mqtt;

public function SendMsgViaMqtt($topic, $message)
{
        $output = Mqtt::ConnectAndPublish($topic, $message);

        if ($output === true)
        {
            return true;
        }

        return false;
}