This file can be found in https://github.com/Azure/azure-iot-sdk-node/tree/main/provisioning/service/samples
This folder contains simple samples showing how to use the various features of the Microsoft Azure IoT Device Provisioning Service from an application running JavaScript code.
- Create a simple IndividualEnrollment object based on TPM.
- Create a simple IndividualEnrollment object based on x509 certificate.
- Create a simple EnrollmentGroup object.
- Create a couple of IndividualEnrollments and delete them.
- Create queries for IndividualEnrollments, EnrollmentGroups and DeviceRegistrationStates that belong to an EnrollmentGroup.
- Perform BulkEnrollmentOperations to do various CRUD operations.
In order to run the device samples you will first need the following prerequisites:
- Node.js v4 or above on your target device. (Check out Nodejs.org for more info)
- Setup Azure IoT Device Provisioning Stop before executing the the Create and provision a simulated device section. The samples below will perform these steps.
To generate a x509 certificate to run the individual enrollment of a device with x509 you need to create one. See create-certificate-for-individual-enrollment.
The following is an endorsement key, used for TPM. It has been generated by a simulator and as it has no corresponding private portion, is only useful as an input to these examples.
AToAAQALAAMAsgAgg3GXZ0SEs/gakMyNRqXXJP1S124GUgtk8qHaGzMUaaoABgCAAEMAEAgAAAAAAAEAxsj2gUScTk1UjuioeTlfGYZrrimExB+bScH75adUMRIi2UOMxG1kw4y+9RW/IVoMl4e620VxZad0ARX2gUqVjYO7KPVt3dyKhZS3dkcvfBisBhP1XH9B33VqHG9SHnbnQXdBUaCgKAfxome8UmBKfe+naTsE5fkvjb/do3/dD6l4sGBwFCnKRdln4XpM03zLpoHFao8zOwt8l/uP3qUIxmCYv9A7m69Ms+5/pCkTu/rK4mRDsfhZ0QLfbzVI6zQFOKF/rwsfBtFeWlWtcuJMKlXdD8TXWElTzgh7JS4qhFzreL0c1mI0GCj+Aws0usZh7dLIVPnlgZcBhgy1SSDQMQ==
Get the following files from the current folder:
- package.json
- sample_file.js (where sample_file.js is one of the files listed above and available in this folder)
Place the files in the folder of your choice on the target machine/device then go through the following steps:
- From a shell or Node.js command prompt, navigate to the folder where you placed the sample files. For creating an IndividualEnrollment do:
$ npm install
$ node create_individual_enrollment.js "<the connection string for the Device Provisioning instance enclosed in quotes>" "<an endorsement key in quotes>"
- For the TokenCredential sample:
For a quick explanation of Role Based Access Control, you can check this overview.
Get the following files from the current folder:
- package.json
- sample_file.js (where sample_file.js is one of the files listed above and available in this folder)
Place the files in the folder of your choice on the target machine/device then go through the following steps:
- From a shell or Node.js command prompt, navigate to the folder where you placed the sample files. For creating an IndividualEnrollment do:
$ npm install
$ node create_tpm_enrollment_with_token_credential.js -h <The host name of the DPS instance> -t <The AAD tenant ID> -c <The AAD client ID> -s <The AAD client secret>
- For creating an EnrollmentGroup:
If you already have a PEM or CER file then simply give the file name below on the command line "node create_enrollment_groupd.js ...". If you need to create a PEM file there are command scripts in this directory that could be useful FOR TESTING. Please see the md file in that directory C SDK cert tools overview.
$ npm install
$ node create_enrollment_group.js "<the connection string for the Device Provisioning instance enclosed in quotes>" "<The name of a file containing a pem or cer representation of a signing certificate>"
- The other samples simply require the connection string:
$ npm install
$ node create_delete.js "<the connection string for the Device Provisioning instance enclosed in quotes>"
- In order to monitor the results of running the sample, use the portal for the Device Provisioning Service which can display group or individual enrollments.
For more information on how to use this library refer to the documents below: