Azure / azure-iot-sdk-node

A Node.js SDK for connecting devices to Microsoft Azure IoT services
https://docs.microsoft.com/en-us/azure/iot-hub/
Other
262 stars 227 forks source link

DPS endpoint is no longer working #1156

Closed jezzdk closed 1 year ago

jezzdk commented 1 year ago

Context

Description of the issue

I've created a simple javascript client based on the examples. I have made sure that every configuration has been set properly. But when I run the client, it fails when trying to provision the device. I have also tried to run a sample from the repo, without changing the code, and it also fails when trying to provision. Both have been working a few weeks ago.

It seems the DPS endpoint is not working. The Azure status page shows that it should be working though.

I have registered the device in IoT Central and set the needed env variables. I have double checked that they all are correct.

In the code below, the IOTHUB_DEVICE_DPS_ENDPOINT env variable is set to "global.azure-devices-provisioning.net", as per the documentation. However, I keep getting a "Server unavailable" error.

Code sample exhibiting the issue

public async provisionDeviceClient(): Promise<string> {
  const provisioningSecurityClient = new SymmetricKeySecurityClient(
    process.env.IOTHUB_DEVICE_DPS_DEVICE_ID,
    process.env.IOTHUB_DEVICE_DPS_DEVICE_KEY
  );

  const provisioningClient = ProvisioningDeviceClient.create(
    process.env.IOTHUB_DEVICE_DPS_ENDPOINT,
    process.env.IOTHUB_DEVICE_DPS_ID_SCOPE,
    new ProvisioningTransport(),
    provisioningSecurityClient
  );

  const provisioningPayload = {
    iotcModelId: "xxxxx",
  };

  provisioningClient.setProvisioningPayload(provisioningPayload);

  const connectionString = await new Promise<string>((resolve, reject) => {
    provisioningClient.register((dpsError, dpsResult) => {
      if (dpsError) {
        return reject(dpsError);
      }

      return resolve(
        `HostName=${dpsResult.assignedHub};DeviceId=${dpsResult.deviceId};SharedAccessKey=IOTHUB_DEVICE_DPS_DEVICE_KEY`
      );
    });
  });

  return connectionString;
}

The result of provisioningClient.register() is an error stating: "Connection refused: Server unavailable". I have tried from several different networks.

The hostname "global.azure-devices-provisioning.net" resolves to "idsu-prod-am-001-su-az.westeurope.cloudapp.azure.com".

anthonyvercolano commented 1 year ago

@jezzdk Any possibility you are using some limited time subscription?

jezzdk commented 1 year ago

@anthonyvercolano That might be the case, although I don't see any indication of it in IoT Central. Where can I check for this?

jezzdk commented 1 year ago

@anthonyvercolano I just created a whole new IoT Central application on a new subscription and the problem persists. The provisioning fail immediately when using "global.azure-devices-provisioning.net" as provisioning host. If I use a random domain as the host, it hangs for a while before it fails.

Edit: I recently upgraded macOS to Ventura. Maybe that has something to do with it?

jezzdk commented 1 year ago

I figured it out now. Turns out I had switched the scope ID and device ID around... Not sure why it has worked earlier. Maybe because I'm an idiot.

Selekena commented 1 year ago

can you please share the DPS instance you were working with. Could you also share the full error code that you were getting?

jezzdk commented 1 year ago

can you please share the DPS instance you were working with. Could you also share the full error code that you were getting?

Check the OP, its all there.