Decoding SenML

  • Platform information:
    • Hardware: virtual machine on Windows 10
    • OS: Ubuntu server 20.04
    • Java Runtime Environment: Zulu 8.46
    • openHAB version: openHABian 2.5.5

Hello there,

Lately I’m playing with some esp32 LoRaWAN boards for a little project where we keep track on how far a sprinkler reel is for on a farm. I have the LoRa part working.

I use the KPN things network to get the LoRa data to my MQTT server. This data exist out of SenML JSON format. Because of my experience with openHAB I thought it would be a good idea to use openHAB and openHABcloud to keep track of my data and send me massages if the reel is X% in.

SenML specification:

I made a little test in python to decode my data with the help of a library. This work partly bud it would be a lot of work to make an android app of some kind with python and it wouldn’t be very expendable. (I have a lot of other ideas involving LoRaWAN)

My coding skills in general are intermediate.
I’m a beginner in java.

My question:
I couldn’t find much about SenML and java and even less about openHAB and SenML. Is there here someone who have a little experience with SenML and openHAB who can help me with creating a decoder?

A MQTT payload look something like this:

Location data:

[{“bn”:“urn:dev:DEVEUI:0012AC00001B0345:”,“bt”:1.00000000E9},{“n”:“locOrigin”,“vs”:“KPNLORA”},{“n”:“latitude”,“u”:“lat”,“v”:51.00000},{“n”:“longitude”,“u”:“lon”,“v”:6.000000},{“n”:“radius”,“u”:“m”,“v”:529.000000},{“n”:“locAccuracy”,“u”:“%”,“v”:9999.0},{“n”:“locPrecision”,“u”:“%”,“v”:9999.0},{“n”:“locTime”,“vs”:“1591962942208”}]

And my own data:

[{“bn”:“urn:dev:DEVEUI:0012AC00001B0345:”,“bt”:1.59196398E9},{“n”:“payload”,“vs”:“0404070164000000”},{“n”:“port”,“v”:1.0}]

Thank you in advance.

Greetings,
Sander

JSON is JSON. The JSONPATH transformation should work with this just fine, unless the order of the entries in the array is not defined (e.g. locTime might be at some other location than the end). If that’s the case you might need to pull the raw JSON into a Rule to parse it or use the REGEX Transformation.

If you use Scripted Automation with Python or JavaScript there are libraries readily available to parse JSON.