Google cloud platform GCP IoTCore赢得';t使用网关和HTTP网桥解析有效负载

Google cloud platform GCP IoTCore赢得';t使用网关和HTTP网桥解析有效负载,google-cloud-platform,google-cloud-iot,Google Cloud Platform,Google Cloud Iot,迄今采取的步骤 创建一个新密钥对,并将其用于即将创建的网关 创建一个网关,我们称之为“我的第一个网关” 创建一个新设备,我们称之为“gw\U设备\U 1” 将gw_设备_1与我的第一个\u网关关联 到目前为止效果很好 现在,我想使用HTTP网桥,使用my_first_网关的私钥,通过我的网关将gw_设备_1的状态数据发送到IoToCore,遵循本教程: 观察1:本教程中的URL似乎格式错误,在“委托设备id”的末尾缺少双引号: curl -X POST -H 'authorization: Be

迄今采取的步骤

  • 创建一个新密钥对,并将其用于即将创建的网关
  • 创建一个网关,我们称之为“我的第一个网关”
  • 创建一个新设备,我们称之为“gw\U设备\U 1”
  • 将gw_设备_1与我的第一个\u网关关联
  • 到目前为止效果很好

    现在,我想使用HTTP网桥,使用my_first_网关的私钥,通过我的网关将gw_设备_1的状态数据发送到IoToCore,遵循本教程:

    观察1:本教程中的URL似乎格式错误,在“委托设备id”的末尾缺少双引号:

    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'
    
    当我现在替换所有占位符并将“DATA”替换为“ewogICJhUHJvcCI6ICJhVmFsdWUiCn0”时,我执行以下curl(该标记显然不是真的):

    我收到这个错误:

    {
      "error": {
        "code": 400,
        "message": "Invalid JSON payload received. Unknown name \"binary_data\": Cannot find field.",
        "status": "INVALID_ARGUMENT",
        "details": [
          {
            "@type": "type.googleapis.com/google.rpc.BadRequest",
            "fieldViolations": [
              {
                "description": "Invalid JSON payload received. Unknown name \"binary_data\": Cannot find field."
              }
            ]
          }
        ]
      }
    }
    
    有趣的是:还有另一个“端点”用于将事件发布到IoCore。它具有相同的签名,但不是“setState”,而是以“publishEvent”结尾(请参见:)。 使用此方法执行完全相同的请求效果很好:

    curl -X POST -H 'authorization: Bearer GW_JWT_TOKEN' -H 'content-type: application/json' --data '{"binary_data": "ewogICJhUHJvcCI6ICJhVmFsdWUiCn0=", "gateway_info": {"delegated_device_id": "gw_device_1"}}' -H 'cache-control: no-cache' 'https://cloudiotdevice.googleapis.com/v1/projects/my_project_id/locations/europe-west1/registries/my_registry/devices/my_first_gateway:publishEvent'
    
    我错过什么了吗?
    感谢您的帮助。

    实际上,谷歌提供的curl是不正确的。 有效负载需要稍微调整,二进制数据字符串需要包装在一个名为“state”的对象中

    { "state": { "binary_data": "ewogICJhUHJvcCI6ICJhVmFsdWUiCn0=" }, "gateway_info": {"delegated_device_id": "gw_device_1"}}
    
    旋度然后按预期工作

    { "state": { "binary_data": "ewogICJhUHJvcCI6ICJhVmFsdWUiCn0=" }, "gateway_info": {"delegated_device_id": "gw_device_1"}}