Can we connect the device to an iot hub of our choice using the azure iot sdk C?

Y MRUDULA 21 Reputation points
2023-01-05T12:16:14.92+00:00

An individual device is enrolled on Azure and assigned to and assigned to an IoT Hub named "A-stg". The configuration selected is "Static configuration".
For registering device first the "Prov_Device_LL_Create()" is called, then the "Prov_Device_LL_Register_Device" is called and finally the "Prov_Device_LL_DoWork" API is called.
When the "Prov_Device_LL_DoWork" the register_device_callback is called wherein it gets the IoT Hub to which the device is assigned in the Azure cloud.

What I want to accomplish is during this device registration process, I would like to connect the device to a different IoT Hub url than what the device is assigned to in the cloud?
I tried changing the IoT Hub url in the register_device_callback but provisioning was not successful. I also tried changing the iothub uri variable inside the handle that is created by the Prov_Device_LL_Create() API but it seems that this variable remains NULL throughout the provisioning process. I also tried changing the configuration for the device on the cloud to "Evenly weighted distribution" and selected all the IoT hubs to which i want to connect the device. Unfortunately, this also did not work.

The error I receive is -
Status=IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED(1); Reason=IOTHUB_CLIENT_CONNECTION_DEVICE_DISABLED(1)

Has anyone ever tried such a thing?
Any help/guidance in this is appreciated.

Thank you

Azure IoT
Azure IoT
A category of Azure services for internet of things devices.
378 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,115 questions
Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
208 questions
{count} votes

Accepted answer
  1. chbeier 1,866 Reputation points
    2023-01-06T12:27:28.55+00:00

    If your device should connect to A.net, B.net or C.net, the device needs to be registered in each IoT Hub instance. Azure IoT Hub Device Provisioning Service can do this for you if you link each IoT Hub instance to your DPS and create a proper allocation policy defining the target IoT Hub instance for your specific device based on your requirements (e.g., load balanced, closest distance, canary instance, et cetera). This is the recommended way as it simplifies management and device provisioning.

    If you want to do this manually, e.g., in an active-active or active-passive HA scenario, you need to create an identity registry entry for this specific device in each IoT Hub. If you have many devices what should be able to connect to multiple IoT Hub instances, you might consider exporting the device registry of IoT Hub A.net after creating all devices and importing the device registry into IoT Hub B.net and C.net. If you add or remove a device, you need to do this in each IoT Hub instance, what could become cumbersome and difficult to keep track of.

    For more information see also the IoT Hub documentation on identity registry


    If your question is answered, please use "accept answer" and feel free to up vote the answer. This helps others to find the right answer more easily.


0 additional answers

Sort by: Most helpful