azure iothub设备状态 [英] azure iothub device status

查看:55
本文介绍了azure iothub设备状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

getConnectionState()是否为已连接/已断开,取决于设备.如果正在发送消息,我应该看到已连接,如果未发送,我应该被断开.但是每次我运行下面的java程序时,我都将获得状态为已断开(无论如何)的设备是否正在发送消息

getConnectionState() as connected /disconnected depending on the device .if it is sending message i should see connected and if it not sending i should get disconnected .But each time i run the below java Program i am getting status as disconnected irrespective of device is sending messages or not

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());
*/  }
    }

推荐答案

我肯定会看到其他情况.

I definitely am seeing otherwise.

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

I'm creating an simple C# console application using the code below,

    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属性在某种程度上看起来像单个设备客户端实例的静态"成员,即使实际状态发生变化,它也不容易改变.

The git here is to always query the whole device list, because the ConnectionState property somehow looks like "static" memebers of the single device client instance, which is not apt-to change even when the actual state changes.

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

And my output is like below, the "connected" state is when I'm using an java client sample to send message to the IoT Hub.

这篇关于azure iothub设备状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