我正在尝试编写一个函数,该函数会将命令发送到Google Cloud IoT核心中定义的设备。从控制台发送命令可以正常工作。
我正在使用Sending commands to devices
中的以下示例OS_PLATFORM_VALID_END
但是,在功能日志中,我收到消息“错误:最低要求是Node.js v10.0.0。”
我在项目中运行了-v节点,结果得到v10.16.3,所以感到很困惑。谁能提供任何建议?
gcloud函数描述结果:
// const cloudRegion = 'us-central1';
// const deviceId = 'my-device';
// const commandMessage = 'message for device';
// const projectId = 'adjective-noun-123';
// const registryId = 'my-registry';
const iot = require('@google-cloud/iot');
const iotClient = new iot.v1.DeviceManagerClient({
// optional auth parameters.
});
const formattedName = iotClient.devicePath(
projectId,
cloudRegion,
registryId,
deviceId
);
const binaryData = Buffer.from(commandMessage);
const request = {
name: formattedName,
binaryData: binaryData,
};
try {
const responses = await iotClient.sendCommandToDevice(request);
console.log('Sent command: ', responses[0]);
} catch (err) {
console.error('Could not send command:', err);
}
package.json:
availableMemoryMb: 256
entryPoint: updateDevice
eventTrigger:
eventType: providers/cloud.firestore/eventTypes/document.create
failurePolicy: {}
resource: projects/project/databases/(default)/documents/pubsubMessages/{docID}
service: firestore.googleapis.com
ingressSettings: ALLOW_ALL
labels:
deployment-tool: cli-firebase
name: projects/project/locations/us-central1/functions/updateDevice
runtime: nodejs8
serviceAccountEmail: email@appspot.gserviceaccount.com
sourceUploadUrl: https://storage.googleapis.com/gcf-upload-us-central1-xxx
status: ACTIVE
timeout: 60s
updateTime: '2020-05-18T09:56:29.144Z'
versionId: '46'