Azure Provisioning service example not working for node

azure iot nodejs
provisioning service client
azure node sdk
azure iot edge node sdk
azure iot device sdk node js
azure iot device mqtt github
iot node js sdk
device provisioning

I followed the node.js tutorial to register device throuh Azure DPS(device provisioning service) @ https://docs.microsoft.com/en-us/azure/iot-dps/quick-create-simulated-device-x509-node . For individual device enrollment it succedded, but when I try to register devices through enrollment groups it fails. I used "create_test-cert.js root" to generate my root certificate and

create_test-cert.js verification --ca {rootcertificate_cert
.pem} --key {rootcertificate_key.pem} --nonce {verificationKey}

to verify . I also used create_test-cert.js device {leafcertificate} {rootcertificate-name} to create the device certificate. Finally I used register_x509.js file to register my device to Azure. Executing this file I have the following error

azure-iot-provisioning-device:X509Registration registrationId: first +0ms
  azure-iot-provisioning-device:PollingStateMachine register called for registrationId "first" +0ms
  azure-iot-provisioning-device:PollingStateMachine completed transition from disconnected to sendingRegistrationRequest +0ms
  azure-iot-provisioning-device-http:Http submitting PUT for first to /0ne00015676/registrations/first/register?api-version=2017-11-15 +0ms
  azure-iot-provisioning-device-http:Http {"registrationId":"first"} +0ms
  azure-iot-provisioning-device-http:Http error executing PUT: UnauthorizedError: Error: {"errorCode":401002,"trackingId":"e6b9c185-64c4-4535-8d23-a7625dd3e011","message":"Unauthorized","timestampUtc":"2018-04-23T12:21:56.1390465Z"} +353ms

Error code "401002 is IotHubUnauthorizedAccess "

thanks

I have tested with the latest version SDK. It works. Following are my operation steps.

Update:

  1. Generate the root ca certificate file with the command(testRootCert_cert.pem,testRootCert_fullchain.pem,testRootCert_key.pem would be genetated in tools folder):

node create_test_cert.js root

  1. Add a certificate named "root" in Certificates, and upload the root ca file(testRootCert_cert.pem).

  2. Generate the verification Code and create the verification ca file with this command,upload the verification_cert.pem file, the status "root" will be "Verified":

node create_test_cert.js verification --ca testRootCert_cert.pem --key testRootCert_key.pem --nonce {verification code}

  1. Create the enrollment group following this guide, an enrollment group named "first" will be created:

node create_enrollment_group.js "" "testRootCert_cert.pem"

  1. Generate the certificate file for the device to enroll to the group via following command.

node create_test_cert.js device device01 testRootCert

  1. Copy the device01 _cert.pem,device01 _fullchain.pem, and device01 _key.pem to '\device\samples' folder,and modify provisioning host,id scope, registration id(here as 'first' named),cert filename and key filename. Please refer to this document.

var provisioningHost = '{your provisioning Host}'; var idScope = '{your id scope}'; var registrationId = 'device01'; var deviceCert = { cert: fs.readFileSync('device01_cert.pem').toString(), key: fs.readFileSync('device01_key.pem').toString() };

  1. At last, run node register_x509.js to assign the device. The message will be shown as :
registration succeeded
assigned hub={iothub host}
deviceId=device01

Please node that the Device Provisioning Service should be linked to your IoT Hub.

azure-iot-sdk-node/provisioning/service/samples at master · Azure , A Node.js SDK for connecting devices to Microsoft Azure IoT services running the sample, use the portal for the Device Provisioning Service which can display​  In this quickstart, you programmatically create an individual enrollment for a TPM device in the Azure IoT Hub Device Provisioning Service using the Node.js Service SDK and a sample Node.js application. You can optionally enroll a simulated TPM device to the provisioning service using this individual enrollment entry. Prerequisites

Thanks to Michael I realized that the issue was in the documentation. It was unclear that the registrationid was the registarationid of the leaf and not the registrationid of the parent certificate

"Replace registration id with the Registration Id noted in the previous section. " should be replaced by "Replace registration id with the Registration Id of the leaf previously generated"

