@josefransaenz/hypergate-mqtt

1.0.4 • Public • Published

hypergate-mqtt

hypergate-mqtt is built on top of MQTT.js and can be used to connect a hypergate instance to a MQTT broker.

API Reference

HypergateMqtt

Kind: global class

new HypergateMqtt(hypergate, baseTopic, url, options)

An instance of the HypergateMqtt class is a mqtt.js Client instance.

Param Type Description
hypergate object The instance of the Hypergate class to use
baseTopic string string that will be appended to the topics related to the hypergate instance. The instance of the HypergateMqtt class will be subscribed to topic 'baseTopic/command/#' and will redirect the related messages to the hypergate.command method. All hypergate events will be automatically published as 'baseTopic/event/{original_hypergate_event}'.
url object MQTT broker url
options object MQTT.js options

Example

const Hypergate = require('@josefransaenz/hypergate-core'); 
const HypergateMqtt = require('@josefransaenz/hypergate-mqtt');

const hypergate = new Hypergate(<YourPluginsSpecification>);

const baseTopic = <YourBaseTopicString>;

const mqttClient = new HypergateMqtt(hypergate, baseTopic, 'mqtt://test.mosquitto.org'); 

mqttClient.on('message', function (topic, message) {
  console.log(`*** Topic: '${topic}',  Payload: ${message.toString()}`);
});

mqttClient.on('connect', function () {
  console.log('*** Connect');
});

mqttClient.on('close', () => {
  console.log('** Disconect');
});

Readme

Keywords

none

Package Sidebar

Install

npm i @josefransaenz/hypergate-mqtt

Weekly Downloads

0

Version

1.0.4

License

GPL-3.0

Unpacked Size

43 kB

Total Files

6

Last publish

Collaborators

  • josefransaenz