将Eclipse Hono连接到Ditto-“ description”:“检查是否设置了所有必需的JSON字段。”},“ status”:400}“错误

时间:2019-07-08 19:46:22

标签: eclipse-hono eclipse-ditto eclipse-iot

我可以使用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命令中的温度和湿度)在同上中没有得到更新。

我在日志中收到以下错误消息,上面写着“描述”:“检查是否设置了所有必需的JSON字段。”},“状态”: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']

如果我缺少什么,请告诉我。预先谢谢你!!

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

2 个答案:

答案 0 :(得分:3)

由于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。为此,请创建一个功能,例如通过http://<your-ditto-address>:<your-ditto-gateway-port>/api/2/things/org.eclipse.ditto:4716/features/environment和内容{}的PUT将ID为“环境”。之后,您的内容应该看起来像这样:

{
    "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,它将更新您的事物的环境特征的值。

答案 1 :(得分:1)

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

因此,您至少有两个选择可以继续:

  1. 以同上协议发送消息,而不是JSON格式{"temp": 23.09, "hum": 45.85},例如看看here为例
  2. 使用Ditto的Payload mapping功能来指定JavaScript函数,以对来自Hono的所有传入消息进行调用,以将其转换为有效的Ditto Protocol消息