Search code examples
eclipse-honoeclipse-dittoeclipse-iot

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


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


Solution

  • 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