Decode Payload - Return Object in SenML format


#1

Hi all,

i want to write a short java codec function under “Application configuration” which return an object in SenML format for testing purpose, because the IOT platform mainflux requires SenML.

I tried:

function Decode(fPort, bytes) {
return {[“n”:“temperature”,“v”:1.2]};
}

But this is not working. Who can help me ?

Thanks in advance

Regards

Uli


#2

The syntax is wrong, it should be something like this (no square brackets and correct quote marks):

function Decode(fPort, bytes) {
    return {
      "n": "temperature",
      "v": 1.2
    };
}

#3

Hi legomez,

but the square brackets are required for the SenML format.

Regards

Uli


#4

Could you share a link to the format definition?


#6

Hi,

here is the Link to the ietf draft:

https://tools.ietf.org/id/draft-ietf-core-senml-16.txt

Thanks for your support.

Regards
Uli


#7

Ok, so I guess you are forwarding this through the http integration. In this case, the service receiving the data should extract the data from the js object. That is, at lora-app-server you may have something like this:

function Decode(fPort, bytes) {
    return {
      "SenMLdata" : [
          {"n": "temperature", "v": 1.2},
          {"n": "temperature", "v": 0.8},
      ]
    };
}

Then at the integration’s end you just need to read object["SenMlData"] to get your array. This has to be done this way because the Decode function must return a JS object, not an array.