azure-iot-sdk-node/provisioning/device/samples at master · Azure , A Node.js SDK for connecting devices to Microsoft Azure IoT services - Azure/​azure-iot-sdk-node. Registration will fail if this field is not set correctly. When running this sample, you'll need to replace the '[provisioning host]' '[id scope]',  Best practices and troubleshooting guide for node applications on Azure App Service Windows. 11/09/2017; 12 minutes to read +6; In this article. In this article, you learn best practices and troubleshooting steps for node applications running on Azure App Service (with iisnode).

the provisioning service sample for .net also does't work, link as itenter link description here.always get a system.argument error, value can't null. then I find the problem is Environment.GetEnvironmentVariable(key) return null. How can I do with this error?

Enroll X.509 devices to Azure Device Provisioning Service using , to the Azure IoT Hub Device Provisioning Service (DPS) using the Node.js The enrollment group is created using the IoT SDK for Node.js and a sample Node.js application. These certificates must not be used in production. Open a command prompt or Git Bash shell, and change to a working folder  In the Azure portal, on the Device Provisioning Service summary blade, select Manage enrollments. Select the Enrollment Groups tab and verify that the new enrollment entry (first) is present. Clean up resources. If you plan to explore the Node.js service samples, do not clean up the resources created in this quickstart.

Provision simulated X.509 device to Azure IoT Hub using Node.js , Create and provision a simulated X.509 device using Node.js device SDK for Azure IoT Hub Device Provisioning Service (DPS). If you plan to continue working on and exploring the device client sample, do not clean up the  Deploying a Node.js Express app to Azure App Service using Visual Studio Code Indraneel Pole 2 years ago (2018-05-26) node.js , express , Azure , app service So Node.js is really cool if you have to do the rapid prototyping, and that is why I decided to use it in our demo for the Vivatech TechCrunch Hackathon at Paris.

Quickstart, Node.js device SDK for Azure IoT Hub Device Provisioning Service to continue working on and exploring the device client sample, do not  Learn how to troubleshoot and resolve common problems when using Azure Kubernetes Service or scaling will not work mounted on the node. For example, you may

Tutorial, Tutorial: Create and connect a Node.js client application to your Azure IoT The instructions in this tutorial assume you're running the node command at azure-​iot-provisioning-device-mqtt azure-iot-security-symmetric-key --save if (err) { console.log(`Device could not connect to Azure IoT Central: ${err. Navigate to your provisioning service in the Azure portal. Click Manage enrollments. Notice that your group of X.509 devices appears under the Enrollment Groups tab, with an auto-generated GROUP NAME. Simulate the device. On the Device Provisioning Service summary blade, select Overview and note your ID Scope and Provisioning Service Global

Comments
  • What is "DPS?" It's helpful to define acronyms. Also, it's unclear what tutorial you're referring to, and without much context around this question, it's unclear what, specifically, you're attempting to do, or what the expected outcome is (other than it involves Azure IoT). Please edit your question accordingly.
  • Hi Michael, I'm currently on the master branch of azure-iot-sdk-node and yes I have linked my iotHub to DPS. Do you know if I can find some logs in AZure portal explaining the problem. I don't know if the problem is link to my certificate or by something else.
  • Hi Mickael, the procedure you describe work also on my side as individual enrollment, my problem is when I try to provision a device on an enrollment group
  • I'm currently on the master branch of azure-iot-sdk-node and yes I have linked my iotHub to DPS. Do you know if I can find some logs in AZure portal explaining the problem. I don't know if the problem is link to my certificate or by something else
  • @stef, you can set Diagnostics settings in your DPS to monitor and diagnostics logs to make sure everything is working properly.
  • @stef, it also works when i tried to provision a device on a enrollment group.I have updated the reply.
  • thanks Mickael, I activated diagnostic logs yesterday, but I don't find them on Azure do you know where I can find them? Yesterday you tried an individual enrollment but did you try to do the same with group enrollment, this is the case which fails, and I don't find example on Azure docs.
  • You can give a feedback about the document at the bottom in the document.