From 6a1915633810de017f6a080465798779fc2bc336 Mon Sep 17 00:00:00 2001 From: Ridwan Fauzan Date: Tue, 27 Nov 2018 11:34:40 +0700 Subject: [PATCH] Change config and readme for configuration mqtt --- README.md | 17 ++++++++++++++--- src/Mqtt/Mqtt.js | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c2b3d3d..34476bb 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ These are the features that I still want to developing in the near future. ## Usage ```bash -npm i --save adonis-mqtt +npm install adonis-mqtt ``` To use adonis-mqtt, add the following to your providers: @@ -52,11 +52,22 @@ Event.on('MQTT:Connected', 'Message.connected') Event.on('MQTT:Disconnected', 'Message.disconnected') ``` +Add new config file into folder config, let's say we have file `mqtt.js` then add code below. + +```js +const Env = use('Env') + +module.exports = { + url: Env.get('MQTT_URL'), + username: Env.get('MQTT_USERNAME', ''), + password: Env.get('MQTT_PASSWORD', '') +} +``` + Lastly we should add some configuration to the `.env` file so MQTT knows where and how to connect ``` -MQTT_HOST=yourmqtthost.com -MQTT_PORT=10444 +MQTT_URL=wss://yourmqtthost.com:10444/path MQTT_USERNAME=username123 MQTT_PASSWORD=password123# ``` diff --git a/src/Mqtt/Mqtt.js b/src/Mqtt/Mqtt.js index 75920f7..17624c4 100644 --- a/src/Mqtt/Mqtt.js +++ b/src/Mqtt/Mqtt.js @@ -140,7 +140,7 @@ class Mqtt { _createClient () { this.client = mqtt.connect( - `mqtt://${this.Config.get('mqtt.host')}:${this.Config.get('mqtt.port')}`, + `${this.Config.get('mqtt.url')}`, { username: this.Config.get('mqtt.username'), password: this.Config.get('mqtt.password')