https://github.com/denherrring/laravel-mqtt-client
A simple Laravel 5 Library / Client to connect/publish to MQTT broker
https://github.com/denherrring/laravel-mqtt-client
laravel laravel-mqtt laravel-mqtt-client laravel-mqtt-library laravel5 mqtt-laravel mqtt-laravel-publisher mqtt-laravel-subscriber
Last synced: about 2 months ago
JSON representation
A simple Laravel 5 Library / Client to connect/publish to MQTT broker
- Host: GitHub
- URL: https://github.com/denherrring/laravel-mqtt-client
- Owner: DenHerrRing
- Created: 2019-05-13T09:59:39.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-14T15:27:27.000Z (about 7 years ago)
- Last Synced: 2025-02-10T17:44:15.910Z (over 1 year ago)
- Topics: laravel, laravel-mqtt, laravel-mqtt-client, laravel-mqtt-library, laravel5, mqtt-laravel, mqtt-laravel-publisher, mqtt-laravel-subscriber
- Language: PHP
- Homepage: https://packagist.org/packages/denherrring/laravel-mqtt-client
- Size: 18.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Laravel MQTT Client Package
A simple Laravel 5 Library / Client to connect/publish to MQTT broker
Based on [bluerhinos/phpMQTT](https://github.com/bluerhinos/phpMQTT)
## Installation
```
composer require denherrring/laravel-mqtt-client
```
## Features
* Name and Password Authentication
* Certificate Protection for end to end encryption
* Enable Debug mode to make it easier for debugging
* Use LWT Messages and Retrain / QOS Flags
## Enable the package (Optional)
This package implements Laravel auto-discovery feature. After you install it the package provider and facade are added automatically for laravel >= 5.5.
__This step is only required if you are using laravel version <5.5__
To declare the provider and/or alias explicitly, then add the service provider to your config/app.php:
```
'providers' => [
DenHerrRing\MqttClient\MqttClientServiceProvider::class,
];
```
And then add the alias to your config/app.php:
```
'aliases' => [
'MqttClient' => DenHerrRing\MqttClient\Facades\MqttClient::class,
];
```
## Configuration
Publish the configuration file
```
php artisan vendor:publish --provider="DenHerrRing\MqttClient\MqttClientServiceProvider"
```
## Config/mqttclient.php
```
'host' => env('mqtt_host','127.0.0.1'),
'clientId' => env('mqtt_clientId', null),
'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
```
#### Publishing topic
```
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;
}
```
#### Publishing topic using Facade
```
use MqttClient;
public function SendMsgViaMqtt($topic, $message)
{
$output = MqttClient::ConnectAndPublish($topic, $message);
if ($output === true)
{
return true;
}
return false;
}
```
### Tested on php 7.3 and laravel 5.7 and also laravel 5.8
## Subscription Part is in development