How to use azure-iot-provisioning-device-mqtt - 5 common examples

To help you get started, we’ve selected a few azure-iot-provisioning-device-mqtt 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 / azure-iot-sdk-node / digitaltwins / samples / iot_central_device / sample_device.js View on Github external
async function main() {
  const provisioningClient = ProvisioningDeviceClient.create(
    provisioningEndpoint,
    idScope,
    new ProvisioningTransport(),
    new SymmetricKeySecurityClient(registrationId, symmetricKey)
  );

  // IoT Central requires a special payload to be sent when the device is provisioned
  provisioningClient.setProvisioningPayload({
    '__iot:interfaces': {
      CapabilityModelId: capabilityModel
    }
  });

  const registrationResult = await provisioningClient.register();
  const deviceConnectionString = `HostName=${registrationResult.assignedHub};DeviceId=${registrationResult.deviceId};SharedAccessKey=${symmetricKey}`;

  const propertyUpdateHandler = (interfaceInstance, propertyName, reportedValue, desiredValue, version) => {
    console.log('Received an update for ' + propertyName + ': ' + JSON.stringify(desiredValue));
    interfaceInstance[propertyName].report(desiredValue, {
github Azure / azure-iot-sdk-node / provisioning / device / samples / register_symkey.js View on Github external
//
// You can find your idScope in the portal overview section for your dps instance.
//
var idScope = process.env.PROVISIONING_IDSCOPE;

//
// The registration id of the device to be registered.
//
var registrationId = process.env.PROVISIONING_REGISTRATION_ID;

var symmetricKey = process.env.PROVISIONING_SYMMETRIC_KEY;

var provisioningSecurityClient = new SymmetricKeySecurityClient(registrationId, symmetricKey);

var provisioningClient = ProvisioningDeviceClient.create(provisioningHost, idScope, new ProvisioningTransport(), provisioningSecurityClient);
// Register the device.
provisioningClient.setProvisioningPayload({a: 'b'});
provisioningClient.register(function(err, result) {
  if (err) {
    console.log("error registering device: " + err);
  } else {
    console.log('registration succeeded');
    console.log('assigned hub=' + result.assignedHub);
    console.log('deviceId=' + result.deviceId);
    console.log('payload=' + JSON.stringify(result.payload));
    var connectionString = 'HostName=' + result.assignedHub + ';DeviceId=' + result.deviceId + ';SharedAccessKey=' + symmetricKey;
    var hubClient = Client.fromConnectionString(connectionString, iotHubTransport);

    hubClient.open(function(err) {
      if (err) {
        console.error('Could not connect: ' + err.message);
github Azure / azure-iot-sdk-node / provisioning / device / ts-samples / src / register_symkey.ts View on Github external
//
// You can find your idScope in the portal overview section for your dps instance.
//
const idScope = process.env.PROVISIONING_IDSCOPE;

//
// The registration id of the device to be registered.
//
const registrationId = process.env.PROVISIONING_REGISTRATION_ID;

const symmetricKey = process.env.PROVISIONING_SYMMETRIC_KEY;

let provisioningSecurityClient = new SymmetricKeySecurityClient(registrationId, symmetricKey);

let provisioningClient = ProvisioningDeviceClient.create(provisioningHost, idScope, new ProvisioningTransport(), provisioningSecurityClient);
// Register the device.
provisioningClient.setProvisioningPayload({a: 'b'});
provisioningClient.register((err, result) => {
  if (err) {
    console.log('error registering device: ' + err);
  } else {
    console.log('registration succeeded');
    console.log('assigned hub=' + result.assignedHub);
    console.log('deviceId=' + result.deviceId);
    console.log('payload=' + JSON.stringify(result.payload));
    let connectionString = 'HostName=' + result.assignedHub + ';DeviceId=' + result.deviceId + ';SharedAccessKey=' + symmetricKey;
    let hubClient = Client.fromConnectionString(connectionString, iotHubTransport);

    hubClient.open((err) => {
      if (err) {
        console.error('Could not connect: ' + err.message);
github Azure / azure-iot-sdk-node / provisioning / e2e / _provisioning_e2e.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 async = require('async');
var uuid = require('uuid');
var assert = require('chai').assert;
var crypto = require('crypto');
var debug = require('debug')('azure-iot-provisioning-device-e2e');
var Http = require('azure-iot-provisioning-device-http').Http;
var Amqp = require('azure-iot-provisioning-device-amqp').Amqp;
var AmqpWs = require('azure-iot-provisioning-device-amqp').AmqpWs;
var Mqtt = require('azure-iot-provisioning-device-mqtt').Mqtt;
var MqttWs = require('azure-iot-provisioning-device-mqtt').MqttWs;
var ProvisioningDeviceClient = require('azure-iot-provisioning-device').ProvisioningDeviceClient;
var ProvisioningServiceClient = require('azure-iot-provisioning-service').ProvisioningServiceClient;
var X509Security = require('azure-iot-security-x509').X509Security;
var Registry = require('azure-iothub').Registry;
var certHelper = require('./cert_helper');
var TpmSecurityClient = require('azure-iot-security-tpm').TpmSecurityClient;
var SymmetricKeySecurityClient = require('azure-iot-security-symmetric-key').SymmetricKeySecurityClient;
var TssJs = require("tss.js");

var idScope = process.env.IOT_PROVISIONING_DEVICE_IDSCOPE;
var provisioningConnectionString = process.env.IOT_PROVISIONING_SERVICE_CONNECTION_STRING;
var registryConnectionString = process.env.IOTHUB_CONNECTION_STRING;
var provisioningHost = process.env.IOT_PROVISIONING_DEVICE_ENDPOINT;

var provisioningServiceClient = ProvisioningServiceClient.fromConnectionString(provisioningConnectionString);
var registry = Registry.fromConnectionString(registryConnectionString);
github Azure / azure-iot-sdk-node / provisioning / e2e / _server_validation.js View on Github external
describe('DPS registration client', function() {
  var deviceCert = {
    cert: Buffer.from(process.env.IOTHUB_CA_ROOT_CERT, 'base64').toString('ascii'),
    key: Buffer.from(process.env.IOTHUB_CA_ROOT_CERT_KEY, 'base64').toString('ascii')
  };
  [
    httpModule.Http,
    amqpModule.Amqp,
    amqpModule.AmqpWs,
    mqttModule.Mqtt,
    mqttModule.MqttWs
  ].forEach(function (DeviceTransport) {
    describe('Over ' + DeviceTransport.name, function () {
      var X509Security = require('azure-iot-security-x509').X509Security;
      var ProvisioningDeviceClient = require('azure-iot-provisioning-device').ProvisioningDeviceClient;
      it.skip ('Should fail to register a device', function(done) {
        this.timeout(30000);
        var transport = new DeviceTransport();
        var securityClient = new X509Security('abcd', deviceCert);
        var deviceClient = ProvisioningDeviceClient.create(dpsDeviceClientEndpoint, 'scope', transport, securityClient);
        deviceClient.register(function(err) {
          correctDisconnectMessage(err, done);
        });
      });
    });
  });
});

azure-iot-provisioning-device-mqtt

MQTT transport for Azure Device Provisioning SDK

MIT
Latest version published 2 years ago

Package Health Score

51 / 100
Full package analysis

Similar packages