Socket
Book a DemoInstallSign in
Socket

mqtt-smarthome-connect

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mqtt-smarthome-connect

Node library for MQTT-Smarthome

0.0.8
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

node-mqtt-smarthome

mqtt-smarthome NPM version Build Status Coverage Status XO code style License

Node module for MQTT-Smarthome

This Module is a wrapper around MQTT.js adding extra functionality to ease the handling of topics and payloads following the mqtt-smarthome architecture proposal.

Usage

$ npm install mqtt-smarthome-connect --save

const mqsh = require('mqtt-smarthome-connect');
mqsh.connect();
mqsh.subscribe('test/1', (topic, val) => {
    console.log(val); // foo
});
mqsh.publish('test/1', 'foo');

API

Classes

MqttSmarthome

Typedefs

messageCallback : function

MqttSmarthome

Kind: global class

new MqttSmarthome([mqttUrl], [options])

Params

  • [mqttUrl] string = "mqtt://localhost"
  • [options] object - see all available options in the MQTT.js docs

mqttSmarthome.sub : MqttSmarthome.subscribe

Just a convenience alias to subscribe

Kind: instance property of MqttSmarthome

mqttSmarthome.pub : MqttSmarthome.publish

Just a convenience alias to publish

Kind: instance property of MqttSmarthome

mqttSmarthome.connect()

Kind: instance method of MqttSmarthome

mqttSmarthome.end([force], [callback])

Disconnect from the MQTT broker.

Kind: instance method of MqttSmarthome
Params

  • [force] boolean = false - passing it to true will close the client right away, without waiting for the in-flight messages to be acked.
  • [callback] function - will be called when the client is closed.

mqttSmarthome.reconnect()

Reconnect to the MQTT broker.

Kind: instance method of MqttSmarthome

mqttSmarthome.subscribe(topic, [callback]) ⇒ idSubscription

Kind: instance method of MqttSmarthome
Returns: idSubscription - id
Params

mqttSmarthome.unregisterCallback(id) ⇒ number

Unregister a callback. If no registered callback on the corresponding topic is left a MQTT unsubscribe will be done.

Kind: instance method of MqttSmarthome
Returns: number - remaining number of subscription on that topic
Params

  • id idSubscription - an id that was returned by the subscribe() method.

mqttSmarthome.unsubscribe(topic, [callback])

Unsubscribe a whole topic with all its callbacks.

Kind: instance method of MqttSmarthome
Params

  • topic string
  • [callback] function

mqttSmarthome.publish(topic, payload, [options], [callback])

Publish a MQTT message. Payloads that are neither of type string nor an instance of Buffer will be JSON stringified.

Kind: instance method of MqttSmarthome
Params

  • topic string
  • payload *
  • [options] object
    • [.qos] number = 0 - QoS level
    • [.retain] boolean = false - Retain Flag
    • [.dup] boolean = false - Mark as duplicate flag
  • [callback] function - Fired when the QoS handling completes, or at the next tick if QoS 0. An error occurs if client is disconnecting.

"connect"

Kind: event emitted by MqttSmarthome

"close"

Kind: event emitted by MqttSmarthome

"error"

Kind: event emitted by MqttSmarthome

"offline"

Kind: event emitted by MqttSmarthome

"reconnect"

Kind: event emitted by MqttSmarthome

"message" (topic, payload, packet,)

Kind: event emitted by MqttSmarthome
Params

messageCallback : function

Kind: global typedef
Params

  • topic string
  • payload string | number | boolean | object
  • [wildcardMatch] array - If subscription was example/+/foo/bar this array contains the "+" in topic string
  • packet Mqtt.packet

License

MIT © Simon Christmann and Contributors

FAQs

Package last updated on 15 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.