0
votes

I´m using Azure Device Provisioning Service (DPS) to automatically register and provision devices to Azure IoT Hub.

I would like to get the device twin of a particular device.

I can manage to get the device twin by using de DeviceClient class:

var result = await provisioningDeviceClient.RegisterAsync().ConfigureAwait(false);
DeviceAuthenticationWithX509Certificate deviceAuthentication = new DeviceAuthenticationWithX509Certificate(result.DeviceId, certificate);
var deviceClient = DeviceClient.Create(result.AssignedHub, deviceAuthentication, TransportType.Mqtt_Tcp_Only);
var deviceTwin = await deviceClient.GetTwinAsync().ConfigureAwait(false);

But I would like to get the device by using the RegistryManager, which requires the connection string of a particuar IoTHub.

using (var registryManager = RegistryManager.CreateFromConnectionString(IotHubConnectionString))
{
    var deviceTwin = await registryManager.GetTwinAsync(result.DeviceId);
}

Is there anyway to get the IoT Hub connection string from the DPS, or the connected device or the IoT Hub name (i.e., result.AssignedHub)? I´m using c# SDK.

I have seen a possible aproach in: https://github.com/MicrosoftDocs/azure-docs.es-es/blob/master/articles/iot-hub/iot-hub-devguide-security.md#compatibilidad-con-c However, I can not manage to see where the variable deviceGatewayConnectionString that they use in the example comes from.

1

1 Answers

0
votes
_deviceClient = DeviceClient.Create(IotHubUri, new 
 DeviceAuthenticationWithRegistrySymmetricKey(DeviceId, DeviceKey), TransportType.Mqtt);

put symm key for 'DeviceKey'

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.devices.client.deviceauthenticationwithregistrysymmetrickey?view=azure-dotnet

i guess this may help you :)