Trying to connect ESP32 to Google IOT Core error

#1
  1. My goal is: Connect ESP32 device to GCP IoT Core Registry
  2. My actions are: use the command
    mos gcp-iot-setup --gcp-project YOUR_PROJECT_ID --gcp-region europe-west1 --gcp-registry iot-registry
    as per instructions in : https://mongoose-os.com/docs/mongoose-os/cloud/google.md
  3. The result I see is: a message which says
    error: google: could not find default credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.


4. My expectation & question is: How to solve this problem and connect my ESP32

#2

Google stuff.
Some months ago (read: several gcloud versions ago) I wrote this tutorial in Spanish, translated here for your convenience:

To have a new device in GCP you have to
• load the device on the device registry
• generate private and public keys
• upload public key to the device registry
• obtain GCP Broker certificate
• configure the device with Cloud IoT Core connect data
• upload private key and Google certificate to the device
mos tool does everything for you, but you need to authorize the API that it will use, via gcloud.
To generate your authorization credentials:

gcloud auth application-default login

a browser window will open, it will ask you for permission to authorize this application (you enter your Google Cloud Platform credentials to comfirm). Then you see something like this at the shell:

Credentials saved to file: [.../.config/gcloud/application_default_credentials.json]
These credentials will be used by any library that requests Application Default Credentials (ADC).

Google will send an email telling you that Google Auth Library was granted access to your Google Account
From now on, do this:

mos gcp-iot-setup --gcp-project PROJECT --gcp-region REGION --gcp-registry REGISTRY

As I said, this was some time ago, your mileage may vary.

Original Spanish text follows:

Las acciones a realizar son:
• cargar el dispositivo en la device registry
• generar las clave privada y pública
• subir la clave pública a la device registry
• obtener el certificado del broker de Google
• configurar el dispositivo con los datos de conexión de Cloud IoT Core correspondientes
• cargar clave privada y certificado de Google en el dispositivo
Afortunadamente, mos tool realiza todo esto por nosotros. Para ello, la primera vez que lo vayamos a hacer debemos autorizar la API que la herramienta utiliza, a través de gcloud. Si no lo hacemos, observaremos un mensaje como el siguiente:
Error: google: could not find default credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
/src/go/src/github.com/mongoose-os/mos/cli/gcp/gcp.go:55: failed to create GCP HTTP
client y si se nos ocurre hacer lo que allí dice, perderemos valioso tiempo de manera innecesaria.
Para generar las credenciales de autorización ejecutamos el siguiente comando:
$ gcloud auth application-default login
se abrirá nuestro navegador para consultarnos si realmente queremos autorizar a esa aplicación, deberemos ingresar con las credenciales de Google Cloud Platform y confirmarlo, y luego observaremos en el intérprete de comandos un mensaje similar al siguiente:
Credentials saved to file: […/.config/gcloud/application_default_credentials.json]
These credentials will be used by any library that requests Application Default Credentials (ADC).
luego, además, recibiremos un mail de Google avisándonos que Google Auth Library was granted access to your Google Account
De ahora en más, lo único que necesitamos hacer para cargar un dispositivo en GCP es ejecutar mos tool de la siguiente forma, con el dispositivo conectado:
mos gcp-iot-setup --gcp-project PROJECT --gcp-region REGION --gcp-registry REGISTRY
donde PROJECT, REGION y REGISTRY corresponden a datos que ingresamos al hacer el quickstart de Cloud IoT Core.

#3

Thank you so much, you saved my day