1.0.4 • Published 4 years ago

@josefransaenz/hypergate-mqtt v1.0.4

Weekly downloads
1
License
GPL-3.0
Repository
-
Last release
4 years ago

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.

ParamTypeDescription
hypergateobjectThe instance of the Hypergate class to use
baseTopicstringstring 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}'.
urlobjectMQTT broker url
optionsobjectMQTT.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');
});