How to use the aws-iot-device-sdk.device function in aws-iot-device-sdk

To help you get started, we’ve selected a few aws-iot-device-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hjespers / teslams / examples / streaming.js View on Github external
process.exit();
}
if (argv.db) {
    MongoClient = require('mongodb').MongoClient;
    // TODO: maybe add a mongouri config paramter to the config.json so people can set this explicitly
    var mongoUri = process.env.MONGOLAB_URI|| process.env.MONGOHQ_URI || 'mongodb://127.0.0.1:27017/' + argv.db;

    MongoClient.connect(mongoUri, function(err, db) {
        if(err) throw err;
	dbo=db.db(argv.db);
        collectionS = dbo.collection('tesla_stream');
        collectionA = dbo.collection('tesla_aux');
    });
} 
if (argv.awsiot) {
    var device = awsIot.device({
        keyPath: creds.awsiot.keyPath,    //path to your AWS Private Key
        certPath: creds.awsiot.certPath,  //path to your AWS Public Key
        caPath: creds.awsiot.caPath,      //path tp your AWS Root Certificate
        clientId: creds.awsiot.clientId,  //Your AWS IoT Client ID
        region: creds.awsiot.region       //The AWS region in whcih your IoT account is registered
    });
    if (!argv.topic) {
        console.log('No AWS IOT topic specified. Using teslams/{id} where {id} is the vehicle id of the car');
        argv.topic = 'teslams';
    }
    //
    // Device is an instance returned by mqtt.Client(), see mqtt.js for full
    // documentation.
    //
    device.on('connect', function() {
        ulog('awsiot device connected!');
github mapbox / asset-tracking / src / IoTHarness / init.js View on Github external
const awsIot = require("aws-iot-device-sdk");
const turf = require("@turf/along").default;
const route = require("./route.json");

const device = awsIot.device({
  keyPath: "./harness-private.pem.key",
  certPath: "./harness-certificate.pem.crt",
  caPath: "./AmazonRootCA1.pem",
  clientId: "testing",
  host: "$$INSERT$$"
});

device.on("connect", () => {
  console.log("connected");
  runTest();
  // * Uncomment this out to subscribe
  // * Then uncomment the message event handler below
  // device.subscribe("assetingest");
});

device.on("reconnect", () => {
github Superjo149 / auryo / src / main / aws / awsIotService.ts View on Github external
constructor(getKeysResponse: GetKeysResponse) {
		this.device = new awsIot.device({
			region: getKeysResponse.region,
			protocol: "wss",
			// debug: true,
			clientId: getKeysResponse.identityId,
			accessKeyId: getKeysResponse.accessKeyId,
			secretKey: getKeysResponse.secretAccessKey,
			sessionToken: getKeysResponse.sessionToken,
			port: 443,
			host: getKeysResponse.iotEndpoint
		});

		if (getKeysResponse) {
			this.identityId = getKeysResponse.identityId || "";
		}

		this.device.on("error", err => {
github aws / aws-iot-device-sdk-js / examples / browser / mqtt-explorer / index.js View on Github external
//
// Initialize our configuration.
//
AWS.config.region = AWSConfiguration.region;

AWS.config.credentials = new AWS.CognitoIdentityCredentials({
   IdentityPoolId: AWSConfiguration.poolId
});

//
// Create the AWS IoT device object.  Note that the credentials must be 
// initialized with empty strings; when we successfully authenticate to
// the Cognito Identity Pool, the credentials will be dynamically updated.
//
const mqttClient = AWSIoTData.device({
   //
   // Set the AWS region we will operate in.
   //
   region: AWS.config.region,
   //
   ////Set the AWS IoT Host Endpoint
   host:AWSConfiguration.host,
   //
   // Use the clientId created earlier.
   //
   clientId: clientId,
   //
   // Connect via secure WebSocket
   //
   protocol: 'wss',
   //
github aws / aws-iot-device-sdk-js / examples / browser / lifecycle / index.js View on Github external
//
// Initialize our configuration.
//
AWS.config.region = AWSConfiguration.region;

AWS.config.credentials = new AWS.CognitoIdentityCredentials({
   IdentityPoolId: AWSConfiguration.poolId
});

//
// Create the AWS IoT device object.  Note that the credentials must be 
// initialized with empty strings; when we successfully authenticate to
// the Cognito Identity Pool, the credentials will be dynamically updated.
//
const mqttClient = AWSIoTData.device({
   //
   // Set the AWS region we will operate in.
   //
   region: AWS.config.region,
   //
   // Set the AWS IoT Host Endpoint
   // //
   host:AWSConfiguration.host,
   //
   // Use the clientId created earlier.
   //
   clientId: clientId,
   //
   // Connect via secure WebSocket
   //
   protocol: 'wss',
github joanaz / MirrorMirrorOnTheWallSkill / src / MirrorMirror.js View on Github external
app.setup = function() {
  app.device = awsIot.device({
    keyPath: __dirname + "/certs/MagicMirror.private.key",
    certPath: __dirname + "/certs/MagicMirror.cert.pem",
    caPath: __dirname + "/certs/root-CA.crt",
    clientId: "MirrorMirror" + (new Date().getTime()),
    region: "us-east-1",
    host: "YOURID.iot.us-east-1.amazonaws.com",
  });

  app.device.on('connect', function() {
    console.log('connect');
  });

  app.device.on('message', function(topic, payload) {
    console.log('message', topic, payload.toString());
  });
}
github joanaz / MMM-MirrorMirrorOnTheWall / MirrorMirror.js View on Github external
app.setup = function() {
  app.device = awsIot.device({
    keyPath: __dirname + "/certs/MagicMirror.private.key",
    certPath: __dirname + "/certs/MagicMirror.cert.pem",
    caPath: __dirname + "/certs/root-CA.crt",
    clientId: "MagicMirror" + (new Date().getTime()),
    region: "us-east-1",
    host: "YOURID.iot.us-east-1.amazonaws.com",
  });

  /**
   * AWS IoT - Connecting MagicMirror as a device to our AWS IoT topics
   */
  console.log("Attempt to connect to AWS ");
  app.device.on("connect", function() {
    console.log("Connected to AWS IoT");

    app.device.subscribe(app.TOPIC_TEXT);
github awslabs / simplebeerservice / device / sbs-simulator.js View on Github external
**************************/

var awsIot = require("aws-iot-device-sdk");
var config = require("./device.json");
const commandLineArgs = require('command-line-args');

const optionDefinitions = [
  { name: 'verbose', alias: 'v', type: Boolean, defaultValue: false },
  { name: 'region', alias: 'r', type: String, defaultValue: config.region },
  { name: 'unitid', alias: 'u', type: String, defaultValue: config.deviceId }
];
const options = commandLineArgs(optionDefinitions);

var data = [];
try {
  var device = awsIot.device({
    keyPath: "cert/private.pem.key",
    certPath: "cert/certificate.pem.crt",
    caPath: "cert/root.pem.crt",
    clientId: options.unitid,
    region: options.region
  });

  var topic = "test/"+options.unitid;

  var messages = [
    {"line1":"I :heart: beer!","line2":"How about you?"},
    {"line1":"Step right up...","line2":"and grab a beer!"},
    {"line1":"What a beautiful","line2":"day for a beer!"},
    {"line1":"HEY! YOU!","line2":"Want a beer?"}
  ]
github cuongquay / node-red-contrib-aws-iot / aws-iot.js View on Github external
var caPath = path.join(awsCerts, '/root-CA.crt');
				self.log("Using the certificates that are presented as follows:");
				self.log(" - keyPath   : " + keyPath);
				self.log(" - certPath  : " + certPath);
				self.log(" - caPath    : " + caPath);
				if (n.mode == "shadow") {
					self.device = require('aws-iot-device-sdk').thingShadow({
						keyPath : keyPath,
						certPath : certPath,
						caPath : caPath,
						clientId : clientId,
						host : self.endpoint,
						protocol: 'mqtts'
					});
				} else {
					self.device = require('aws-iot-device-sdk').device({
						keyPath : keyPath,
						certPath : certPath,
						caPath : caPath,
						clientId : clientId,
						host : self.endpoint,
						protocol: 'mqtts'
					});
				}
				if (self.device) {
					self.device.on('connect', function() {
						callback('connected');
					});
					self.device.on('reconnect', function() {
						callback('reconnected');
					});
					self.device.on('error', function(error) {
github ioBroker / ioBroker.iot / main.js View on Github external
.then(key => {
            adapter.log.debug(`URL key is ${JSON.stringify(key)}, clientId: ${clientId}`);

            connectStarted = Date.now();
            device = new DeviceModule({
                privateKey: new Buffer(certs.private),
                clientCert: new Buffer(certs.certificate),
                caCert:     fs.readFileSync(__dirname + '/keys/root-CA.crt'),
                clientId,
                username:   'ioBroker',
                host:       adapter.config.cloudUrl,
                debug:      !!adapter.config.debug,
                baseReconnectTimeMs: 5000,
                keepalive:  60
            });

            device.subscribe('command/' + clientId + '/#');
            device.on('connect', onConnect);
            device.on('close', onDisconnect);
            device.on('reconnect', () => adapter.log.debug('reconnect'));
            device.on('offline', () => adapter.log.debug('offline'));

aws-iot-device-sdk

AWS IoT Node.js SDK for Embedded Devices

Apache-2.0
Latest version published 4 months ago

Package Health Score

75 / 100
Full package analysis

Popular aws-iot-device-sdk functions