PHPackages                             iisustudio/laravel-mqtt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. iisustudio/laravel-mqtt

ActiveLibrary[HTTP &amp; Networking](/categories/http)

iisustudio/laravel-mqtt
=======================

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

v2.0.10(4y ago)04.6kMITPHPPHP ^7.0 || ^7.1 || ^7.2 || ^7.3 || ^7.4 || ^8.0

Since Jun 11Pushed 4y agoCompare

[ Source](https://github.com/iisuStudio/MQTT-Laravel)[ Packagist](https://packagist.org/packages/iisustudio/laravel-mqtt)[ Fund](https://www.buymeacoffee.com/salmanzafar949)[ Patreon](https://www.patreon.com/salmanzafar949)[ RSS](/packages/iisustudio-laravel-mqtt/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (24)Used By (0)

Laravel MQTT Package
====================

[](#laravel-mqtt-package)

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

Based on [bluerhinos/phpMQTT](https://github.com/bluerhinos/phpMQTT)

For Example see this [repo](https://github.com/salmanzafar949/Laravel-Mqtt-Example)

Installation
------------

[](#installation)

```
composer require salmanzafar/laravel-mqtt

```

Features
--------

[](#features)

- Name and pawd 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)
-----------------------------

[](#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 &gt;= 5.5.

**This step is only required if you are using laravel version &lt;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
-------------

[](#configuration)

Publish the configuration file

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

```

Config/mqtt.php
---------------

[](#configmqttphp)

```
    'host'      => env('mqtt_host','127.0.0.1'),
    'pawd'      => env('mqtt_pawd',''),
    '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

[](#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

[](#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

[](#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

[](#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

[](#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

[](#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...!
----------------

[](#happy-coding)

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 76.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~45 days

Recently: every ~60 days

Total

21

Last Release

1626d ago

Major Versions

v1.0.9 → v2.0.02020-09-20

PHP version history (6 changes)v1.0.0PHP &gt;=5.4.0

v1.0.4PHP &gt;=7.4.0

v1.0.5PHP &gt;=7

v1.0.6PHP &gt;=7.3

v2.0.3PHP ^7.0 || ^7.1 || ^7.2 || ^7.3 || ^7.4

v2.0.4PHP ^7.0 || ^7.1 || ^7.2 || ^7.3 || ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/f3052eaba8564c2b5139409cfbdee85f0806bb4006e9bb702a73edc678f94881?d=identicon)[iisu](/maintainers/iisu)

---

Top Contributors

[![salmanzafar40](https://avatars.githubusercontent.com/u/29972877?v=4)](https://github.com/salmanzafar40 "salmanzafar40 (69 commits)")[![salmanzafar949](https://avatars.githubusercontent.com/u/29015432?v=4)](https://github.com/salmanzafar949 "salmanzafar949 (13 commits)")[![iisuStudio](https://avatars.githubusercontent.com/u/12378431?v=4)](https://github.com/iisuStudio "iisuStudio (5 commits)")[![Casdak7](https://avatars.githubusercontent.com/u/33229620?v=4)](https://github.com/Casdak7 "Casdak7 (1 commits)")[![TMogdans](https://avatars.githubusercontent.com/u/19358139?v=4)](https://github.com/TMogdans "TMogdans (1 commits)")[![wilianx7](https://avatars.githubusercontent.com/u/42422976?v=4)](https://github.com/wilianx7 "wilianx7 (1 commits)")

---

Tags

phplaravellaravel 6laravel 7laravel 8laravel 5laravel5php-8laravel6laravel8laravel7php-7.4PHP 5.4php 7.0php 7.1php 7.2php 7.3mqtt-laravelmqtt-laravel-publishermqtt-laravel-subscriberlaravel mqtt librarylaravel-mqtt

### Embed Badge

![Health badge](/badges/iisustudio-laravel-mqtt/health.svg)

```
[![Health](https://phpackages.com/badges/iisustudio-laravel-mqtt/health.svg)](https://phpackages.com/packages/iisustudio-laravel-mqtt)
```

###  Alternatives

[salmanzafar/laravel-mqtt

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

106153.1k1](/packages/salmanzafar-laravel-mqtt)[salmanzafar/laravel-geocode

A Laravel Library to find Lat and Long of a given Specific Address

153.9k](/packages/salmanzafar-laravel-geocode)[victorybiz/geoip-location

Get the geographical location of website visitors based on their IP addresses. Support Laravel and PHP (Non-Laravel) Project.

22157.9k2](/packages/victorybiz-geoip-location)[alexstack/laravel-cms

Simple Bootstrap Laravel CMS. Can integrate to any existing Laravel project. Only add few database tables with prefix, not effect your existing database tables. Support Laravel 8.x &amp; 7.x &amp; Laravel 6.x &amp; Laravel 5.x - Amila Laravel CMS

1084.3k5](/packages/alexstack-laravel-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
