This page explains how to create, configure, and manage gateways.
Creating or editing a gateway
You can create a gateway or edit an existing one using Cloud Console, or gcloud. After you create a gateway, you can't change it to a non-gateway device. Make sure you've created a registry and a device key pair before completing the steps in this section.
Console
To create a new gateway:
- Go to the Registries page in Cloud Console.
- Click the ID of the registry for the gateway.
- On the Registry details page, click Gateways, then click Add gateway to create a new gateway.
- Enter a Gateway ID that briefly describes the gateway or otherwise helps you identify it. (This field can't be edited later.) For information on gateway naming and size requirements, see Permitted characters and size requirements.
- For Gateway communication, select Allow or Block. This option allows you to block communication when needed, such as when a gateway or one or more devices bound to it are not functioning properly. In most cases, you'll want to allow communication when first creating the gateway. When a gateway is blocked, all devices bound to it are also blocked from communicating with Cloud IoT Core.
- Select the Public key format that matches the key pair for this gateway. Paste the certificate or key in the Public key value field. You can also set an expiration date for the key.
- Select the authentication method to use for devices bound to the gateway.
- Use the Key and Value fields to add optional gateway metadata, such as a serial number. For information on metadata key-value naming and size requirements, see Permitted characters and size requirements.
- Under Stackdriver Logging, select an activity log level for the gateway. The gateway's log level overrides its registry's log level.
- Click Create to create the gateway or Update to save changes to an existing gateway.
To edit an existing gateway:
- Go to the Registries page in Cloud Console.
- Click the ID of the registry for the gateway.
- Click Registry details.
- Click Gateways.
- Click the ID of the gateway you want to edit.
- Click Edit at the top of the page.
To add a key to an existing gateway, click Add public key on the Device details page.
gcloud
To create a gateway, run the gcloud iot devices create
command. You can create a gateway with either RS256 or ES256 credentials.
To create a gateway with RS256 credentials, run the following command:
gcloud iot devices create --device-type=gateway \ --project=PROJECT_ID \ --region=REGION \ --registry=REGISTRY_ID \ --public-key path=rsa_cert.pem,type=rs256 \ --auth-method={ASSOCIATION_ONLY|AUTH_TOKEN_ONLY|AUTH_TOKEN_AND_ASSOCIATION}
To create a gateway with ES256 credentials, run the following command:
gcloud iot devices create --device-type=gateway \ --project=PROJECT_ID \ --region=REGION \ --registry=REGISTRY_ID \ --public-key path=ec_public.pem,type=es256 \ --auth-method={ASSOCIATION_ONLY|AUTH_TOKEN_ONLY|AUTH_TOKEN_AND_ASSOCIATION}
To edit a gateway, run the gcloud iot devices update
command command. You can change various properties of the gateway, but you can't change it to a non-gateway device.
gcloud iot devices update DEVICE_ID \ --project=PROJECT_ID \ --region=REGION \ --registry=REGISTRY_ID \ --auth-method={ASSOCIATION_ONLY|AUTH_TOKEN_ONLY|AUTH_TOKEN_AND_ASSOCIATION}
API
Use the following methods to create or edit a gateway:
- Device
create
method to add gateways to registries - Device
patch
method to edit existing gateways
C#
Go
Java
Node.js
Python
Ruby
To learn how to create the devices you'll use with the gateway, see Creating or editing a device.
Configuring the gateway and getting state
With Cloud IoT Core, you can control a gateway by modifying its configuration, just as you would with any other device. See Configuring Devices to learn how to configure a gateway over the MQTT or HTTP bridge.
After a configuration has been applied to a gateway, the gateway can report its state to Cloud IoT Core. You can compare the gateway's state and its most recent configuration to make sure the gateway is doing what it's supposed to be doing.
Binding or unbinding a device
You can authenticate non-gateway devices to Cloud IoT Core by binding them to the gateway. Binding creates an association between the devices and the gateway that Cloud IoT Core checks to authenticate the devices.
Console
- Go to the Registries page in Cloud Console.
- Click the ID of the registry for the gateway.
- Click Gateways, then click the gateway's ID.
- On the Gateway details page, click Bound devices.
- Click Bind device.
- Select the devices you want to bind to the gateway, then click Bind.
- To unbind a device, select the device in the Gateway details page and click Unbind device, then click Unbind again to confirm.
gcloud
To bind a device to a gateway, run the gcloud iot devices gateways bind
command:
gcloud iot devices gateways bind --gateway=GATEWAY_ID \ --device=DEVICE_ID \ --project=PROJECT_ID \ --device-region=DEVICE_REGION \ --device-registry=DEVICE_REGISTRY \ --gateway-region=GATEWAY_REGION \ --gateway-registry=GATEWAY_REGISTRY
To unbind a device from a gateway, run the gcloud iot devices gateways unbind
command:
gcloud iot devices gateways unbind --gateway=GATEWAY_ID \ --device=DEVICE_ID \ --project=PROJECT_ID \ --device-region=DEVICE_REGION \ --device-registry=DEVICE_REGISTRY \ --gateway-region=GATEWAY_REGION \ --gateway-registry=GATEWAY_REGISTRY
API
Use the following methods to bind a device to or unbind a device from a gateway:
- Registries
BindDeviceToGateway
method to bind devices to gateways - Registries
UnbindDeviceFromGateway
method to unbind devices from gateways
C#
Go
Java
Node.js
Python
Ruby
Listing all devices bound to a gateway
Console
- Go to the Registries page in Cloud Console.
- Click the ID of the registry for the gateway.
- Click Gateways, then click the gateway's ID.
- On the Gateway details page, click Bound devices.
gcloud
To list all associations between a gateway and its devices, run the gcloud iot devices gateways list-bound-devices
command:
gcloud iot devices gateways list-bound-devices --gateway=GATEWAY_ID \ --registry=REGISTRY \ --region=REGION \ --project=PROJECT_ID
API
Use the Devices list
method and specify a gateway ID to list all devices bound to the gateway.
C#
Go
Java
Node.js
Python
Ruby
Listing all gateways in a registry
Console
- Go to the Registries page in Cloud Console.
- Click the ID of the registry for the gateway.
- On the Registry details page, click Gateways to see a list of all gateways in that registry.
gcloud
To list all gateways in a registry, run the gcloud iot devices list
command:
gcloud iot devices list \ --device-type=gateway DEVICE_ID \ --registry=REGISTRY_ID
API
Use the Device list
method to list all gateways in a registry.
C#
Go
Java
Node.js
Python
Ruby
Deleting devices bound to a gateway
To delete a device bound to a gateway, you first unbind the device from all gateways it's bound to, then delete the device from the registry.
Console
Unbind the device from every gateway it's bound to.
In the Device details page, click Delete.
Enter the device ID to confirm and click Delete.
gcloud
To list all gateways a device is bound to, run the gcloud iot devices list
command:
gcloud iot devices list DEVICE_ID \ --project=PROJECT_ID \ --registry=REGISTRY_ID \ --region=REGION
To unbind a device, run the gcloud iot devices gateways unbind
command:
gcloud iot devices gateways unbind --gateway=GATEWAY_ID \ --device=DEVICE_ID \ --project=PROJECT_ID \ --device-region=DEVICE_REGION \ --device-registry=DEVICE_REGISTRY \ --gateway-region=GATEWAY_REGION \ --gateway-registry=GATEWAY_REGISTRY
To delete a device, run the gcloud iot devices delete
command:
gcloud iot devices delete DEVICE_ID \ --project=PROJECT_ID \ --registry=REGISTRY_ID \ --region=REGION
API
After unbinding the device from all gateways it's bound to, use the Device delete
method to delete the device.
C#
Go
Java
Node.js
Python
Ruby
Deleting a gateway
To delete a gateway, you first unbind its devices then delete the gateway from the registry.
Console
- Unbind all devices from the gateway.
- Go back to the Gateway details page and click Delete.
- Enter the gateway's name to confirm, then click Delete.
gcloud
To unbind a device, run the gcloud iot devices gateways unbind
command:
gcloud iot devices gateways unbind --gateway=GATEWAY_ID \ --device=DEVICE_ID \ --project=PROJECT_ID \ --device-region=DEVICE_REGION \ --device-registry=DEVICE_REGISTRY \ --gateway-region=GATEWAY_REGION \ --gateway-registry=GATEWAY_REGISTRY
To delete a gateway, run the gcloud iot devices delete
command:
gcloud iot devices delete GATEWAY_ID
API
After unbinding all devices from the gateway, use the Device delete
method to delete the gateway, specifying the ID of the gateway you want to delete.
C#
Go
Java
Node.js
Python
Ruby
What's next
- Use the MQTT or HTTP bridge to relay messages and configuration data between the devices and Cloud IoT Core
- Review the Cloud IoT Core quotas and limits