来自 Azure SDK 的 Azure 物联网 deviceId 验证
Azure iot deviceId validation from Azure SDK
我们使用 Azure SDK 创建资源组、物联网中心和设备。
例如:
iotHubDescription = await iotHubClient.IotHubResource.CreateOrUpdateAsync(resourceGroupName, iotHubName,
iotHubDescription);
或
var device = await registryManager.AddDeviceAsync(new Device(azureDevice.DeviceId));
我找到了如何在创建 Iot Hub 名称之前验证它:
var info = await iotHubClient.IotHubResource.CheckNameAvailabilityAsync(new OperationInputs(iotHubName));
但找不到如何验证设备 ID。
所以,问题是:如何从 Azure SDK 验证物联网设备 ID?
你需要使用 Exception
,
try
{
simulatedDevice = await registryManager.AddDeviceAsync(new Device(simulatedDeviceId));}
catch (DeviceAlreadyExistsException)
{
simulatedDevice = await registryManager.GetDeviceAsync(simulatedDeviceId);
Console.WriteLine("Retrieving existing device id");
}
}
我们使用 Azure SDK 创建资源组、物联网中心和设备。
例如:
iotHubDescription = await iotHubClient.IotHubResource.CreateOrUpdateAsync(resourceGroupName, iotHubName,
iotHubDescription);
或
var device = await registryManager.AddDeviceAsync(new Device(azureDevice.DeviceId));
我找到了如何在创建 Iot Hub 名称之前验证它:
var info = await iotHubClient.IotHubResource.CheckNameAvailabilityAsync(new OperationInputs(iotHubName));
但找不到如何验证设备 ID。
所以,问题是:如何从 Azure SDK 验证物联网设备 ID?
你需要使用 Exception
,
try
{
simulatedDevice = await registryManager.AddDeviceAsync(new Device(simulatedDeviceId));}
catch (DeviceAlreadyExistsException)
{
simulatedDevice = await registryManager.GetDeviceAsync(simulatedDeviceId);
Console.WriteLine("Retrieving existing device id");
}
}