Apyload decoder with dev_id

Hi is it possibile to get in the decoder output the dev_id of the device?
I have different devices in the same application and I would like to integrate this information in the output so to be able later in node red to discriminate …

possible ?
thanks regs
gp

The output from the decoder is embedded in to a message with the meta-data of the device, application and gateway ids, locations, timestamps and more. This is an MQTT message:

{
    "app_id": "descartes-room-monitor",
    "counter": 36259,
    "dev_id": "descartes-tt-indoor-002",
    "hardware_serial": "DE5CA7FFFFFFFFF9",
    "metadata": {
        "airtime": 56576000,
        "coding_rate": "4/5",
        "data_rate": "SF7BW125",
        "frequency": 868.1,
        "gateways": [
            {
                "altitude": 150,
                "channel": 0,
                "gtw_id": "eui-de5ca70000000001",
                "latitude": 53.34065,
                "longitude": -1.69435,
                "rf_chain": 0,
                "rssi": -60,
                "snr": 9,
                "time": "",
                "timestamp": 1084307099
            },
            {
                "channel": 0,
                "gtw_id": "eui-de5ca70000000002",
                "rf_chain": 0,
                "rssi": -82,
                "snr": 8.75,
                "time": "2020-08-11T14:58:40Z",
                "timestamp": 2928876931
            },
            {
                "altitude": 217,
                "channel": 0,
                "gtw_id": "eui-de5ca70000000000",
                "latitude": 53.32636,
                "longitude": -1.74385,
                "rf_chain": 0,
                "rssi": -78,
                "snr": 9,
                "time": "",
                "timestamp": 1692305843
            }
        ],
        "modulation": "LORA",
        "time": "2020-08-11T14:58:40.031208959Z"
    },
    "payload_fields": {
        "DHTHumidity": 50,
        "DHTTemp": 22,
        "DS18Temp": 24.31,
        "LDR": 339,
        "battery": 3.515,
        "flags": 0
    },
    "payload_raw": "AAOWCX8BUxYy",
    "port": 1
}

However you should not rely on the decoder as it’s fallback is to send / store the uplink without decoding if the servers are under load and the JS times out.

ok
what is the best way to handle an application where there are different devices with different payloads.

  • decode payloads in ttn with a super decoder script that can handle all cases ?
  • decode payloads later in the flow ?
  • split devices with same payload in different applications and decode them in ttn ?
  • or ?
    thanks
    kind regs
    gp

Here’s an HTTP Integration message:

{
    "app_id": "bradwell-hydro",
    "counter": 30,
    "dev_id": "bradwell-hydro-2019",
    "downlink_url": "https://integrations.thethingsnetwork.org/ttn-eu/api/v2/down/bradwell-hydro/bradwell-hydro-http?key=ttn-account-v2.REDACTED",
    "hardware_serial": "DE5CA7FFFFFFFFF8",
    "metadata": {
        "altitude": 160,
        "coding_rate": "4/5",
        "data_rate": "SF7BW125",
        "frequency": 868.1,
        "gateways": [
            {
                "altitude": 217,
                "channel": 0,
                "gtw_id": "eui-de5ca70000000000",
                "latitude": 53.32636,
                "longitude": -1.74385,
                "rf_chain": 1,
                "rssi": -89,
                "snr": 10.8,
                "time": "",
                "timestamp": 4224007899
            }
        ],
        "latitude": 53.326077,
        "location_source": "registry",
        "longitude": -1.740633,
        "modulation": "LORA",
        "time": "2019-12-26T13:16:43.067763258Z"
    },
    "payload_fields": {
        "AirTemp": 4.8,
        "BatteryA": 0,
        "BatteryV": 12.69,
        "Depth": 2,
        "GeneratorA": 0,
        "GeneratorV": 0,
        "LDR": 783,
        "LightsA": 0,
        "LightsV": 0,
        "RPM": 1,
        "Ultrasonic": 511,
        "WaterTemp": -127,
        "flags": 0
    },
    "payload_raw": "AAAAAAAE9QAAAAAAAM5kAeADDwH/AQI=",
    "port": 1
}

I believe the original thinking was that an application would have many (hundreds, thousands, more) devices that were all the same.

For smaller deployments, developmenting and for easy admin, I too end up with an amalgamation - particularly if it’s one of each prototype but all with different payloads.

You can use the port number to indicate which payload type it is - that comes free as it’s in the LoRaWAN header anyway. Or you could have a byte field - but why bother, you have the port number.

The application can only have one decoder script, so you’d then switch/branch on each port number to decide how to do it.

Or have an application each, which can be a PITA if it’s only got one device in it.

If you have one application, you end up with a bigger decoder. With a bit of careful design you can organise a lot of overlap so you could have a header set of fields that are the same across devices with the special fields separately under.

However, the nub of what I was trying to impart is that it is not guaranteed for TTN to run the decoder if the application server it hits is busy and the JS times out.

So regardless of how you develop, and a JS decoder is very useful for development purposes, you should really think in terms of decoding at your back end. Otherwise you could have a run of uplinks that don’t have the payload fields in, something interesting might be going on but you won’t know about it.

2 Likes