Creating, configuring, and managing gateways
Creating or editing a gateway
After you create a gateway, you can't change it to a non-gateway device. Ensure you've created a registry and a device key pair before completing the steps below.
Console
Create a new gateway
1. Go to the Registries page. Click a registry ID.
2. On the Registry details page, click Gateways and Add gateway to create a new gateway.
3. Enter a gateway ID that describes the gateway and helps you identify it (this field can't be edited later).
4. For Gateway communication, select Allow or Block. The latter allows you to block communication when needed, such as when a gateway or one or more devices bound to it are not functioning properly. You’ll most likely want to allow communication when creating the gateway. When a gateway is blocked, all devices bound to it are blocked from communicating with ClearBlade IoT Core.
5. Select the public key format that matches this gateway’s key pair. Paste the certificate or key in the Public key value field. You can also set the key’s expiration date.
6. Select the authentication method to use for devices bound to the gateway.
7. Use the Key and Value fields to add optional gateway metadata, such as a serial number.
8. Click Submit to create the gateway or Update to save changes to an existing gateway.
Edit an existing gateway
1. Go to the Registries page.
2. Click the gateway’s registry ID.
3. Click Registry details.
4. Click Gateways.
5. Click the gateway’s ID you want to edit.
6. 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 these methods to create or edit a gateway:
Creating or editing a gateway code samples
Node.js
// const cloudRegion = 'us-central1';
// const deviceId = 'my-unauth-device';
// const gatewayId = 'my-gateway';
// const projectId = 'adjective-noun-123';
// const registryId = 'my-registry';
// const gatewayAuthMethod = 'ASSOCIATION_ONLY';
import { DeviceManagerClient } from '@clearblade/iot';
const iotClient = new DeviceManagerClient({
 // optional auth parameters.
});
async function createDevice() {
 // Construct request
 const regPath = iotClient.registryPath(projectId, cloudRegion, registryId);
 console.log('Creating gateway:', gatewayId);
 let credentials = [];
 // if public key format and path are specified, use those
 if (publicKeyFormat && publicKeyFile) {
  credentials = [
   {
    publicKey: {
     format: publicKeyFormat,
     key: readFileSync(publicKeyFile).toString()
    }
   }
  ];
 }
 const device = {
  id: gatewayId,
  credentials: credentials,
  gatewayConfig: {
   gatewayType: 'GATEWAY',
   gatewayAuthMethod: gatewayAuthMethod
  }
 };
 const request = {
  parent: regPath,
  device
 };
 const [response] = await iotClient.createDevice(request);
 console.log('Created device:', response);
}
createDevice();
Â
C#
{
  logger.LogInformation("Create a new gateway");
  string id = "Sample-New-Gateway";
  string name = "projects/developmentenv/locations/us-central1/registries/Sample-New-Registry/Devices/Sample-New-Gateway";
  String keyText = File.ReadAllText("path/to/key");
  var credentials = new List<DeviceCredential>
  {
    new DeviceCredential()
    {
      PublicKey = new PublicKeyCredential()
      {
        Key = keyText,
        Format = "ES256_PEM"
      },
    }
  };
  var gatewayConfig = new GatewayConfig()
  {
    GatewayType = "GATEWAY",
    GatewayAuthMethod = "ASSOCIATION_ONLY"
  };
  var result = await mClient.CreateDevice(4, id, name, credentials, gatewayConfig);
  if (!result.Item1 || (result.Item2 == null))
    logger.LogError("Failed to create new device");
  else
  {
    logger.LogInformation("Successfully created new device");
    // The result.Item2 object can be used to refer to newly created device
  }
}
Â
Python
import os
import io
from clearblade.cloud import iot_v1
def create_gateway():
 project_id = 'YOUR_PROJECT_ID'
 cloud_region = 'us-central1'
 registry_id = 'your-registry-id'
 device_id = 'your-device-id'
 gateway_id = 'your-gateway-id'
 public_key_file = 'path/to/ec_public.pem'
 algorithm = 'ES256'
Â
 # Check that the gateway doesn't already exist
 exists = False
 client = iot_v1.DeviceManagerClient()
 parent = client.registry_path(project_id, cloud_region, registry_id)
 listDevicesRequest = iot_v1.ListDevicesRequest(parent=parent)
 devices = list(client.list_devices(request=listDevicesRequest))
 for device in devices:
  if device.id == gateway_id:
   exists = True
  print(
   "Device: {} : {} : {} : {}".format(
    device.id, device.num_id, device.config, device.gateway_config
   )
  )
 with io.open(public_key_file) as f:
  public_key = f.read()
 if algorithm == "ES256":
  public_key_format = iot_v1.PublicKeyFormat.ES256_PEM
 else:
  public_key_format = iot_v1.PublicKeyFormat.RSA_X509_PEM
 # TODO: Auth type
 gateway = iot_v1.Device(
  name=gateway_id,
  credentials=[{
   "publicKey": { "format": public_key_format, "key": public_key }
  }],
  gateway_config={
   "gatewayType": "GATEWAY",
   "gatewayAuthMethod": "ASSOCIATION_ONLY",
  }
 )
 if not exists:
  createDeviceRequest = iot_v1.CreateDeviceRequest(
   parent=parent,
   device=gateway
  )
  res = client.create_device(request=createDeviceRequest)
  print("Created Gateway {}".format(res))
 else:
  print("Gateway exists, skipping")
os.environ["CLEARBLADE_CONFIGURATION"] = "/path/to/your-credentials.json"
create_gateway()
Â
Go
See Creating or editing a device to learn how to create the devices you'll use with the gateway.
Configuring the gateway and getting state
With ClearBlade IoT Core, you can control a gateway by modifying its configuration, like 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 ensure it’s functioning properly.
Binding or unbinding a device
You can authenticate non-gateway devices to ClearBlade IoT Core by binding them to the gateway. Binding creates an association between the devices and the gateway that ClearBlade IoT Core checks to authenticate the devices.
Binding is required when using the HTTP bridge.
Console
1. Go to the Registries page.
2. Click the gateway’s registry ID.
3. Click Gateways, then click the gateway's ID.
4. On the Gateway details page, click Bound devices.
5. Click Bind device.
6. Select the devices you want to bind to the gateway, then click Bind.
7. To unbind a device, select the device in the Gateway details page, and click Unbind device and Unbind to confirm.
API
Use these 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
Binding a device to or unbinding a device from a gateway code samples
Node.js
Â
C#
Â
Python
Â
Go
Listing all devices bound to a gateway
Console
1. Go to the Registries page. Click the gateway’s registry ID.
2. Click Gateways, then click the gateway's ID.
3. On the Gateway details page, click Bound devices.
API
Use the devices list method and specify a gateway ID to list all devices bound to the gateway.
Listing all devices bound to the gateway code samples
Node.js
Â
C#
Â
Python
Â
Go
Listing all gateways in a registry
Console
1. Go to the Registries page.
2. Click a registry ID.
3. On the Registry details page, click Gateways to see a list of the registry’s gateways.
API
Use the device list method to list a registry’s gateways.
Listing a registry’s gateways code samples
Node.js
Â
C#
Â
Python
Â
Go
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 it from the registry.
Console
1. Unbind the device from every gateway it's bound to.
2. In the Device details page, click Delete.
API
After unbinding the device from all gateways it's bound to, use the device delete method to delete the device.
Deleting a device bound to a gateway code samples
Node.js
Â
C#
Â
Python
Â
Go
Deleting a gateway
To delete a gateway, you first unbind its devices and then delete the gateway from the registry.
Console
1. Unbind all devices from the gateway.
2. Go back to the Gateway details page and click Delete.
API
After unbinding all devices from the gateway, use the device delete method to delete the gateway, specifying the gateway’s ID you want to delete.
Deleting a gateway code samples
Node.js
Â
C#
Â
Python
Â