How to use aws-iot-device-sdk - 10 common examples

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 phodal / designiot-code / chapter6 / aws-example / aws.js View on Github external
var awsIot = require('aws-iot-device-sdk');

var thingName = 'Led';
var thingShadows = awsIot.thingShadow({
    keyPath: 'certs/fa635d3140-private.pem.key',
    certPath: 'certs/fa635d3140-certificate.pem.crt',
    caPath: 'certs/root-CA.crt',
    clientId: thingName,
    region: 'us-west-2'
});

thingShadows.on('connect', function () {
    console.log("Connected...");
    thingShadows.register(thingName);

    // An update right away causes a timeout error, so we wait about 2 seconds
    setTimeout(function () {
        console.log("Updating Led Status...");
        var led = thingShadows.update(thingName, {
            "state": {
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 aws / aws-iot-device-sdk-js / examples / browser / temperature-monitor / index.js View on Github external
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
   IdentityPoolId: AWSConfiguration.poolId
});

//
// Keep track of whether or not we've registered the shadows used by this
// example.
//
var shadowsRegistered = false;

//
// Create the AWS IoT shadows 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 shadows = AWSIoTData.thingShadow({
   //
   // Set the AWS region we will operate in.
   //
   region: AWS.config.region,
   //
   //Set the AWS IoT Host Endpoint
   //     
   host:AWSConfiguration.host,
   //
   // Use a random client ID.
   //
   clientId: 'temperature-control-browser-' + (Math.floor((Math.random() * 100000) + 1)),
   //
   // 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?"}
  ]

aws-iot-device-sdk

AWS IoT Node.js SDK for Embedded Devices

Apache-2.0
Latest version published 6 months ago

Package Health Score

77 / 100
Full package analysis

Popular aws-iot-device-sdk functions