Google cloud platform Google Cloud IoT sendCommandToDevice from Cloud Functions显示服务不可用

Google cloud platform Google Cloud IoT sendCommandToDevice from Cloud Functions显示服务不可用,google-cloud-platform,google-cloud-functions,google-cloud-iot,Google Cloud Platform,Google Cloud Functions,Google Cloud Iot,我尝试从云函数发送命令,但收到错误:该服务当前不可用 Package.JSON “依赖项”:{ “firebase管理员”:“~6.0.0”, “firebase功能”:“^2.0.3”, “googleapis”:“34.0.0” } 日志: {错误:该服务当前不可用。在解压时(/user_code/node_modules/googleapis/node_modules/axios/lib/core/createError.js:16:15)解压时(/user_code/node_modul

我尝试从云函数发送命令,但收到错误:该服务当前不可用

Package.JSON “依赖项”:{ “firebase管理员”:“~6.0.0”, “firebase功能”:“^2.0.3”, “googleapis”:“34.0.0” }

日志:
{错误:该服务当前不可用。在解压时(/user_code/node_modules/googleapis/node_modules/axios/lib/core/createError.js:16:15)解压时(/user_code/node_modules/googleapis/node_modules/node_modules/axios/axios/adapters/http.js:201:11)在emitNone(events.js:91:20)在Unzip.emit(events.js:185:7)在endReadableNT(_stream_readable.js:974:12)在emitNone(events.js:91:20)在endReadableNT(_stream_readable.js:974:12)在_combinedTickCallback(internal/process/next_tick.js:80:11)在process

我对Firebase云函数不太熟悉,但我使用云函数的内联编辑器()时没有遇到错误。您能告诉我何时开始出现此错误(如果仍然遇到此错误)吗

作为参考,这里是我使用的代码(基本上是您使用的代码,但是对
projectd,cloudRegion
有更明确的定义)

const {google} = require('googleapis');

const API_VERSION = 'v1';
const DISCOVERY_API = 'https://cloudiot.googleapis.com/$discovery/rest';

exports.sendCommand = (req, res) => {
  let reqData = req.body;

  const projectId = reqData.projectId || process.env.GCLOUD_PROJECT;
  const cloudRegion = reqData.cloudRegion || process.env.GCLOUD_REGION;

  const parentName = `projects/${projectId}/locations/${cloudRegion}`;
  const registryName = `${parentName}/registries/${reqData.registryId}`;
  const binaryData = Buffer.from(JSON.stringify(reqData.message)).toString('base64');
  const request = {
      name: `${registryName}/devices/${reqData.deviceId}`,
      binaryData: binaryData
  };

  google.auth.getClient().then((authClient) => {
      const discoveryUrl =
          `${DISCOVERY_API}?version=${API_VERSION}`;
      if (authClient.createScopedRequired && authClient.createScopedRequired()) {
        // Scopes can be specified either as an array or as a single,
        // space-delimited string.
        authClient = authClient.createScoped([
          'https://www.googleapis.com/auth/cloud-platform'
        ]);
      }

      google.options({
        auth: authClient
      });

      google.discoverAPI(discoveryUrl).then((client, err) => {
        if (err) {
          console.log('Error during API discovery', err);
          return undefined;
        }
        client.projects.locations.registries.devices.sendCommandToDevice(request,
          (err, data) => {
            if (err) {
              console.log('Could not send command:', request);
              console.log('Message: ', err);
            } else {
              console.log('Success :', data.statusText);
            }
          });
      });
    });
  res.status(200).send(reqData.message);
};

问题是必须指定
子文件夹
,并且不能是空字符串

当我在Firebase函数中使用它时,我只将
Firebase
子文件夹用于发送的没有特定子文件夹的任何命令

const request = {
    name: `${registryName}/devices/${deviceId}`,
    binaryData: Buffer.from(JSON.stringify(commandMessage)).toString("base64"),
    subfolder: 'firebase'
}
以下是部门职能:

  "dependencies": {
    "firebase-admin": "^6.4.0",
    "firebase-functions": "^2.1.0",
    "fs-extra": "^7.0.0",
    "googleapis": "^36.0.0",
  },
这可能是由于

  • 节点库中的bug
  • 谷歌端点的bug
  • 谷歌方面缺乏测试

  • 谷歌的“物联网”似乎还很年轻,需要大量的工作

    我也有同样的错误,似乎没有人知道为什么……但真正奇怪的是,我无法在本地运行的机器上重现这种行为,这让我相信这是特定于GCF的。
      "dependencies": {
        "firebase-admin": "^6.4.0",
        "firebase-functions": "^2.1.0",
        "fs-extra": "^7.0.0",
        "googleapis": "^36.0.0",
      },