bowens-h/laravel-mqtt 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bowens-h/laravel-mqtt

Composer 安装命令:

composer require bowens-h/laravel-mqtt

包简介

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

README 文档

README

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

Based on bluerhinos/phpMQTT

Installation

composer require bowens-h/laravel-mqtt

Features

  • Name and Password Authentication
  • Certificate Protection for end to end encryption
  • Enable Debug mode to make it easier for debugging

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

        Bowens\Mqtt\MqttServiceProvider::class,
];

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

'aliases' => [

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

Configuration

Publish the configuration file

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

Config/mqtt.php

    'host'     => env('mqtt_host','127.0.0.1'),
    'password' => env('mqtt_password',''),
    'client_id'=> env('mqtt_client_id',''),
    '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 Bowens\Mqtt\MqttClass\Mqtt;

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

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

        return false;
}

Publishing topic using Facade

use Mqtt;

public function SendMsgViaMqtt($topic, $message)
{
        $output = Mqtt::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

统计信息

  • 总下载量: 73
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 34
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固