将 Eclipse Hono 连接到 Ditto - "description":"Check if all required JSON fields were set."},"status":400}" 错误

Connecting Eclipse Hono to Ditto - "description":"Check if all required JSON fields were set."},"status":400}" Error

我使用 AMQP 适配器成功地将 Hono 连接到 Ditto,并且在日志中收到以下消息。从在 Hono 中注册的演示设备发送的值已在 Ditto 事物中成功接收和更新。

connectivity_1_ad306c4c315b | 2019-07-08 21:12:05,434 INFO  [ID:AMQP_NO_PREFIX:TelemetrySenderImpl-35]  o.e.d.s.c.m.a.AmqpPublisherActor akka://ditto-cluster/system/sharding/connection/1/Insight-connection-1/pa/$a/c1/amqpPublisherActor2 - Response dropped, missing replyTo address: UnmodifiableExternalMessage [headers={orig_adapter=hono-http, device_id=4716, correlation-id=ID:AMQP_NO_PREFIX:TelemetrySenderImpl-35, content-type=application/vnd.eclipse.ditto+json, etag="hash:18694a24", orig_address=/telemetry, source=nginx:ditto}, response=true, error=false, authorizationContext=null, topicPath=ImmutableTopicPath [namespace=org.eclipse.ditto, id=4716, group=things, channel=twin, criterion=commands, action=modify, subject=null, path=org.eclipse.ditto/4716/things/twin/commands/modify], enforcement=null, headerMapping=null, sourceAddress=null, payloadType=TEXT, textPayload={"topic":"org.eclipse.ditto/4716/things/twin/commands/modify","headers":{"orig_adapter":"hono-http","device_id":"4716","correlation-id":"ID:AMQP_NO_PREFIX:TelemetrySenderImpl-35","content-type":"application/vnd.eclipse.ditto+json","etag":"\"hash:18694a24\"","orig_address":"/telemetry","source":"nginx:ditto"},"path":"/features","value":null,"status":204}, bytePayload=null']
things-search_1_8f2ad3dda4bf | 2019-07-08 21:12:05,593 INFO  [] o.e.d.s.t.p.w.s.EnforcementFlow  - Updating search index of <1> things
things-search_1_8f2ad3dda4bf | 2019-07-08 21:12:05,598 INFO  [] o.e.d.s.t.p.w.s.EnforcementFlow  - Got SudoRetrieveThingResponse <1> times
things-search_1_8f2ad3dda4bf | 2019-07-08 21:12:05,725 INFO  [] a.s.Materializer akka.stream.Log(akka://ditto-cluster/user/thingsSearchRoot/searchUpdaterRoot/StreamSupervisor-21) - [SearchUpdaterStream/BulkWriteResult] Element: BulkWriteResult[matched=1,upserts=0,inserted=0,modified=1,deleted=0]

但是当我尝试建立新连接时(Hono - 安装在不同的服务器上,同上托管在建立上述成功连接的同一服务器上)。连接已建立,并且当我尝试将消息从在 ​​Hono 中注册的演示设备发送到 Ditto 时。我收到以下回复。

vigkam@srvgal89:~$ curl -X POST -i -u sensor0101@tenantAdapters:mylittle -H 'Content-Type: application/json' -d '{"temp": 23.09, "hum": 45.85}'  http://srvgal89.deri.ie:8080/telemetry
HTTP/1.1 202 Accepted
content-length: 0

当我尝试检索连接指标时,我可以看到指标计数相对于从 Hono 发送的消息数有所增加。

但唯一的问题是传感器值(上述 curl 命令中的温度和湿度)没有得到更新。

我在日志中收到以下错误消息,上面写着 "description":"Check if all required JSON fields were set."},"status":400}"

