...
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 in this sectionbelow.
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.
...
Under Stackdriver Logging, select an activity log level for the gateway. The gateway's log level overrides its registry's log level.
...
8. Click Submit to create the gateway or Update to save changes to an existing gateway.To edit
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 the following these methods to create or edit a gateway:
...
Code Block |
---|
// getDevice retrieves a specific device and prints its details. func createGateway(w io.Writer, projectID string, region string, registryID string, gatewayID string, gatewayAuthMethod string, publicKeyPath string) (*iot.Device, error) { ctx := context.Background() service, err := iot.NewService(ctx) if err != nil { return nil, err } keyBytes, err := ioutil.ReadFile(publicKeyPath) if err != nil { return nil, err } gateway := &cloudiot.Device{ Id: gatewayID, Credentials: []*cloudiot.DeviceCredential{ { PublicKey: &cloudiot.PublicKeyCredential{ Format: "RSA_X509_PEM", Key: string(keyBytes), }, }, }, GatewayConfig: &cloudiot.GatewayConfig{ GatewayType: "GATEWAY", GatewayAuthMethod: gatewayAuthMethod, }, } parent := fmt.Sprintf("projects/%s/locations/%s/registries/%s", projectID, region, registryID) response, err := service.Projects.Locations.Registries.Devices.Create(parent, gateway).Do() if err != nil { return nil, err } fmt.Fprintln(w, "Successfully created gateway:", gatewayID) return response, nil } |
See Creating or editing a device to learn how to create the devices you'll use with the gateway.
...
With ClearBlade IoT Core, you can control a gateway by modifying its configuration, like any other device. See Configuring Devicesdevices to learn how to configure a gateway over the MQTT or HTTP bridge.
...
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.
Note: 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 the following these methods to bind a device to or unbind a device from a gateway:
...
Code Block |
---|
if (bBindUnBindDevice)
{
logger.LogInformation("Get configuration of a device");
// While running this sample, it is assumed that, device with name
// "Sample-New-Device" exists and Gateway with name "TestGateway" exists
// "Sample-New-Registry" is the registry name
// Sample - Bind Device
var result = await mClient.BindDeviceToGateway(4, "projects/developmentenv/locations/us-central1/registries/Sample-New-Registry", "TestGateway", "Sample-New-Device");
if (!result)
{
logger.LogError("Failed To Bind Device");
}
else
{
// Actual test - UnBind Device
result = await mClient.UnBindDeviceFromGateway(4, "projects/developmentenv/locations/us-central1/registries/Sample-New-Registry", "TestGateway", "Sample-New-Device");
if (!result)
logger.LogError("Failed to unbind a device");
else
logger.LogInformation("Successfully bind device");
}
} |
...
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 devices list method and specify a gateway ID to list all devices bound to the gateway.
...
Code Block |
---|
{
logger.LogInformation("Obtain list of devices for a particular registry and gateway");
// While running this sample, it is assumed that, gateway with name
// "associated-gateway" exists
GatewayListOptionsModel gatewayListOptions = new GatewayListOptionsModel()
{
AssociationsGatewayId = "associated-gateway",
};
var result = await mClient.GetDevicesList(4, "projects/developmentenv/locations/us-central1/registries/Sample-New-Registry", gatewayListOptions);
if (!result.Item1)
logger.LogError("Failed to get list of devices");
else
{
logger.LogInformation("Succeeded in getting the list of Devices");
// Use the list
}
} |
...
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 device list method to list all a registry’s gateways in a registry.
Listing
...
a registry’s gateways
...
code samples
Node.js
Code Block |
---|
// const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const registryId = 'my-registry'; import { DeviceManagerClient } from '@clearblade/iot'; const iotClient = new DeviceManagerClient({ // optional auth parameters. }); async function listDevices() { // Construct request const registryPath = iotClient.registryPath(projectId, cloudRegion, registryId); console.log('Current gateways in registry:'); const [response] = await iotClient.listDevices({ parent: registryPath, fieldMask: { paths: ['config', 'gateway_config'] }, gatewayListOptions: { gatewayType: 'GATEWAY' } }); const devices = response; devices.forEach((device) => { console.log('----\n', device); }); } listDevices(); |
...
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.
...
Enter the device ID to confirm and click Delete.
API
After unbinding the device from all gateways it's bound to, use the Device device delete method to delete the device.
...
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.
...
Enter the gateway's name to confirm, then click Delete.
API
After unbinding all devices from the gateway, use the Device device delete method to delete the gateway, specifying the gateway’s ID you want to delete.
...