@josefransaenz/hypergate-aws-mqtt
v1.0.4
Published
hypergate-aws-mqtt is built on top of [aws-iot-device-sdk](https://www.npmjs.com/package/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.
Downloads
2
Readme
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.
| 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 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}'. | | AWSMqttOptions | object | AWSIoT-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');
});