connectivity_1_ad306c4c315b | 2019-07-08 21:34:17,640 INFO  [ID:AMQP_NO_PREFIX:TelemetrySenderImpl-13] o.e.d.s.c.m.a.AmqpPublisherActor akka://ditto-cluster/system/sharding/connection/23/Gal-Connection-10/pa/$a/c1/amqpPublisherActor2 - Response dropped, missing replyTo address: UnmodifiableExternalMessage [headers={content-type=application/vnd.eclipse.ditto+json, orig_adapter=hono-http, orig_address=/telemetry, device_id=4816, correlation-id=ID:AMQP_NO_PREFIX:TelemetrySenderImpl-13}, response=true, error=true, authorizationContext=null, topicPath=ImmutableTopicPath [namespace=unknown, id=unknown, group=things, channel=twin, criterion=errors, action=null, subject=null, path=unknown/unknown/things/twin/errors], enforcement=null, headerMapping=null, sourceAddress=null, payloadType=TEXT, textPayload={"topic":"unknown/unknown/things/twin/errors","headers":{"content-type":"application/vnd.eclipse.ditto+json","orig_adapter":"hono-http","orig_address":"/telemetry","device_id":"4816","correlation-id":"ID:AMQP_NO_PREFIX:TelemetrySenderImpl-13"},"path":"/","value":{"status":400,"error":"json.field.missing","message":"JSON did not include required </path> field!","description":"Check if all required JSON fields were set."},"status":400}, bytePayload=null']

如果我遗漏了什么,请告诉我。提前谢谢你。!!

更多信息: Ditto 中的 thingId 是 org.eclipse.ditto:4816, Hono 中的租户 ID - tenantAdapters, 在 Hono 中注册的设备 - 4816(tenantAdapters), 设备的授权 ID - sensor0101, Hono 和 Ditto 之间的 ConnectionId - Gal-Connection-10

Eclipse Ditto 通过 AMQP(例如 Hono)处理的消息必须在所谓的 Ditto Protocol 中,它是一个基于 JSON 的协议,除了其他 JSON 字段外,还包含 [=您的 JSON 中缺少 10=] 字段(因此出现错误消息 "JSON did not include required </path> field!")。

因此您至少有 2 个选项可以继续:

  1. 而不是您的 JSON 格式 {"temp": 23.09, "hum": 45.85} 以 Ditto 协议发送消息,例如看一下 here 的例子
  2. 使用 Ditto 的 Payload mapping 功能来指定一个 JavaScript 函数来调用来自 Hono 的所有传入消息,以便将它们转换为有效的 Ditto 协议消息

您遇到此故障可能是因为 Ditto 无法解析非同上协议消息。通过阅读您的日志,我认为您的 Ditto 目前看起来像这样:

{
  "thingId": "org.eclipse.ditto:4716",
  "features": null
}

您可以通过向 http://<your-ditto-address>:<your-ditto-gateway-port>/api/2/things/org.eclipse.ditto:4716 发送 GET 请求来验证这一点。

由于您可能希望将温度和湿度存储到事物的特征中,因此最好不要像 null 那样具有特征,但已经提供具有值 ID 的特征。通过创建一个功能来做到这一点,例如id 'environment' 通过 PUT 到 http://<your-ditto-address>:<your-ditto-gateway-port>/api/2/things/org.eclipse.ditto:4716/features/environment 和内容 {}。之后你的东西应该看起来像这样:

{
    "thingId": "org.eclipse.ditto:4716",
    "features": {
        "environment": {}
    }
}

现在回到您最初的问题:Ditto 只会理解 ditto 协议消息,因此不知道如何处理您的 JSON 对象。

要解决这个问题,您有两个选择: 1. 为传入消息添加有效负载映射脚本到您的连接。 2. 发布同上协议消息而不是简单的 JSON 对象。这看起来像这样:

vigkam@srvgal89:~$ curl -X POST -i -u sensor0101@tenantAdapters:mylittle -H 'Content-Type: application/json' -d '{ "topic": "org.eclipse.ditto/4716/things/twin/commands/modify", "path": "/features/environment", "value": {"temp": 23.09, "hum": 45.85} }'  http://srvgal89.deri.ie:8080/telemetry

请注意,我已指定路径 /features/environment,它将更新您事物的环境特征值。