Add a IoT device in Google Cloud Platform (GCP) using IoT Cloud Tester
Devices connect to Google Cloud Platform and send/receive data through MQTT or HTTP.
IoT Cloud Tester application provides an easy interface to create devices in Google Cloud platform.
To create a device in Google Cloud project,
- Select the project.
- In the 'Devices' tab, select the region, registry and press 'Add Device'.
- Device ID is automatically generated but that can be changed.
Following information are required to create a gateway device in Google Cloud,
- Device ID
- Project ID
- Cloud Region
- Registry
- Authentication - RS256, ES256, RS256_X509, RS256_X509. IoT Cloud Tester defaults to RS256 for authentication.
- Data Model - This parameter is used by IoT Cloud Tester to auto-generate data for the device. IoT Cloud Tester application provides an option to create custom data models for devices. Sample data for the data model is available to preview when creating the device.
To create a device in GCP, a post request is made to the below URL. IoT Cloud Tester tool generates the key for the devices and includes it as a post parameter.
IoT Cloud Tester application creates the RS256 public/private keys and stores it on the local machine. These keys are used used for device authentication with GCP.
Private Key - C:\Program Files (x86)\IoT Cloud Tester\device_keys\dev_95661_priv.pem
Public Key = C:\Program Files (x86)\IoT Cloud Tester\device_keys\dev_95661_pub.pem
Request sent to GCP to create device
POST:https://cloudiot.googleapis.com/v1/projects/iot-cloud-tutorial/locations/asia-east1/registries/reg_193129/devices
{
"credentials" : [ {
"publicKey" : {
"format" : "RSA_PEM",
"key" : "-----BEGIN PUBLIC KEY-----\r\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApKM+KOAs883zp0LldTLM\r\nNTZHiAOd+r2jVThS82lBJN2VHnRkjH96XedXV79jbd5vSYOG+z8WX0UKTIWlnMMi\r\nwkgrHvA3OoEgmu8Zg+oEu4quZwsiu/WZ532lVKC50kvM9QYXSiGqYSqfSDLjbCV5\r\nHBGMZRRBZzlLpydX/ULOtkSI9qcH0OhPjUEmK6+wHDUTr5TKc8jB0+Fkz02FIfPq\r\nNxwTAJEoADRsL4akTINYy+nq3+GFEWaFv7ZZiZDYb15V/TEbPKuMVqLTVW3GbGbq\r\n/YvchuNVdoPOoZ98r9d1ndldYHiP1Hdh4ewOsyVsjlfgNVE91gJQds0ZecKoT/hy\r\nZwIDAQAB\r\n-----END PUBLIC KEY-----\r\n"
}
} ],
"id" : "dev_95661"
}
Response from GCP for device creation
{
"config" : {
"cloudUpdateTime" : "2021-05-06T13:52:11.759406Z",
"version" : 1
},
"credentials" : [ {
"expirationTime" : "1970-01-01T00:00:00Z",
"publicKey" : {
"format" : "RSA_PEM",
"key" : "-----BEGIN PUBLIC KEY-----\r\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApKM+KOAs883zp0LldTLM\r\nNTZHiAOd+r2jVThS82lBJN2VHnRkjH96XedXV79jbd5vSYOG+z8WX0UKTIWlnMMi\r\nwkgrHvA3OoEgmu8Zg+oEu4quZwsiu/WZ532lVKC50kvM9QYXSiGqYSqfSDLjbCV5\r\nHBGMZRRBZzlLpydX/ULOtkSI9qcH0OhPjUEmK6+wHDUTr5TKc8jB0+Fkz02FIfPq\r\nNxwTAJEoADRsL4akTINYy+nq3+GFEWaFv7ZZiZDYb15V/TEbPKuMVqLTVW3GbGbq\r\n/YvchuNVdoPOoZ98r9d1ndldYHiP1Hdh4ewOsyVsjlfgNVE91gJQds0ZecKoT/hy\r\nZwIDAQAB\r\n-----END PUBLIC KEY-----\r\n"
}
} ],
"id" : "dev_95661",
"name" : "projects/iot-cloud-tutorial/locations/asia-east1/registries/reg_193129/devices/3252538596013057",
"numId" : 3252538596013057
}
The added device can be viewed in the Google Cloud console.
https://console.cloud.google.com/iot/locations/asia-east1/registries/reg_193129/devices/details/dev_117826/overview?folder=&organizationId=&project=iot-cloud-tutorial