Google Cloud Platform setup OTA


I am wondering if there is a way to do the below OTA?
mos gcp-iot-setup --gcp-project PROJECT --gcp-region REGION --gcp-registry REGISTRY
It seems I need to make these settings after each code flash to be able to connect with Google Cloud Platform and I would like to do it remotely.


Every time to flash, you erase the file system and replace it with a new one.
When you gcp-iot-setup, you generate a new key, update GCP servers with the public key, put private key and GCP certificate on the device, and update mos.yml with the proper parameters.
If you are developing, you can retrieve key and certificate from the device and store them on the fs directory on your machine, and copy the relevant contents of mos.yml to your projects’ mos.yml file.

$ mos get gcp-<id>.key.pem > fs/ gcp-<id>.key.pem
$ mos get gcp-lts-ca.pem > fs/gcp-lts-ca.pem

["gcp.ca_cert", "gcp-lts-ca.pem"]
["gcp.device", "<id>"]
["gcp.enable", true]
["gcp.key", "gcp-<id>.key.pem"]
["gcp.project", "<your project>"]
["gcp.region", "<your region>"]
["gcp.registry", "<your registry>"]
["gcp.server", "<your assigned server>:8883"]
["sntp.enable", true]

To do something over-the-air, you need to be connected to some network.
If you can connect to your device somehow other than GCP, you still have RPC available and should be able to setup the device for GCP remotely.
If you can only connect through GCP, you have rpc-gcp, but to connect to GCP you need GCP credentials, so you have to provide them inside the image you send.


Thanks for your reply! I have now saved the key and certificate on my local machine, and added the configs you listed in mos.yml. I am using mDash, where I can access my device and can use RPC, but am still not sure how to do mos gcp-iot-setup or corresponding with RPC if this is what I would need.


Using this method, you don’t gcp-iot-setup every time you flash but only once, since the device is already configured in GCP and you will provide proper credentials and configuration inside your image. You must also provide (preserve) any WiFi configuration needed, too.
I did not try remotely, I just did it when connected through the serial port.


Thanks a lot! This was great - seems to have done the trick!