Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To use ClearBlade IoT Core, you must create at least one device registry.

Console

1. Go to the ClearBlade IoT Core console’s Registries page.

2. At the top of the page, click ADD REGISTRY, then select Create registry.

3. Enter a registry ID and select a cloud region. For registry naming and size requirements, see Permitted characters and size requirements.

4. Select the protocols that devices in this registry will use to connect to ClearBlade IoT Core: MQTT, HTTP, or both.

5. Use the Pub/Sub service to create new Pub/Sub topics.

6. Click Create to continue.

API

Creating a registry code samples

...

Creating or editing a device

Console

1. Go to the ClearBlade IoT Core console’s Registries page.

2. Click the device registry’s ID.

3. Click Devices in the left registry menu.

4. Click Create a device.

...

To edit an existing device, click its ID on the Devices page and click Edit device at the top of the page.

5. Enter a device ID that describes or identifies the device. This field can't be edited later.

6. For Device communication, select Allow or Block. This option allows you to block communication when needed, such as when a device is not functioning properly. You'll most likely want to enable communication when creating the device.

7. If you're creating a new device, select the Input method you wish to use to enter the public key:

  • Manual: Copy and paste the public key into the Public key value field.

  • Upload: In the Public key value field, click Browse to select a file on your device.

8. Select the public key format that matches this device’s key pair. Paste the certificate or key in the Public key value field. You can also set the key’s expiration date.

...

To add a key to an existing device, click Add public key on the Device details page.

9. Use the Key and Value fields to add optional device metadata, such as a serial number.

10. Select a Cloud Logging level to determine which device events are sent to Cloud Logging.

11. Click Submit to create the device or Update to save changes to an existing device.

API

Use these methods to create or edit devices:

...

For ES256, the Device.credentials[i].public_key.key field must be set to the ec_public.pem contents (including the header and the footer). The Device.credentials[i].public_key.format field must be set to ES256_PEM or ES256_X509_PEM.

Creating a device with RSA credentials code samples

Node.js
Code Block
// const cloudRegion = 'us-central1';
// const deviceId = 'my-rsa-device';
// const projectId = 'adjective-noun-123';
// const registryId = 'my-registry';
import { DeviceManagerClient } from '@clearblade/iot';

const iotClient = new DeviceManagerClient({
  // optional auth parameters.
});

async function createDevice() {
  // Construct request
  const regPath = iotClient.registryPath(projectId, cloudRegion, registryId);
  const device = {
    id: deviceId,
    credentials: [
      {
        publicKey: {
          format: 'RSA_X509_PEM',
          key: readFileSync(rsaCertificateFile).toString()
        }
      }
    ]
  };

  const request = {
    parent: regPath,
    device
  };

  const [response] = await iotClient.createDevice(request);
  console.log('Created device', response);
}

createDevice();

...

Code Block
// createRSA creates a device in a registry given RSA X.509 credentials.
func createRSA(w io.Writer, projectID string, region string, registryID string, deviceID string, keyPath string) (*iot.Device, error) {
    ctx := context.Background()
    service, err := iot.NewService(ctx)
    if err != nil {
        return nil, err
    }

    keyBytes, err := ioutil.ReadFile(keyPath)
    if err != nil {
        return nil, err
    }

    device := iot.Device{
        Id: deviceID,
        Credentials: []*iot.DeviceCredential{
            {
                PublicKey: &iot.PublicKeyCredential{
                    Format: "RSA_X509_PEM",
                    Key:    string(keyBytes),
                },
            },
        },
    }

    parent := fmt.Sprintf("projects/%s/locations/%s/registries/%s", projectID, region, registryID)
    response, err := service.Projects.Locations.Registries.Devices.Create(parent, &device).Do()
    if err != nil {
        return nil, err
    }

    fmt.Fprintf(w, "Successfully created RSA256 X.509 device: %s", deviceID)

    return response, nil
}

Creating a device with Elliptic Curve (EC) credentials code samples

Node.js
Code Block
// const cloudRegion = 'us-central1';
// const deviceId = 'my-es-device';
// const projectId = 'adjective-noun-123';
// const registryId = 'my-registry';
import { DeviceManagerClient } from '@clearblade/iot';

const iotClient = new DeviceManagerClient({
  // optional auth parameters.
});

async function createDevice() {
  // Construct request
  const regPath = iotClient.registryPath(projectId, cloudRegion, registryId);
  const device = {
    id: deviceId,
    credentials: [
      {
        publicKey: {
          format: 'ES256_PEM',
          key: readFileSync(esCertificateFile).toString()
        }
      }
    ]
  };
  const request = {
    parent: regPath,
    device
  };

  const [response] = await iotClient.createDevice(request);
  console.log('Created device', response);
}

createDevice();

...

Getting device details

Console

1. Go to the ClearBlade IoT Core console’s Registries page.

2. Click the device registry’s ID.

3. Click Devices in the left menu.

4. Click the device ID to go to the Device details page. This page summarizes recent device activity, including the last time a message was published and the most recent error time. This page also shows the device numeric ID.

5. Click the Configuration & state history tab to see the device's recent configuration versions and update times.

The fields for the last heartbeat time and the last time a configuration was ACKed are for the MQTT bridge only. The HTTP bridge does not support heartbeat or explicit ACKs.

...

Deleting devices and registries

Console

You can delete one or more devices from the registry's device list.

To delete devices:

Delete devices

1. Go to the ClearBlade IoT Core console’s Registries page.

2. Click the device registry’s ID.

3. Click Devices in the left menu.

4. Select each device you want to delete, then click Delete.

5. Confirm you want to delete the selected devices, then click Delete.

API

Use these methods to delete devices and registries:

...