Skip to main content
Skip table of contents

Using gateways with the HTTP bridge

When you use a gateway with the HTTP bridge, you must bind the devices to the gateway. Before you begin, read Using the HTTP bridge for information on using the HTTP bridge with ClearBlade IoT Core.

To use gateways with the HTTP bridge:

  1. Create and configure the gateway if you haven't already.

  2. Create devices if you haven't already.

  3. Bind the devices to the gateway.

  4. Use the gateway to publish telemetry events and update a device's configuration.

Publishing the device's telemetry events through the gateway

After you've bound the device to the gateway, use the publishEvent method to publish telemetry events on the device’s behalf to ClearBlade IoT Core. Binary payload data must be base64-encoded.

Callers can use one of three tokens to send requests:

  1. The token obtained by clicking the API keys button (key icon) at the top-right of the Registry details page (referred to subsequently as registry token).

  2. The gateway's JWT.

  3. The device's JWT.

Using the registry token or gateway's JWT:

curl -X POST -H 'ClearBlade-UserToken: GATEWAY_JWT_OR_REGISTRY_TOKEN' -H 'Content-Type: application/json' --data '{"binaryData": BASE64_ENCODED_STRING, "gatewayInfo": {"delegatedDeviceId": "device-id"}}' 'https://us-central1.clearblade.com/api/v/4/webhook/execute/baa6bab40cb6959087ada3f0e9f401/cloudiotdevice_devices?name=URL_ENCODED_GATEWAY_NAME&method=publishEvent'

Using the registry token or device's JWT:

curl -X POST -H 'ClearBlade-UserToken: DEVICE_JWT_OR_REGISTRY_TOKEN' -H 'Content-Type: application/json' --data '{"binaryData": BASE64_ENCODED_STRING, "gatewayInfo": {"gatewayId": "gateway-id"}}' 'https://us-central1.clearblade.com/api/v/4/webhook/execute/baa6bab40cb6959087ada3f0e9f401/cloudiotdevice_devices?name=URL_ENCODED_DEVICE_NAME&method=publishEvent'

Telemetry events are forwarded to a Cloud Pub/Sub topic, as specified in the console or with the eventNotificationConfigs[i].pubsubTopicName field in the device registry resource. The publishEvent method provides an optional subFolder field for classifying telemetry events. To learn how to publish data from subfolders to separate Pub/Sub topics, see using the HTTP bridge.

Updating device configuration through the gateway

Gateways must explicitly request new configurations for the devices attached when using the HTTP bridge.

To get the device configuration available from ClearBlade IoT Core, use a getConfig request. You can include the JWT from the gateway or the authorization bearer header’s device.

Using the registry token or gateway's JWT:

curl -X GET -H 'ClearBlade-UserToken: GATEWAY_JWT_OR_REGISTRY_TOKEN' 'https://us-central1.clearblade.com/api/v/4/webhook/execute/baa6bab40cb6959087ada3f0e9f401/cloudiotdevice_devices?name=URL_ENCODED_GATEWAY_NAME&localVersion=0&gatewayInfo.delegatedDeviceId=DEVICE_ID'

Using the registry token or device's JWT:

curl -X GET -H 'ClearBlade-UserToken: DEVICE_JWT_OR_REGISTRY_TOKEN' 'https://us-central1.clearblade.com/api/v/4/webhook/execute/baa6bab40cb6959087ada3f0e9f401/cloudiotdevice_devices?name=URL_ENCODED_DEVICE_NAME&localVersion=0&gatewayInfo.gatewayId=GATEWAY_ID'

Setting device state through the gateway

Use a setState request to report the device state to ClearBlade IoT Core. State data must be base64-encoded. You can include the JWT from the gateway or the device in the authorization bearer header.

Using the registry token or gateway's JWT:

curl -X POST -H 'ClearBlade-UserToken: GATEWAY_JWT_OR_REGISTRY_TOKEN' -H 'Content-Type: application/json' --data '{"state": {"binaryData": BASE64_ENCODED_STRING}, "gatewayInfo": {"delegatedDeviceId": "device-id"}}' 'https://us-central1.clearblade.com/api/v/4/webhook/execute/baa6bab40cb6959087ada3f0e9f401/cloudiotdevice_devices?name=URL_ENCODED_GATEWAY_NAME&method=setState'

Using the registry token or device's JWT:

curl -X POST -H 'ClearBlade-UserToken: DEVICE_JWT_OR_REGISTRY_TOKEN' -H 'Content-Type: application/json' --data '{"state": {"binaryData": BASE64_ENCODED_STRING}, "gatewayInfo": {"gatewayId": "gateway-id"}}' 'https://us-central1.clearblade.com/api/v/4/webhook/execute/baa6bab40cb6959087ada3f0e9f401/cloudiotdevice_devices?name=URL_ENCODED_DEVICE_NAME&method=setState'

Getting device state data

View the Cloud console’s device details or use the API to retrieve device state data.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.