Created
July 29, 2017 10:37
-
-
Save yoshimax/d0a1ab6eb1a6693cff390be48fc693d2 to your computer and use it in GitHub Desktop.
AWS Iot
This file contains hidden or 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
// Pub Sub On Node.js | |
var awsIot = require('aws-iot-device-sdk'); | |
var device = awsIot.device({ | |
keyPath: 'keys/XXXXX.private.key', | |
certPath: 'keys/XXXXX.cert.pem', | |
caPath: 'keys/aws-iot-rootCA.crt', | |
clientId: 'max-1', | |
host: 'AAAAA.iot.us-east-1.amazonaws.com' | |
}); | |
device | |
.on('connect', function() { | |
console.log('connect'); | |
device.subscribe('topic_1'); | |
device.publish('topic_2', JSON.stringify({ test_data: 1})); | |
}); | |
device | |
.on('message', function(topic, payload) { | |
console.log('message', topic, payload.toString()); | |
}); | |
// Test Command | |
$ mosquitto_pub --cafile aws-iot-rootCA.crt --cert XXXXX.cert.pem --key XXXXX.private.key -h AAAAA.iot.us-east-1.amazonaws.com -p 8883 -q 1 -d -t topic_1 -i client_max1 -m 'testMessage' | |
$ mosquitto_sub --cafile aws-iot-rootCA.crt --cert XXXXX.cert.pem --key XXXXX.private.key -h AAAAA.iot.us-east-1.amazonaws.com -p 8883 -q 1 -d -t topic_2 -i client_max1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment