Skip to content

Commit

Permalink
make MQTT client options configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
megastef committed Sep 13, 2019
1 parent 9b72ed0 commit 186930b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions config/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,17 @@ input:
#mqtt-client:
# module: input-mqtt-client
# url: mqtt://test.mosquitto.org
# # see connect options: https://www.npmjs.com/package/mqtt#connect
# connectOptions:
# userName: nobody
# password: secret
# topics:
# - log-messages
# - sensor-data
# # optional filter settings matching data field with regular expressions
# filter:
# field: logSource
# match: .*
#
##############################################

Expand Down
8 changes: 8 additions & 0 deletions config/examples/mqtt-output.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ output:
mqtt:
module: output-mqtt
url: mqtt://test.mosquitto.org
# see https://www.npmjs.com/package/mqtt#connect
#connectOptions:
# userName: nobody
# password: secret
# keepAlive: 60
# wsOptions:
# port: 9999
# host: localhost
topic: sensor-data
debug: false
# optional filter settings matching data field with regular expressions
Expand Down
10 changes: 9 additions & 1 deletion lib/plugins/output/mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ var consoleLogger = require('../../util/logger.js')
module: mqtt
url: mqtt://127.0.0.1:1883
topic: all_events
# see https://www.npmjs.com/package/mqtt#connect options
connectOptions:
userName: nobody
password: secret
keepAlive: 60
wsOptions:
port: 9999
host: localhost
filter:
field: logSource
match: sensor.*
Expand Down Expand Up @@ -61,7 +69,7 @@ OutputMqtt.prototype.eventHandler = function (data, context) {

OutputMqtt.prototype.start = function () {
var self = this
this.client = mqtt.connect(this.config.url)
this.client = mqtt.connect(this.config.url, this.config.connectOptions || {})
this.client.on('close', function () {
if (self.config.debug) {
consoleLogger.log('mqtt client connection closed')
Expand Down

0 comments on commit 186930b

Please sign in to comment.