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

Google Cloud IoT核心节点Node.js客户端:如何在Google Cloud函数中获取设备的lastHeartbeatTime?

如何解决Google Cloud IoT核心节点Node.js客户端:如何在Google Cloud函数中获取设备的lastHeartbeatTime?

我在云函数中使用2.1.1 API的 DeviceManagerClient.listDevices 函数 并且它正常工作,除了得到的 IDevice 的大多数属性为空的事实。 id numId 元数据属性不是null,而是其他所有包含 lastHeartbeatTime 属性。 如何使用Node.js API从云功能获取设备的 lastHeartbeatTime

最好的问候, Árpád

解决方法

谢谢您的回答!

这是一个用法示例:

const listDevicesResponse = await iotClient.listDevices({
  parent: iotClient.registryPath(process.env.GCLOUD_PROJECT!,CLOUD_REGION,REGISTRY_ID),fieldMask: {paths: ['last_heartbeat_time']}
  // For a full list of fieldMask paths see https://github.com/googleapis/nodejs-iot/issues/178#issuecomment-580999577
});
const devices = listDevicesResponse[0];
for(const device of devices) {
  if (devices === null) continue;
  functions.logger.info(`device.id:${device.id},device.lastHeartbeatTime?.seconds:${device.lastHeartbeatTime?.seconds}`);
}

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