How to use the azure-iot-provisioning-device.ProvisioningDeviceClient.create function in azure-iot-provisioning-device

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

github Azure-Samples / azure-iot-samples-node / provisioning / Samples / device / register_x509.js View on Github external
// This id will be shown at the device enrollment registration records
//
var registrationId = process.env.REGISTRATION_ID;
if (!registrationId) {
  console.error('please set the REGISTRATION_ID environment variable to the one you want to use.');
  process.exit(-1);
}

var deviceCert = {
  cert: fs.readFileSync('<cert filename>').toString(),
  key: fs.readFileSync('<key filename>').toString()
};

var transport = new Transport();
var securityClient = new X509Security(registrationId, deviceCert);
var deviceClient = ProvisioningDeviceClient.create(provisioningHost, idScope, transport, securityClient);

// Register the device.  Do not force a re-registration.
deviceClient.register(function(err, result) {
  if (err) {
    console.log("error registering device: " + err);
    process.exit(-1);
  } else {
    console.log('registration succeeded');
    console.log('assigned hub=' + result.assignedHub);
    console.log('deviceId=' + result.deviceId);
    process.exit(0);
  }
});
github Azure / azure-iot-sdk-node / provisioning / device / samples / register_tpm.js View on Github external
var tpmSecurity = require('azure-iot-security-tpm');
var ProvisioningDeviceClient = require('azure-iot-provisioning-device').ProvisioningDeviceClient;

//
// For the public clouds the address of the provisioning host would be: global.azure-devices-provisioning.net
//
var provisioningHost = '<replace with provisioning host entry point>';

//
// You can find your idScope in the portal overview section for your dps instance.
//
var idScope = '<the id scope for your dps instance>';

var securityClient = new tpmSecurity.TpmSecurityClient();

var provisioningClient = ProvisioningDeviceClient.create(provisioningHost, idScope, new ProvisioningTransport(), securityClient);
// Register the device.  Do not force a re-registration.
provisioningClient.register(function(err, result) {
  if (err) {
    console.log("error registering device: " + err);
  } else {
    console.log('registration succeeded');
    console.log('assigned hub=' + result.registrationState.assignedHub);
    console.log('deviceId=' + result.registrationState.deviceId);
    var tpmAuthenticationProvider = tpmSecurity.TpmAuthenticationProvider.fromTpmSecurityClient(result.registrationState.deviceId, result.registrationState.assignedHub, securityClient);
    var hubClient = Client.fromAuthenticationProvider(tpmAuthenticationProvider, iotHubTransport);

    var connectCallback = function (err) {
      if (err) {
        console.error('Could not connect: ' + err.message);
      } else {
        console.log('Client connected');
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 / device / samples / register_x509.js View on Github external
// var Transport = require('azure-iot-provisioning-device-mqtt').MqttWs;

var X509Security = require('azure-iot-security-x509').X509Security;
var ProvisioningDeviceClient = require('azure-iot-provisioning-device').ProvisioningDeviceClient;

var provisioningHost = '[provisioning host]';
var idScope = '[id scope]';
var registrationId = '[registration id]';
var deviceCert = {
  cert: fs.readFileSync('[cert filename]').toString(),
  key: fs.readFileSync('[key filename]').toString()
};

var transport = new Transport();
var securityClient = new X509Security(registrationId, deviceCert);
var deviceClient = ProvisioningDeviceClient.create(provisioningHost, idScope, transport, securityClient);

// Register the device.  Do not force a re-registration.
deviceClient.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);
  }
});
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 / 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}`;
github Azure / azure-iot-sdk-node / provisioning / e2e / _server_validation.js View on Github external
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);
        });
      });
    });
github Azure / azure-iot-sdk-node / provisioning / e2e / _provisioning_e2e.js View on Github external
this.register = function (Transport, callback) {
    var securityClient = new X509Security(self.registrationId, self._cert);
    var transport = new Transport();
    var provisioningDeviceClient = ProvisioningDeviceClient.create(provisioningHost, idScope, transport, securityClient);
    provisioningDeviceClient.register(function (err, result) {
      assert.isNotOk(err);
      assert.isOk(result.deviceId);
      self.deviceId = result.deviceId;
      callback(err, result);
    });
  };
github Azure / azure-iot-sdk-node / provisioning / e2e / _provisioning_e2e.js View on Github external
this.register = function (Transport, callback) {
    var transport = new Transport();
    var provisioningDeviceClient = ProvisioningDeviceClient.create(provisioningHost, idScope, transport, securityClient);
    provisioningDeviceClient.register(function (err, result) {
      callback(err, result);
    });
  };