微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 listDevices 从谷歌云物联网核心获取设备元数据信息

如何解决如何使用 listDevices 从谷歌云物联网核心获取设备元数据信息

我想使用 listDevices 将我的所有设备都放在一个注册表下。 Google NodeJS Core IOT API spec

我得到一个数组,它似乎包含一个元数据 obj/json 文档,但它是空的。

---
- credentials: []
  Metadata: {}
  id: device001
  name: ''
  numId: '3038801391636994'
  config:
  lastConfigAckTime:
  state:
  lastConfigSendTime:
  blocked: false
  lastStateTime:
  logLevel: LOG_LEVEL_UNSPECIFIED
  gatewayConfig:
- credentials: []
  Metadata: {}
  id: device002
  name: ''
  numId: '2991873732633082'
  config:
  lastConfigAckTime:
  state:
  lastConfigSendTime:
  blocked: false
  lastStateTime:
  logLevel: LOG_LEVEL_UNSPECIFIED
  gatewayConfig:

如果我运行 getDevice,我确实会获得预期的元数据,但这需要对每个设备发出请求,这会变得太慢并消耗资源。错误还是设计?

const [response] = await iotClient.getDevice({name: devicePath});

实际显示元数据

    Found device: device002 {
  credentials: [
    {
      expirationTime: [Object],publicKey: [Object],credential: 'publicKey'
    }
  ],Metadata: {
    hasGPS: 'true',model: 'Pyton_v1',hasSolar: 'true',netType: 'WIFI'
  },id: 'device002'
}

解决方法

我对设备列表功能做了一些尝试,我认为这是一种设计。

如果您运行 here,您只会得到字段 idnum_id,它们也填充在您的输出数组中。

我尝试使用其他客户端库,但得到了相同的结果,所以看起来它是这样设计的,但 NodeJS 库会为每个设备检索额外的字段。

,

在 listDevices api 的 fieldMask 参数中定义。在此处检查示例代码:

https://cloud.google.com/iot/docs/how-tos/devices?authuser=1#getting_device_details

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。