首页 文章

azure iothub设备状态

提问于
浏览
1

getConnectionState()作为连接/断开连接取决于设备 . 如果它正在发送消息我应该看到连接,如果它不发送我应该断开连接 . 但每次我运行下面的java程序我得到状态为断开连接而不管设备是是否发送消息

RegistryManager registryManager = RegistryManager.createFromConnectionString(connectionString);
    System.out.println(registryManager.getDevices(new Integer(1000)));
    while(true){
    ArrayList<Device> deviceslist=registryManager.getDevices(new Integer(1000));
    for(Device device:deviceslist)
    {
        /*System.out.println(device.getDeviceId());
        System.out.println(device.getPrimaryKey());
        System.out.println(device.getSecondaryKey());*/
        System.out.println(device.getDeviceId());
        System.out.println(device.getConnectionState());
        /*System.out.println(device.getConnectionStateUpdatedTime());
        System.out.println(device.getLastActivityTime());
        System.out.println(device.getStatusReason());
        System.out.println(device.getStatusUpdatedTime());
        System.out.println(device.getSymmetricKey());
        System.out.println(device.geteTag());
*/  }
    }

1 回答

  • 0

    我肯定是在看别的 .

    我正在使用下面的代码创建一个简单的C#控制台应用程序,

    static async void QueryDevices()
        {
            RegistryManager manager = RegistryManager.CreateFromConnectionString(connectionString);
            while (true)
            {
                var devices = await manager.GetDevicesAsync(100);
                {
                    foreach (var item in devices)
                    {
                        Console.WriteLine(DateTime.Now + ": " + item.Id + ", " + item.ConnectionState);
    
                        System.Threading.Thread.Sleep(100);
                    }
                }
            }
        }
    

    这里的git总是查询整个设备列表,因为ConnectionState属性看起来像单个设备客户端实例的“静态”成员,即使实际状态发生变化也不易改变 .

    我的输出如下所示,“连接”状态是当我使用Java客户端示例向IoT Hub发送消息时 .

    enter image description here

相关问题