All Projects → salmanzafar949 → Mqtt Laravel

salmanzafar949 / Mqtt Laravel

A simple Laravel Library to connect/publish/subscribe to MQTT broker

Projects that are alternatives of or similar to Mqtt Laravel

Laravel Mqtt Publish
A laravel mqtt publisher
Stars: ✭ 24 (-72.73%)
Mutual labels:  laravel, mqtt
Poetryclub Backend
基于 laravel + vue.js 的诗词小筑网站后台页面与后端代码
Stars: ✭ 87 (-1.14%)
Mutual labels:  laravel
N2o
⭕ N2O: Distributed Application Server
Stars: ✭ 1,262 (+1334.09%)
Mutual labels:  mqtt
Laravel Spark Google2fa
Google Authenticator support for Laravel Spark
Stars: ✭ 86 (-2.27%)
Mutual labels:  laravel
Rating
rating system for laravel 5
Stars: ✭ 85 (-3.41%)
Mutual labels:  laravel
Mqtt
MQTT Client class
Stars: ✭ 86 (-2.27%)
Mutual labels:  mqtt
Circleci Demo Php Laravel
Example CircleCI project using PHP and Laravel
Stars: ✭ 85 (-3.41%)
Mutual labels:  laravel
Warehouse
Artesãos Warehouse - A simple and direct approach to repositories!
Stars: ✭ 87 (-1.14%)
Mutual labels:  laravel
Netxms
NetXMS - Open Source network and infrastructure monitoring and management
Stars: ✭ 88 (+0%)
Mutual labels:  mqtt
Laravel 5 Myblog
The php blog writed by laravel5.1
Stars: ✭ 86 (-2.27%)
Mutual labels:  laravel
Laravel Api Starter
laravel5.5 + dingo/api + JWT
Stars: ✭ 85 (-3.41%)
Mutual labels:  laravel
Docker Laravel
Laravel 5 with Dockerized Gulp, PHP-FPM, MySQL and nginx using docker-compose
Stars: ✭ 85 (-3.41%)
Mutual labels:  laravel
Laravel Woocommerce
WooCommerce Rest API for Laravel
Stars: ✭ 86 (-2.27%)
Mutual labels:  laravel
Teslamate
A self-hosted data logger for your Tesla 🚘
Stars: ✭ 1,255 (+1326.14%)
Mutual labels:  mqtt
Background Template For Laravel5
专门为Laravel5整理的后台模板,只写了路由的页面跳转,给开发者最大的空间自己开发.
Stars: ✭ 87 (-1.14%)
Mutual labels:  laravel
Laravel Fb Messenger
Laravel Facebook Messenger Provider
Stars: ✭ 85 (-3.41%)
Mutual labels:  laravel
Dingtalk Exception
Laravel/Lumen exception notify through DingTalk
Stars: ✭ 86 (-2.27%)
Mutual labels:  laravel
Zipcode
Zip code searcher
Stars: ✭ 86 (-2.27%)
Mutual labels:  laravel
Laravel Enum
Simple, extensible and powerful enumeration implementation for Laravel.
Stars: ✭ 1,278 (+1352.27%)
Mutual labels:  laravel
Laravel Facebook Ads
Facebook & Instagram Ads API for Laravel
Stars: ✭ 87 (-1.14%)
Mutual labels:  laravel

Laravel MQTT Package

A simple Laravel Library to connect/publish/subscribe to MQTT broker

Based on bluerhinos/phpMQTT

For Example see this repo

Installation

composer require salmanzafar/laravel-mqtt

Features

  • Name and password authentication
  • Client certificate authentication
  • 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
  • Addition of Helper functions to make development more easy

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' => [

        Salman\Mqtt\MqttServiceProvider::class,
];

And then add the alias to your config/app.php:

'aliases' => [

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

Configuration

Publish the configuration file

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

Config/mqtt.php

    'host'      => env('mqtt_host','127.0.0.1'),
    'password'  => env('mqtt_password',''),
    'username'  => env('mqtt_username',''),
    'certfile'  => env('mqtt_cert_file',''),
    'localcert' => env('mqtt_local_cert', ''),
    'localpk'   => env('mqtt_local_pk', ''),
    '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

use Salman\Mqtt\MqttClass\Mqtt;

public function SendMsgViaMqtt($topic, $message)
{
        $mqtt = new Mqtt();
        $client_id = Auth::user()->id;
        $output = $mqtt->ConnectAndPublish($topic, $message, $client_id);

        if ($output === true)
        {
            return "published";
        }
        
        return "Failed";
}

Publishing topic using Facade

use Mqtt;

public function SendMsgViaMqtt($topic, $message)
{
        $client_id = Auth::user()->id;
        
        $output = Mqtt::ConnectAndPublish($topic, $message, $client_id);

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

        return "Failed";
}

Subscribing topic

use Salman\Mqtt\MqttClass\Mqtt;

public function SubscribetoTopic($topic)
    {
        $mqtt = new Mqtt();
        $client_id = Auth::user()->id;
        $mqtt->ConnectAndSubscribe($topic, function($topic, $msg){
            echo "Msg Received: \n";
            echo "Topic: {$topic}\n\n";
            echo "\t$msg\n\n";
        }, $client_id);


    }

Subscribing topic using Facade

use Mqtt;

public function SubscribetoTopic($topic)
    {
       //You can also subscribe to multiple topics using the same function $topic can be array of topics e.g ['topic1', 'topic2']

       Mqtt::ConnectAndSubscribe($topic, function($topic, $msg){
            echo "Msg Received: \n";
            echo "Topic: {$topic}\n\n";
            echo "\t$msg\n\n";
        },$client_id);


    }

Publishing topic using Helper method


public function SendMsgViaMqtt($topic, $message)
{
        $client_id = Auth::user()->id;
        
        $output = connectToPublish($topic, $message, $client_id);

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

        return "Failed";
}

Subscribing topic using Helper method

//You can also subscribe to multiple topics using the same function $topic can be array of topics e.g ['topic1', 'topic2']
public function SubscribetoTopic($topic)
{
  return connectToSubscribe($topic,$client_id);
}

Happy Coding...!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].