简体   繁体   中英

Azure Get IoTHub Connection String from connected device/DPS Service

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 (ie, 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.

_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:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM