Project for transfer data to GCP from ESP32
Wrote on PlatformIO Arduino Framework
-
Open
config/config.h
file -
Change
*ssid
and*password
variable to credentials for login in you wifi network -
Change
*project_id
,*location
,*registry_id
,*device_id
to your credentials from GCP Console -
Generate Public and Private ES256 key. Get the certificate for your region:
$ openssl req -x509 -newkey rsa:2048 -keyout iot-sample-device-rsa_private.pem -nodes -out rsa_cert.pem -subj /CN=unused $ openssl ecparam -genkey -name prime256v1 -noout -out iot-sample-device-ec_private.pem $ openssl ec -in iot-sample-device-ec_private.pem -pubout -out iot-sample-device-ec_public.pem $ cat rsa_cert.pem
-
Create in GCP Console IoT Core device and add public key
$ gcloud iot devices create iot-sample-device -region=europe-west1 -registry=iot-sample-registry -public-key=path=./iot-sample-device-ec_public.pem,type=es256
-
Get private key (must)
$ openssl ec -in iot-sample-device-ec_private.pem -noout -text read EC key Private-Key: (256 bit) priv: <PRIVATE KEY HERE> pub: <pub key> ASN1 OID: prime256v1 NIST CURVE: P-256
-
Insert Private key to
*private_key_str
and RSA certificate to*root_cert
-
Run code on the ESP32