Skip to content

Instantly share code, notes, and snippets.

@scherbenokk
Last active April 7, 2016 10:14
Show Gist options
  • Select an option

  • Save scherbenokk/9a15e5ee748c339e5c30258912aa9e65 to your computer and use it in GitHub Desktop.

Select an option

Save scherbenokk/9a15e5ee748c339e5c30258912aa9e65 to your computer and use it in GitHub Desktop.
var awsIot = require('aws-iot-device-sdk');
//
// Replace the values of '<YourUniqueClientIdentifier>' and '<YourAWSRegion>'
// with a unique client identifier and the AWS region you created your
// certificate in (e.g. 'us-east-1'). NOTE: client identifiers must be
// unique within your AWS account; if a client attempts to connect with a
// client identifier which is already in use, the existing connection will
// be terminated.
//
var device = awsIot.device({
keyPath: '/home/kirill/Documents/work_folder/promwad/amazon/certificate/privateKey.pem',
certPath: '/home/kirill/Documents/work_folder/promwad/amazon/certificate/cert.pem',
caPath: '/home/kirill/Documents/work_folder/promwad/amazon/mqtt/rootCA.pem',
clientId: 'AKIAIUNY2S2UBS6RWG3A',
region: 'us-east-1'
});
//
// Device is an instance returned by mqtt.Client(), see mqtt.js for full
// documentation.
//
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());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment