1.0.2 • Published 5 months ago
bajo-mqtt v1.0.2
bajo-mqtt
Plugin name: bajoMqtt, alias: mqtt
Attention: I do NOT accept any pull request at the moment, thanks!
MQTT binding for Bajo. If Bajo Emitter is loaded, events & messages are also handled through Bajo Emitter processing system.
Installation
Goto your <bajo-base-dir>
and type:
$ npm install bajo-mqtt
Now open your <bajo-data-dir>/config/.plugins
and put bajo-mqtt
in it
. Order doesn't matter here, but you should put it below bajo-emitter
:
...
bajo-emitter
bajo-mqtt
...
Configuration
Open/create <bajo-data-dir>/config/bajoMqtt.json
:
Key | Type | Required | Default | Description |
---|---|---|---|---|
connections | array | no | [] | Define one or more connections to your MQTT Broker |
name | string | no | default | Connection name, must be unique among all your connections |
url | string | yes | Url to your MQTT Broker, e.g: mqtt://localhost | |
broadcast | boolean | no | false | Incoming messages are broadcastable by bajoEmitter |
options | object | no | Connection options, see github.com/mqttjs/MQTT.js | |
subscriptions | array | no | [] | Define one or more subscriptions within your connections |
name | string | no | default | Subscription name, must be unique among all your subscription |
connection | string | yes | Connection name, must be one of defined connections above | |
topic | string | yes | MQTT topic to subscribe into |
Example:
{
"connections": [{
"name": "local",
"url": "mqtt://localhost",
"broadcast": true
}, {
"name": "remote",
"url": "mqtt://remotebroker.domain.com",
"options": {
"username": "guest",
"password": "SuperSecret"
}
}],
"subscriptions": [{
"name": "sensor",
"connection": "local",
"topic": "sensor/data/#"
}]
}
Hook
bajoMqtt:onClose (conn)
bajoMqtt:onConnect (conn)
bajoMqtt:onDisconnect (conn)
bajoMqtt:onEnd (conn)
bajoMqtt:onError (conn, error)
bajoMqtt:onMessage (conn, topic, message)
bajoMqtt:onOffline (conn)
bajoMqtt:onReconnect (conn)