Accessing DEV_EUI value from TTN message

In my application there are a certain number of data-loggers that acquire environmental data. They are all connected via the TTN network. The message payload contains, among other things, the serial number of the end node (4 bytes!!) which is derived from its MAC address. The same MAC address is also used to compose the DEV_EUI that the node uses to join the TTN network. Currently I have written a JavaScript payload formatter that unpacks the data contained in the payload and prepares them to be sent to my online database via a webhook.
Is there a programmatic method that allows me to extract the DEV_EUI from each message? This way I could reduce the size of each message from 13 to 9 bytes. The payload formatter doesn’t seem to be the solution since the payload doesn’t contain this information.

Not with the payload formatter.

Yes if you use parse the other JSON that you are sent along with the contents of the PF

No it’s nothing to do with me, I literally saw this post just after I sent mine :see_no_evil:

OK thanks. I will look for a solution to this problem taking into account your suggestion.

There isn’t much to look in to - you get a whole bunch of JSON which includes the results of the payload formatter. If you can read the PF JSON, then you can read the dev_eui field that’s included else where!

The start, note all the loverly id’s supplied …

"end_device_ids": {
      "device_id": "dtt-tt-soil-01",
      "application_ids": {
        "application_id": "descartes-tinythings-testzone"
      },
      "dev_eui": "DE5CA7777E570000",
      "join_eui": "DE5CA7FFFF777E57",
      "dev_addr": "260B0007"
    },
    "correlation_ids": [
      "as:up:01GQ5JE49JHVQZPBRSHMPD9ANW",
      "ns:uplink:01GQ5JE432NTHVY6EDYAJ46MX1",
      "pba:conn:up:01GPZWDA2M502WPEHSN0KS3K94",
      "pba:uplink:01GQ5JE42X9AYYFE7V9G0YGRX3",
      "rpc:/ttn.lorawan.v3.GsNs/HandleUplink:01GQ5JE432DN073RS21GFENYFF",
      "rpc:/ttn.lorawan.v3.NsAs/HandleUplink:01GQ5JE49HM8P526EPYY2VKERB"
    ],
    "received_at": "2023-01-19T17:50:13.297746419Z",

The middle with the decoded_payload not to be relied upon because it doesn’t all ways get created depending on server load:

    "uplink_message": {
      "session_key_id": "AYXFYQVSfW07+0dCaItp/w==",
      "f_port": 189,
      "f_cnt": 547,
      "frm_payload": "ADkJAAKEA3YGCgM8Bdw=",
      "decoded_payload": {
        "Analog1": 644,
        "Analog2": 886,
        "Analog3": 1546,
        "Analog4": 828,
        "BatteryV": 2.57,
        "DS18Temps": [
          13
        ],
        "DS18s": 1,
        "DigitalIO": 0,
        "DigitalIn1": 0,
        "DigitalIn2": 0,
        "DigitalIn3": 0,
        "DigitalOut": 0,
        "MCUtempC": 9,
        "flags": 0,
        "flagsText": ""
      },

The rest …

      "rx_metadata": [
        {
          "gateway_ids": {
            "gateway_id": "packetbroker"
          },
          "packet_broker": {
            "message_id": "01GQ5JE42X9AYYFE7V9G0YGRX3",
            "forwarder_net_id": "000013",
            "forwarder_tenant_id": "ttnv2",
            "forwarder_cluster_id": "ttn-v2-legacy-eu",
            "forwarder_gateway_eui": "DE5CA70000000000",
            "forwarder_gateway_id": "eui-de5ca70000000000",
            "home_network_net_id": "000013",
            "home_network_tenant_id": "ttn",
            "home_network_cluster_id": "eu1.cloud.thethings.network"
          },
          "rssi": -97,
          "channel_rssi": -97,
          "snr": 3,
          "location": {
            "latitude": 53.57029618,
            "longitude": -2.46078611,
            "altitude": 134
          },
          "uplink_token": "=",
          "received_at": "2023-01-19T17:50:13.081599982Z"
        }
      ],
      "settings": {
        "data_rate": {
          "lora": {
            "bandwidth": 125000,
            "spreading_factor": 7,
            "coding_rate": "4/5"
          }
        },
        "frequency": "867500000"
      },
      "received_at": "2023-01-19T17:50:13.090580307Z",
      "consumed_airtime": "0.066816s",
      "network_ids": {
        "net_id": "000013",
        "tenant_id": "ttn",
        "cluster_id": "eu1",
        "cluster_address": "eu1.cloud.thethings.network"
      }
    }
  }

Thank you,
in my application each uplink event raised by an end-node is connected to a webhook which transmits a request to my database server. The request contains JSON formatted information as you pointed out to me.
Currently I have chosen to apply the “up.uplink_message.decoded_payload” filter, however this filter generates JSON content that does not report the dev_eui of the device. I see the gateway EUIs but not the end node one. I’ve tried other available filters but I haven’t found one that also includes the dev_eui.
I’m probably making some mistake but I don’t understand where I’m wrong.

immagine

Sorry to be blunt, not sorry, but you’ve put a filter on the event data and you’re not getting the fields you need. :wink:

Perhaps remove the filter and then put a filter back once you have what you need and debug from there?

However as it’s a JSON path, you can’t have just the end_device_ids and decoded_payload.

I’d strongly recommend keeping the f_cnt as well - always useful for figuring out if a device has restarted.

wow! You were right to be blunt, it helped me :wink:
I had the solution under my eyes and I didn’t see it, in fact by removing any filter I got a much bigger JSON file but with much more information, including the much desired dev_eui
You helped me solve a problem, I also thank you for your patience :smiley: :+1:

Second pair of eye balls always helps!

Can you mark MY answer as the solution please!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.