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}`);
}