Merge branch 'development'

This commit is contained in:
Salman Zafar 2019-10-29 17:39:06 +05:00
commit 794934bc62
3 changed files with 15 additions and 5 deletions

View File

@ -16,6 +16,8 @@ composer require salmanzafar/laravel-mqtt
* Certificate Protection for end to end encryption
* Enable Debug mode to make it easier for debugging
* Now you can also set Client_id of your choice and if you don't want just simply don't use or set it to null
* Set QOS flag directly from config file
* Set Retain flag directly from config file
## Enable the package (Optional)
@ -51,6 +53,8 @@ php artisan vendor:publish --provider="Salman\Mqtt\MqttServiceProvider"
'certfile' => env('mqtt_cert_file',''),
'port' => env('mqtt_port','1883'),
'debug' => env('mqtt_debug',false) //Optional Parameter to enable debugging set it to True
'qos' => env('mqtt_qos', 0), // set quality of service here
'retain' => env('mqtt_retain', 0) // it should be 0 or 1 Whether the message should be retained.- Retain Flag
```
#### Publishing topic

View File

@ -40,6 +40,8 @@ class Mqtt
protected $password = null;
protected $port = null;
protected $debug = null;
protected $qos = 0;
protected $retain = 0;
public function __construct()
{
@ -49,6 +51,8 @@ class Mqtt
$this->cert_file = config('mqtt.certfile');
$this->port = config('mqtt.port');
$this->debug = config('mqtt.debug');
$this->qos = config('mqtt.qos');
$this->retain = config('mqtt.retain');
}
@ -61,7 +65,7 @@ class Mqtt
if ($client->connect(true, null, $this->username, $this->password))
{
$client->publish($topic,$msg);
$client->publish($topic,$msg, $this->qos, $this->retain);
$client->close();
return true;
@ -81,7 +85,7 @@ class Mqtt
{
$topics[$topic] = array("qos" => 0, "function" => $proc);
$client->subscribe($topics, 0);
$client->subscribe($topics, $this->qos);
while($client->proc())
{

View File

@ -8,10 +8,12 @@
return [
'host' => env('mqtt_host','127.0.0.1'),
'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) //Optional Parameter to enable debugging set it to True
'port' => env('mqtt_port','1883'),
'debug' => env('mqtt_debug',false), //Optional Parameter to enable debugging set it to True
'qos' => env('mqtt_qos', 0), // set quality of service here
'retain' => env('mqtt_retain', 0) // it should be 0 or 1 Whether the message should be retained.- Retain Flag
];