curleclipse-honohono

How to send telemetry in a batch with hono


I am able to send the telemetry data using hono adapter over HTTP, I'm using a cpp method.

when I send every feature one by one I see it reflected on DITTO Example of the generated jsonData for a single feature:

{"topic": "org.tip/dev1/things/twin/commands/modify","headers": {},"path": "/features/sensor1/properties/value","value": 1}

The problem is I added a bunch of features (sensors) and every time I want to send telemetry I am sending multiple HTTP calls in a short period of time. So now I want to batch them in groups. But It's not working. This is the jsonData generated:

{"topic": "org.tip/dev1/things/twin/commands/modify","headers": {},"data": 
 {path": "/features/sensor1/properties/value","value": 1},
 {path": "/features/sensor2/properties/value","value": 23},
 {path": "/features/sensor3/properties/value","value": 32},
 {path": "/features/sensor4/properties/value","value": 4},
 {path": "/features/sensor5/properties/value","value": 13},
 {path": "/features/sensor6/properties/value","value": 17}}

I receive HTTP Status Code: 202 so It's accepted but I would assume the json format it's wrong. Is there any reference or anyone know how the json should be generated


Solution

  • I found this works

    {
      "topic": "org.tip/dev1/things/twin/commands/modify",
      "headers": {},
      "path": "/features",
      "value": {
        "sensor1": { "properties": { "value": 1 } },
        "sensor2": { "properties": { "value": 1 } },
        "sensor3": { "properties": { "value": 1 } },
        "sensor4": { "properties": { "value": 1 } },
        "sensor5": { "properties": { "value": 1 } },
        "sensor6": { "properties": { "value": 1 } },
        "sensor7": { "properties": { "value": 1 } },
        "sensor8": { "properties": { "value": 1 } },
        "sensor9": { "properties": { "value": 1 } },
      }
    }