1.0.4 • Published 4 years ago

@josefransaenz/hypergate-aws-mqtt v1.0.4

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

hypergate-aws-mqtt

hypergate-aws-mqtt is built on top of aws-iot-device-sdk and can be used to connect a hypergate instance to the AWS IoT Platform via MQTT or MQTT over the Secure WebSocket Protocol.

API Reference

HypergateAWSMqtt

Kind: global class

new HypergateAWSMqtt(hypergate, baseTopic, AWSMqttOptions)

An instance of the HypergateAWSMqtt class is a mqtt.js Client instance created by using the aws-iot-device-sdk library.

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 HypergateAWSMqtt 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}'.
AWSMqttOptionsobjectAWSIoT-specific arguments as specified in the aws-iot-device-sdk documentation

Example

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

const hypergate = new Hypergate(<YourPluginsSpecification>);

const AWSMqttOptions = {
  keyPath: <YourPrivateKeyPath>,
  certPath: <YourCertificatePath>,
  caPath: <YourRootCACertificatePath>,
  clientId: <YourUniqueClientIdentifier>,
  host: <YourCustomEndpoint>
};
const baseTopic = <YourBaseTopicString>;

const mqttClient = new HypergateAWSMqtt(hypergate, baseTopic, AWSMqttOptions); 

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');
});