0

When invokes an iotHub query to get DevicetwinDevice of multiple devices:

SqlQuery sqlQuery = SqlQuery.createSqlQuery("*", SqlQuery.FromType.DEVICES, generateWhere(listDeviceIds), null);
            Query twinQueryCollection = twinClient.queryTwin(sqlQuery.getQuery());
            QueryOptions options = new QueryOptions();
            while (twinClient.hasNextDeviceTwin(twinQueryCollection)) {
                    deviceTwinList.add(twinClient.getNextDeviceTwin(twinQueryCollection));
            }

When later invokes getTags() from element, exception was throwed:

throw new IllegalArgumentException("Key cannot contain illegal unicode control characters '.', '$', ' '");

The problem is element inside tags contains a keys with $:

{"Session":"Sessio1",
"ManufacturingDate":"2019-0517T08:57:20.260+02:00[Europe/Madrid]",
"IV":"01.00",
"**$version**":1.0,
"Subtype":"-----",
"**$metadata**":{}
}

those elements on tag aren't mine. is it a SDK error? My code contains an error?

4

1 回答 1

0

我找到了一个可能的问题解决方案,执行查询后,我得到了一个 DeviceTwinDevice 列表。要毫无例外地获取标签,我需要执行twinClient.getTwin(deviceTwinDevice); . 像这样:

SqlQuery sqlQuery = SqlQuery.createSqlQuery("*", SqlQuery.FromType.DEVICES, generateWhere(listDeviceIds), null);
            Query twinQueryCollection = twinClient.queryTwin(sqlQuery.getQuery());
            QueryOptions options = new QueryOptions();
            while (twinClient.hasNextDeviceTwin(twinQueryCollection)) {
                    deviceTwinList.add(twinClient.getNextDeviceTwin(twinQueryCollection));
            }
            for (DeviceTwinDevice deviceTwinDevice : deviceTwinList) {
                **twinClient.getTwin(deviceTwinDevice);**
                if(!deviceTwinDevice.getTags().isEmpty()) {
                    -------------------------------------------------------
                }

getTwin() 方法删除 $keys。在这种情况下,我向 Azure IotHub 发送了不止一条消息。单个设备的查询和 getTwin。我想在 Azure IotHub 的独特消息中做同样的事情。可能吗?

于 2019-05-17T10:42:53.167 回答