How to use the azure-iot-device.ConnectionString function in azure-iot-device

To help you get started, we’ve selected a few azure-iot-device 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 Azure / iothub-diagnostics / iothubtests / iotClient.js View on Github external
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

'use strict';

const logger = require('../lib').logger;
const config = require('../config')
const iothub = require('azure-iothub');
const Message = require('azure-iot-device').Message;
const DeviceConnectionString = require('azure-iot-device').ConnectionString;
const DeviceClient = require('azure-iot-device').Client;

var runTest = function(deviceConnectionString, protocol, done) {
  var testDeviceId = DeviceConnectionString.parse(deviceConnectionString).DeviceId;
  var client = DeviceClient.fromConnectionString(deviceConnectionString, protocol);

  logger.trace('Opening the client for ' + testDeviceId);

  // Connect to the service
  client.open(function (err) {
    if (err) {
      logger.fatal('Could not connect to IOT HUB: ' + err);
      return done(err);
    } else {
      logger.debug('Client connected, sending message');
github ThingLabsIo / IoTLabs / Edison / azure-iot / iot-starter-kit.js View on Github external
// If you want to use a different protocol, comment out the protocol you want to replace, 
// and uncomment one of the other transports.
// var Protocol = require('azure-iot-device-amqp-ws').AmqpWs;
var Protocol = require('azure-iot-device-amqp').Amqp;
// var Protocol = require('azure-iot-device-http').Http;
// var Protocol = require('azure-iot-device-mqtt').Mqtt;

// The device-specific connection string to your Azure IoT Hub
var connectionString = process.env.IOTHUB_DEVICE_CONN || 'YOUR IOT HUB DEVICE-SPECIFIC CONNECTION STRING HERE';

// Create the client instanxe that will manage the connection to your IoT Hub
// The client is created in the context of an Azure IoT device.
var client = Client.fromConnectionString(connectionString, Protocol);

// Extract the Azure IoT Hub device ID from the connection string
var deviceId = device.ConnectionString.parse(connectionString).DeviceId;

// location is simply a string that you can filter on later
var location = process.env.DEVICE_LOCATION || 'GIVE A NAME TO THE LOCATION OF THE THING';

// Define the sensors you will use
var th02, lcd, led, button;

// Define some variable for holding sensor values
var tempC, tempF, humidity, r, g, b = 0;

// Define the board, which is an abstraction of the Intel Edison
var board = new five.Board({
  io: new Edison()
});
github Azure / iothub-explorer / iothub-explorer-simulate-device.js View on Github external
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

'use strict';

// Native packages
var fs = require('fs');
var path = require('path');

// External dependencies
var program = require('commander');
var prettyjson = require('prettyjson');

// Azure IoT SDK dependencies
var DeviceClient = require('azure-iot-device').Client;
var DeviceConnectionString = require('azure-iot-device').ConnectionString;
var Registry = require('azure-iothub').Registry;

// Local dependencies
var packageJson = require('./package.json');
var inputError = require('./common.js').inputError;
var printSuccess = require('./common.js').printSuccess;
var serviceError = require('./common.js').serviceError;
var printErrorAndExit = require('./common.js').printErrorAndExit;
var getSas = require('./common.js').getSas;
var getHostFromSas = require('./common.js').getHostFromSas;
var createDeviceConnectionString = require('./common.js').createDeviceConnectionString;
var createMessageFromArgument = require('./common.js').createMessageFromArgument;
var showDeprecationText = require('./common.js').showDeprecationText;

showDeprecationText('az iot device simulate');
github ThingLabsIo / IoTLabs / Azure / weather.js View on Github external
/* 
// PARTICLE PHOTON USERS
// Add the following definition for the Particle plugin for Johnny-Five
var Particle = require("particle-io");

var token = 'YOUR PARTICLE ACCESS TOKEN HERE';
*/

var location = process.env.DEVICE_LOCATION || 'GIVE A NAME TO THE LOCATION OF THE THING';
var connectionString = process.env.IOTHUB_CONN || 'YOUR IOT HUB DEVICE-SPECIFIC CONNECTION STRING HERE';

// Create an Azure IoT client that will manage the connection to your IoT Hub
// The client is created in the context of an Azure IoT device, which is why
// you use a device-specific connection string.
var client = clientFromConnectionString(connectionString);
var deviceId = device.ConnectionString.parse(connectionString).DeviceId;

// Create a Johnny-Five board instance to represent your Particle Photon
// Board is simply an abstraction of the physical hardware, whether is is a 
// Photon, Arduino, Raspberry Pi or other boards.
var board = new five.Board();
/* 
// PARTICLE PHOTON USERS
// When creating a Board instance for the Photon you must specify the token and device ID
// for your Photon using the Particle-IO Plugin for Johnny-five.
// Replace the Board instantiation with the following:
var board = new five.Board({
  io: new Particle({
    token: token,
    deviceId: 'YOUR PARTICLE PHOTON DEVICE IS OR ALIAS'
  })
});
github Azure-Samples / iot-hub-node-intel-edison-getstartedkit / remote_monitoring / remote_monitoring.js View on Github external
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

'use strict';

// Azure IoT packages
var Protocol = require('azure-iot-device-http').Http;
var Client = require('azure-iot-device').Client;
var ConnectionString = require('azure-iot-device').ConnectionString;
var Message = require('azure-iot-device').Message;

// Edison packages
var five = require("johnny-five");
var Edison = require("edison-io");
var board = new five.Board({
  io: new Edison()
});

var hostName        = '';
var deviceId        = '';
var sharedAccessKey = '';

// String containing Hostname, Device Id & Device Key in the following formats:
//  "HostName=;DeviceId=;SharedAccessKey="
var connectionString = 'HostName=' + hostName + ';DeviceId=' + deviceId + ';SharedAccessKey=' + sharedAccessKey;
github ThingLabsIo / IoTLabs / Azure / simulator.js View on Github external
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
'use strict';
var device = require('azure-iot-device');

// Use the DeviceExplorer or IotHub-Exploror tools to create a device and get its connection string.
var connectionString = process.env.IOTHUB_CONN || 'YOUR IOT HUB DEVICE-SPECIFIC CONNECTION STRING HERE';

// Create an Azure IoT client that will manage the connection to your IoT Hub
// The client is created in the context of an Azure IoT device, which is why
// you use a device-specific connection string.
var client = device.Client.fromConnectionString(connectionString);
var deviceId = device.ConnectionString.parse(connectionString).DeviceId;

// For this simulation, create an Array of five simulated devices
var sensors = new Array();
createSimulatedSensors();

// Use setInterval to send the data from each of the five simulated device
// in 10-second intervals (i.e. five device messages every 10 seconds,
// which is 30 messages per minute, or 43,200 messages per day).
// This is simulating five independent devices sending messages.
// An alternative would be to collect the data from five devices
// in a field gateway and aggregate the data into a single message.
// This would reduce the message count.
setInterval(function(){
  // Set up valiables used for the simulation
  var sensor;
  // Iterate through each of the five devices to gather the device data
github Azure / azure-iot-sdk-node / device / samples / remote_monitoring.js View on Github external
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

'use strict';

var Protocol = require('azure-iot-device-mqtt').Mqtt;
var Client = require('azure-iot-device').Client;
var ConnectionString = require('azure-iot-device').ConnectionString;
var Message = require('azure-iot-device').Message;

// String containing Hostname, Device Id & Device Key in the following formats:
//  "HostName=;DeviceId=;SharedAccessKey="
var deviceConnectionString = process.env.DEVICE_CONNECTION_STRING;
var deviceId = ConnectionString.parse(connectionString).DeviceId;

// Sensors data
var temperature = 50;
var humidity = 50;
var externalTemperature = 55;

// Create IoT Hub client
var client = Client.fromConnectionString(deviceConnectionString, Protocol);

// Helper function to print results for an operation
github Azure-Samples / iot-hub-c-thingdev-getstartedkit / command_center_node / server.js View on Github external
'use strict';

var express = require('express');
var bodyParser = require('body-parser');

var ServiceClient = require('azure-iothub').Client;
var Message = require('azure-iot-common').Message;
var EventHubClient = require('azure-event-hubs').Client;
var DeviceConnectionString = require('azure-iot-device').ConnectionString;
var azure = require('azure-storage');
var nconf = require('nconf');

nconf.argv().env().file('./config.json');
var eventHubName = nconf.get('eventHubName');
var ehConnString = nconf.get('ehConnString');
var deviceConnString = nconf.get('deviceConnString');
var storageAcountName = nconf.get('storageAcountName');
var storageAccountKey = nconf.get('storageAccountKey');
var storageTable = nconf.get('storageTable');
var iotHubConnString = nconf.get('iotHubConnString');

var deviceId = DeviceConnectionString.parse(deviceConnString).DeviceId;
var iotHubClient = ServiceClient.fromConnectionString(iotHubConnString);

// event hub alerts
github Azure-Samples / iot-hub-node-intel-edison-getstartedkit / command_center / command_center.js View on Github external
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

'use strict';

// Azure IoT packages
var Protocol = require('azure-iot-device-amqp').Amqp;
// Uncomment one of these transports and then change it in fromConnectionString to test other transports
// var Protocol = require('azure-iot-device-amqp-ws').AmqpWs;
// var Protocol = require('azure-iot-device-http').Http;
// var Protocol = require('azure-iot-device-mqtt').Mqtt;
var Client = require('azure-iot-device').Client;
var Message = require('azure-iot-device').Message;
var ConnectionString = require('azure-iot-device').ConnectionString;

// Edison packages
var five = require("johnny-five");
var Edison = require("edison-io");
var board = new five.Board({
  io: new Edison()
});

var hostName = '';
var deviceId = '';
var sharedAccessKey = '';

// String containing Hostname, Device Id & Device Key in the following formats:
//  "HostName=;DeviceId=;SharedAccessKey="
var connectionString = 'HostName=' + hostName + ';DeviceId=' + deviceId + ';SharedAccessKey=' + sharedAccessKey;