PHP code example of denherrring / laravel-mqtt-client

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

    

denherrring / laravel-mqtt-client example snippets


'aliases' => [

       'MqttClient' => DenHerrRing\MqttClient\Facades\MqttClient::class,
];

php artisan vendor:publish --provider="DenHerrRing\MqttClient\MqttClientServiceProvider"

use DenHerrRing\MqttClient\MqttClientClass\MqttClient;

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

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

        return false;
}

use MqttClient;

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

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

        return false;
}