【问题标题】:How to get the device metadata info from google cloud iot core using listDevices如何使用 listDevices 从谷歌云物联网核心获取设备元数据信息
【发布时间】:2021-01-03 00:37:22
【问题描述】:

我想使用 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'
}

【问题讨论】:

  • 您的数据似乎已在 YAML 中列出,并显示了一组看似设备的内容。所以你已经完成了任务......你已经在注册表下检索了设备。我们似乎看到“元数据”字段为空。您对存在与 device001 或 device002 关联的元数据有多大把握?
  • @Kolban 我更新了我的问题以包含 getDevices(registry) 中列出的设备之一的 getDevice(deviceid) 打印输出。在那里。但也许它的意思是空的?我正在尝试查找模型类型为“Python_v1”的设备。 API Doc提到元数据没有被索引等等,但我可以在客户端过滤它。

标签: google-cloud-platform google-cloud-iot


【解决方案1】:

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

如果您运行"gcloud iot devices list" command,您只会得到idnum_id 字段,这些字段也会填入您的输出数组。

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

【讨论】:

  • 无赖,但你是对的,我刚刚用 node.js 测试了这个,实际上在 listDevices 中你必须执行 getDevice 才能获取元数据。
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    相关资源
    最近更新 更多