1.1.0 • Published 6 years ago

@createview/mqtt-manager v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

mqtt-manager

Npm package to configure mqtt in easy way without need for duplication code

JavaScript Style Guide License: MIT Build Status stability-experimental NSP Status

Stability

Expect the unexpected. Please provide feedback on api and your use-case

Installation

`npm install @createview/mqtt-manager

Usage

// lets make a json config file like this :

{
  "connection": "mqtt://127.0.0.1'",
  "publication": {
    "Greeting B" :  "Greeting B",
    "Bye B" :  "Bye B"
  },
  "subscription":{
    "Greeting A" : "Greeting A",
    "Bye A" :   "Bye A"
  }
}

Here is a way of using it. You can also try npm run testA and npm run testB is this order

'use strict'
const MqttManager = require('./index.js')
const mqttconfig = require('./configA')
// define the functions to trig on messages
function displayGreeting (msg, data, mqttService) {
  console.log(data)
  // can send other message
  mqttService.publish(mqttconfig.publication['Greeting B'], 'Hello B')
}

function displayBye (msg, data, mqttService) {
  console.log(data)
  // can send other message
  mqttService.publish(mqttconfig.publication['Bye B'], 'bye byeB ')
}

let actions = [

]
// add actions on subscriptions
actions.push({topic: mqttconfig.subscription['Bye A'], func: displayBye})
actions.push({topic: mqttconfig.subscription['Greeting A'], func: displayGreeting})

// create a new Mqttmanager
let mqttService = new MqttManager()

// Sett he config
mqttService.setup(mqttconfig, actions)

Tests

npm test

Comments

PS : the packages was previously named @createview/mqtt-service I am very sorry for the desagrement caused by the remove of this package from Npm. I prefered to delete it after 24 h to put a good name on it :)

The package needs improvement

Contributing

arn-the-long-beard