Skip to content

Instantly share code, notes, and snippets.

@vuongngo
Created August 22, 2017 10:55
Show Gist options
  • Save vuongngo/5b9853f794208df992708f69bfcfb11b to your computer and use it in GitHub Desktop.
Save vuongngo/5b9853f794208df992708f69bfcfb11b to your computer and use it in GitHub Desktop.
var awsIot = require('aws-iot-device-sdk');
var device = awsIot.device({
keyPath: "./private.key",
certPath: "./cert.pem",
caPath: "./root-CA.crt",
clientId: "name-of-thing",
host: "https-endpoint",
});
device
.on('connect', function() {
console.log('connect');
device.subscribe('topic');
});
device
.on('message', function(topic, payload) {
console.log('message', topic, payload.toString());
});
device
.on('error', function(e) {
console.log('error', e);
});
device
.on('close', function() {
console.log('closed');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment