...
You can create a gateway or edit an existing one using 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.
Use the following methods to create or edit a gateway:
...
-
To create a new gateway:
Go to the Registries page in Google 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 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.
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 Google 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.
API -
Use the following methods to create or edit a gateway:
Device
create
method (projects.locations.registries.devices.create) to add gateways to registriesDevice
patch
method (projects.locations.registries.devices.patch) to edit existing gateways
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 ClearBlade 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 ClearBlade 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.
...
Note: Binding is required when using the HTTP bridge.
Go to the Registries page in Google 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.
API -
Use the following methods to bind a device to or unbind a device from a gateway:
Registries
BindDeviceToGateway
method (projects.locations.registries.bindDeviceToGateway) to bind devices to gatewaysRegistries
UnbindDeviceFromGateway
method to unbind devices from gateways
...
(
...
projects.locations.registries.unbindDeviceFromGateway) to unbind devices from gateways
Listing all devices bound to a gateway
Use the Devices list
method and specify a gateway ID to list all devices bound to the gateway.
...
-
Go to the Registries page in Google 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.
API -
Use the Devices list
method (projects.locations.registries.devices.list) and specify a gateway ID to list all devices bound to the gateway.
Listing all gateways in a registry
Use the Device list
method to list all gateways in a registry.
...
-
Go to the Registries page in Google 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.
API -
Use the Device list
method (projects.locations.registries.devices.list) to list all gateways in a registry.
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.
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.
API -
After unbinding the device from all gateways it's bound to, use the Device delete
method to delete the device.
...
(projects.locations.registries.devices.delete) to delete the device.
Deleting a gateway
To delete a gateway, you first unbind its devices then delete the gateway from the registry.
Go back to the Gateway details page and click Delete.
Enter the gateway's name to confirm, then click Delete.
API -
After unbinding all devices from the gateway, use the Device delete
method (projects.locations.registries.devices.delete) to delete the gateway, specifying the ID of the gateway you want to delete.
Code Block |
---|
public static object DeleteDevice(string projectId, string cloudRegion, string registryId, string deviceId){
var cloudIoT = CreateAuthorizedClient();
// The resource name of the location associated with the key rings.
var name = $"projects/{projectId}/locations/{cloudRegion}/registries/{registryId}/devices/{deviceId}";
try
{
var res = cloudIoT.Projects.Locations.Registries.Devices.Delete(name).Execute();
Console.WriteLine($"Removed device: {deviceId}");
}
catch (Google.GoogleApiException e)
{
Console.WriteLine(e.Message);
if (e.Error != null) return e.Error.Code;
return -1;
}
return 0;} |