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:
Create and configure the gateway if you haven't already.
Create devices if you haven't already.
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:
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).
The gateway's JWT.
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.