"Invalid gcp.key" 来自 Mongoose OS 当连接 ESP32 到 Google Cloud Platform

"Invalid gcp.key" from Mongoose OS when connecting ESP32 to Google Cloud Platform

我正在尝试使用 Mongoose OS 将我的 ESP32 设备连接到 Google 云平台 (GCP)。我是 Mongoose OS 的新手,但已经了解了如何构建和刷新代码以及如何连接到 wifi。但是当我将信息添加到 mos.yml 文件以连接到 GCP 时,我遇到了问题。这是错误:

mgos.gcp.c:361 Invalid gcp.key (0xffffc200)

我已经使用以下命令创建了我的密钥对:

openssl ecparam -genkey -name prime256v1 -noout -out ec_private.pem
openssl ec -in ec_private.pem -pubout -out ec_public.pem

这是我的 mos.yml:

author: HiMinds.com
description: Test application for connecting to Google IoT Core via MQTT-bridge
version: 0.1
arch: esp32

libs_version: ${mos.version}
modules_version: ${mos.version}
mongoose_os_version: ${mos.version}

# Optional. List of tags for online search.
tags:

  - js
  - c

# List of files / directories with C sources. No slashes at the end of dir names.
sources:
  - src

# List of dirs. Files from these dirs will be copied to the device filesystem
filesystem:
  - fs

config_schema:
  - ["pins", "o", {title: "Pins layout"}]
  - ["pins.button", "i", 0, {title: "Button GPIO pin"}]
  - ["pins.button_pull_up", "b", true, {title: "True if button is pulled up when inactive"}]
  - ["pins.led", "i", 5, {title: "LED GPIO pin"}]
  - ["wifi.ap.enable", false]
  - ["wifi.sta.enable", true]
  - ["wifi.sta.ssid", "my_SSID"]
  - ["wifi.sta.pass", "my_password"]
  - ["device.id", "esp32"]
  - ["mqtt.enable.", true]
  - ["mqtt.server", "mqtt.googleapis.com:8883"]
  - ["mqtt.ssl_ca_cert", "roots.pem"]
  - ["gcp.enable", true]
  - ["gcp.project", "project_name"]
  - ["gcp.region", "europe-west1"]
  - ["gcp.registry", "registry_name"]
  - ["gcp.device", "esp32"]
  - ["gcp.key", "ec_private.pem"]
  - ["provision.max_state", 3]

libs:
 # - origin: https://github.com/mongoose-os-libs/ca-bundle
  - origin: https://github.com/mongoose-os-libs/core
  - origin: https://github.com/mongoose-os-libs/provision
  - origin: https://github.com/mongoose-os-libs/rpc-service-config
  - origin: https://github.com/mongoose-os-libs/rpc-service-fs
  - origin: https://github.com/mongoose-os-libs/rpc-service-gpio
  - origin: https://github.com/mongoose-os-libs/rpc-uart

  #IoT 
  - origin: https://github.com/mongoose-os-libs/adc
  - origin: https://github.com/mongoose-os-libs/mjs
  - origin: https://github.com/mongoose-os-libs/mqtt
  - origin: https://github.com/mongoose-os-libs/wifi
  - origin: https://github.com/mongoose-os-libs/gcp
  - origin: https://github.com/mongoose-os-libs/sntp

# Used by the mos tool to catch mos binaries incompatible with this file format
manifest_version: 2017-09-29

我错过了什么?

我有 运行 mos put full_path_to_key/ec_private.pem 将密钥发送到设备,只有当我从我的 "mos.yml" 发出 GCP 行时才有效。在重建和刷新包括 GCP 行在内的新代码后,我是否需要再次发送密钥?我还发送了一个下载的根证书文件 "roots.pem"(但实际上没有在任何地方读到你应该将这个文件发送到设备)。

我也不确定密钥文件(和 roots.pem 文件)的路径是否应该是我计算机上的完整路径,或者它们是否引用设备本身上的文件并且就足够了只有文件名没有路径。 None 个选项有效。

附带说明一下,即使 mos.yml 中没有 GCP 信息,我也会收到此错误,如果这可能与此有关:

MJS error: failed to exec file "api_aws.js": failed to read file "api_aws.js"

所以,原来我不需要在 "mos.yml" 中设置所有 GCP 信息信息,但它是在 运行ning

时为我设置的
mos gcp-iot-setup --gcp-project YOUR_PROJECT_ID --gcp-region YOUR_REGION --gcp-registry YOUR_REGISTRY

如果我尝试 运行使用 mos.yml 中的 GCP 信息执行此命令,我收到一条错误消息

Error: write /dev/ttyUSB0: file already closed

所以我不得不删除 GCP 信息,然后 运行 命令,然后建立连接!

密钥文件是在运行执行上述命令时生成的,因此无需将其传输到设备。根证书文件似乎也由命令处理。