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 general information on using the HTTP bridge with Cloud 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 behalf of the device to Cloud IoT Core. Binary payload data must be base64-encoded.

For added security, you can use the device's JWT to send the message instead of the gateway's JWT. Whichever JWT you provide must match the device path of the request.

Using the gateway's JWT:

curl -X POST -H 'authorization: Bearer GATEWAY_JWT' -H 'content-type: application/json' --data '{"binary_data": "DATA", "gateway_info": {"delegated_device_id: "device-id"}}' -H 'cache-control: no-cache' 'https://cloudiotdevice.googleapis.com/v1/projects/{project-id}/locations/{cloud-region}/registries/{registry-id}/devices/{gateway-id}:publishEvent'

Using the device's JWT:

curl -X POST -H 'authorization: Bearer DEVICE_JWT' -H 'content-type: application/json' --data '{"binary_data": "DATA", "gateway_info": {"gateway_id: "gateway-id"}}' -H 'cache-control: no-cache' 'https://cloudiotdevice.googleapis.com/v1/projects/{project-id}/locations/{cloud-region}/registries/{registry-id}/devices/{device-id}:publishEvent'

Telemetry events are forwarded to a Cloud Pub/Sub topic, as specified in GCP 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 to it when using the HTTP bridge.

To get the device configuration that's currently available from Cloud IoT Core, use a getConfig request. You can include the JWT from either the gateway or the device in the authorization bearer header.

Using the gateway's JWT:

curl -X POST -H 'authorization: Bearer GATEWAY_JWT' -H 'content-type: application/json' --data '{"binary_data": "DATA", "gateway_info": {"delegated_device_id: "device-id"}}' -H 'cache-control: no-cache' 'https://cloudiotdevice.googleapis.com/v1/projects/{project-id}/locations/{cloud-region}/registries/{registry-id}/devices/{gateway-id}/config?local_version=0'

Using the device's JWT:

curl -X POST -H 'authorization: Bearer DEVICE_JWT' -H 'content-type: application/json' --data '{"binary_data": "DATA", "gateway_info": {"gateway_id: "gateway-id"}}' -H 'cache-control: no-cache' 'https://cloudiotdevice.googleapis.com/v1/projects/{project-id}/locations/{cloud-region}/registries/{registry-id}/devices/{device-id}/config?local_version=0'

Setting device state through the gateway

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

Using the gateway's JWT:

curl -X POST -H 'authorization: Bearer GATEWAY_JWT' -H 'content-type: application/json' --data '{"binary_data": "DATA", "gateway_info": {"delegated_device_id: "device-id"}}' -H 'cache-control: no-cache' 'https://cloudiotdevice.googleapis.com/v1/projects/{project-id}/locations/{cloud-region}/registries/{registry-id}/devices/{gateway-id}:setState'

Using the device's JWT:

curl -X POST -H 'authorization: Bearer DEVICE_JWT' -H 'content-type: application/json' --data '{"binary_data": "DATA", "gateway_info": {"gateway_id: "gateway-id"}}' -H 'cache-control: no-cache' 'https://cloudiotdevice.googleapis.com/v1/projects/{project-id}/locations/{cloud-region}/registries/{registry-id}/devices/{device-id}:setState'

Getting device state data

To retrieve device state data, view the device details in Cloud Console or use the API. For more details, see Getting device state data.

Esta página foi útil? Conte sua opinião sobre:

Enviar comentários sobre…

Cloud IoT Core Documentation