我正在编写 C# 代码,需要检查 Azure 中心是否禁用了 IoT 设备。请帮助我使用 C# 代码片段,如果设备已启用和禁用,我如何在代码中检查它。目前我正在使用 10 台设备进行测试。请帮忙。
最佳答案
我引用了这篇文章(How to disable Enable connection to IoT Hub?),我想我们可以使用下面的代码来测试它。
官方文档:
相关帖子
1. How to disable Enable connection to IoT Hub?
Dictionary<string,int> dic = new Dictionary<string, int>();
// key-value deviceid--status
dic.Add("deviceid1",-1);
...
dic.Add("deviceid10", -1);
// init RegistryManager
var registryManager = RegistryManager.CreateFromConnectionString(iotHubConnectionString);
Device device = null;
foreach (var item in dic)
{
device= registryManager.GetDeviceAsync(item.Key);
if (device != null)
{
dic[item.Key] = device.Status.DeviceStatus;
}
if (dic[item.Key] == -1)
{
Console.WriteLine("deviceid=" + item.Key + " , device not found");
}
else {
Console.WriteLine("deviceid=" + item.Key + " , status=" + (dic[item.Key] == 1 ? "Disabled" : "Enabled"));
}
}
关于c# - 如何通过 C# 代码检查 Azure IoT 中心门户中 IoT 设备的状态(启用或禁用)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65426390/