Created
August 22, 2017 10:55
-
-
Save vuongngo/5b9853f794208df992708f69bfcfb11b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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