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

不打扰是莪最后的温柔 提交于 2020-04-30 08:11:05

问题


I was successfully able to connect Hono to Ditto using AMQP adapters and I got the following messages in the log. The value sent from the demo device registered in Hono is successfully received and updated in the Ditto thing.

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]

But when I tried to make a new connection (Hono - installed in a different server and ditto hosted in same server where the above successful connection is made). Connection is established and also when I try to send the messages from the demo devices registered in Hono to Ditto. I get the following response.

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

And when I try to retrieve connection metrices, I can see the increase in the metric count with respect to the number of messages sent from Hono.

But the only problem is the sensor values (temp and Humidity as in the above curl command) are not getting updated in the ditto thing.

I got the below error message in the log which says "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']

Please let me know if I am missing something. Thank you in advance.!!

More Information : The thingId in Ditto is org.eclipse.ditto:4816, Tenant Id in Hono - tenantAdapters, Device Registered in Hono - 4816 (tenantAdapters), Auth Id of the device - sensor0101, ConnectionId between Hono and Ditto - Gal-Connection-10


回答1:


Messages processed by Eclipse Ditto via AMQP (e.g. Hono) must be in the so called Ditto Protocol being a JSON based protocol which contains apart from other JSON fields the path field which is missing in your JSON (hence the error message "JSON did not include required </path> field!").

So you have at least 2 options to proceed:

  1. Instead of your JSON format {"temp": 23.09, "hum": 45.85} send a message in Ditto Protocol, e.g. have a look here for an example
  2. Use the Payload mapping feature of Ditto in order to specify a JavaScript function to invoke on all incoming messages from Hono in order to transform them into a valid Ditto Protocol message



回答2:


probably you are getting this failure since Ditto can't parse non ditto protocol messages. From reading your logs, I think your Ditto thing currently looks like this:

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

You could verify this by using a GET request to http://<your-ditto-address>:<your-ditto-gateway-port>/api/2/things/org.eclipse.ditto:4716.

Since you probably want to store the temperature and humidity to a feature of your thing, it would be best to not have the features as null, but already provide a feature with an ID for the value. Do this by creating a feature, e.g. with id 'environment' via a PUT to http://<your-ditto-address>:<your-ditto-gateway-port>/api/2/things/org.eclipse.ditto:4716/features/environment and content {}. Afterwards your thing should probably look like this:

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

Now back to your initial question: Ditto will only understand ditto protocol messages and therefore doesn't know what to do with your JSON object.

To solve this problem you have two options: 1. adding a payload mapping script for incoming messages to your connection. 2. publishing a ditto protocol message instead of the simple JSON object. This would then look something like this:

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

Note that I have specified the path /features/environment which will update the value of the environment feature of your thing.



来源:https://stackoverflow.com/questions/56941682/connecting-eclipse-hono-to-ditto-descriptioncheck-if-all-required-json-fie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!