Decoding RSSI value from TTN?

Hello,

hit a little bump on the road. I am trying to get RSSI value from payload. Issue is that the data has “0” in it:

image

So when I try to get this data it looks like this:
image

So I guess the question is how to handle data paths that have a numeric value as a name? Sorry I really m a noob…

Hello @IgorP,

When I started to develop I also had the same doubt, it’s normal for someone who is starting.

To access objects in a list of values, or properties that start with a number, you need to use Bracket Notation, this also works for cases of variable names that start with specific symbols, according to the Javascript standard.

So to access the value of the variable, inside a function node, which seems to be the case, you could use payload.data.body.uplink_message.rx_metadata["0"].rssi or payload.data.body.uplink_message.rx_metadata[0].rssi.

However, to access the same variable in other nodes, it is necessary to use a dot before the bracket notation, that is, data.body.uplink_message.rx_metadata.[0].rssi, and in this case “0” should not be used inside quotation marks, as the nodes already render Strings Templates and Paths as strings, and thus would not work correctly.

Another interesting issue to know is that the bracket notation allows passing dynamic variables, such as:

var index = 0
payload.out = payload.data.body.uplink_message.rx_metadata[index].rssi

however this is only possible to use in function node, in Strings Templates and Paths it is not possible to pass dynamic variables in bracket notation.

I hope it helped, and I recommend checking the Javascript operations and Accessing Payload Data in Losant Documentation to facilitate development on the platform.

Hello,

unfortunatelly it did not work for me?

image

Can you provide the whole payload object? Based on what I am seeing here I would expect this to work in a Function Node:

payload.data.body.uplink_message.rx_metadata[0].rssi

And this to work in any string template referencing the same value in other nodes:

{{data.body.uplink_message.rx_metadata.[0].rssi}}

Hello,

sorry for late reply. Here is full packet from TTN:

{
  "name": "as.up.data.forward",
  "time": "2023-06-21T09:54:46.477384640Z",
  "identifiers": [
    {
      "device_ids": {
        "device_id": "eui-",
        "application_ids": {
          "application_id": "demo-rh-t-sensors"
        },
        "dev_eui": "redacted",
        "join_eui": "0000000000000000",
        "dev_addr": "redacted"
      }
    }
  ],
  "data": {
    "@type": "type.googleapis.com/ttn.lorawan.v3.ApplicationUp",
    "end_device_ids": {
      "device_id": "eui-redacted",
      "application_ids": {
        "application_id": "demo-rh-t-sensors"
      },
      "dev_eui": "redacted",
      "join_eui": "redacted",
      "dev_addr": "redacted"
    },
    "correlation_ids": [
      "as:up:redacted",
      "gs:conn:redacted",
      "gs:up:host:redacted",
      "gs:uplink:redacted",
      "ns:uplink:redacted",
      "rpc:/ttn.lorawan.v3.GsNs/HandleUplink:redacted",
      "rpc:/ttn.lorawan.v3.NsAs/HandleUplink:redacted"
    ],
    "received_at": "2023-06-21T09:54:46.472549279Z",
    "uplink_message": {
      "session_key_id": "redacted",
      "f_port": 1,
      "f_cnt": 468,
      "frm_payload": "uAs0QsKh4kF+AQ==",
      "decoded_payload": {
        "battery": 2.9458115183246076,
        "humidity": 28.328983306884766,
        "temperature": 45.011444091796875
      },
      "rx_metadata": [
        {
          "gateway_ids": {
            "gateway_id": "redacted",
            "eui": "redacted"
          },
          "timestamp": 424792863,
          "rssi": -102,
          "channel_rssi": -102,
          "snr": -7,
          "frequency_offset": "2457",
          "uplink_token": "redacted",
          "channel_index": 5,
          "received_at": "2023-06-21T09:54:46.266642855Z"
        },
        {
          "gateway_ids": {
            "gateway_id": "redacted",
            "eui": "redacted"
          },
          "time": "2023-06-21T09:54:46.246729Z",
          "timestamp": 2894703827,
          "rssi": -112,
          "channel_rssi": -112,
          "snr": -1.2,
          "location": {
            "latitude": 45.99987403687367,
            "longitude": 14.393074214458467,
            "altitude": 365,
            "source": "SOURCE_REGISTRY"
          },
          "uplink_token": "redacted",
          "received_at": "2023-06-21T09:54:46.286691156Z"
        }
      ],
      "settings": {
        "data_rate": {
          "lora": {
            "bandwidth": 125000,
            "spreading_factor": 7,
            "coding_rate": "4/5"
          }
        },
        "frequency": "868100000",
        "timestamp": 424792863
      },
      "received_at": "2023-06-21T09:54:46.268288992Z",
      "consumed_airtime": "0.061696s",
      "network_ids": {
        "net_id": "000013",
        "tenant_id": "ttn",
        "cluster_id": "eu1",
        "cluster_address": "eu1.cloud.thethings.network"
      }
    }
  },
  "correlation_ids": [
    "as:up:redacted",
    "gs:conn:redacted",
    "gs:up:host:redacted",
    "gs:uplink:redacted",
    "ns:uplink:redacted",
    "rpc:/ttn.lorawan.v3.GsNs/HandleUplink:redacted",
    "rpc:/ttn.lorawan.v3.NsAs/HandleUplink:redacted"
  ],
  "origin": "ip-10-100-13-125.eu-west-1.compute.internal",
  "context": {
    "tenant-id": "redacted"
  },
  "visibility": {
    "rights": [
      "RIGHT_APPLICATION_TRAFFIC_READ"
    ]
  },
  "unique_id": "redacted"
}

Let me fetch also Losant packet…

{
  "applicationId": "redacted",
  "applicationName": "redacted",
  "data": {
    "body": {
      "correlation_ids": [
        "as:up:redacted",
        "gs:conn:redacted",
        "gs:up:host:redacted",
        "gs:uplink:redacted",
        "ns:uplink:redacted",
        "rpc:/ttn.lorawan.v3.GsNs/HandleUplink:redacted",
        "rpc:/ttn.lorawan.v3.NsAs/HandleUplink:redacted"
      ],
      "end_device_ids": {
        "application_ids": {
          "application_id": "demo-rh-t-sensors"
        },
        "dev_addr": "redacted",
        "dev_eui": "redacted",
        "device_id": "eui-redacted",
        "join_eui": "redacted"
      },
      "received_at": "2023-06-21T10:13:49.507751820Z",
      "uplink_message": {
        "consumed_airtime": "0.061696s",
        "decoded_payload": {
          "battery": 2.9458115183246076,
          "humidity": 27.316165924072266,
          "temperature": 46.13832092285156
        },
        "f_cnt": 470,
        "f_port": 1,
        "frm_payload": "pI04QoKH2kF+AQ==",
        "network_ids": {
          "cluster_address": "eu1.cloud.thethings.network",
          "cluster_id": "eu1",
          "net_id": "000013",
          "tenant_id": "ttn"
        },
        "received_at": "2023-06-21T10:13:49.300129455Z",
        "rx_metadata": [
          {
            "channel_index": 6,
            "channel_rssi": -101,
            "frequency_offset": "2484",
            "gateway_ids": {
              "eui": "redacted",
              "gateway_id": "redacted"
            },
            "received_at": "2023-06-21T10:13:49.299051910Z",
            "rssi": -101,
            "snr": -4,
            "timestamp": 1567832571,
            "uplink_token": "*****REDACTED*****"
          },
          {
            "channel_index": 1,
            "channel_rssi": -110,
            "gateway_ids": {
              "eui": "redacted",
              "gateway_id": "redacted"
            },
            "location": {
              "altitude": 365,
              "latitude": redacted,
              "longitude": redacted,
              "source": "SOURCE_REGISTRY"
            },
            "received_at": "2023-06-21T10:13:49.319715386Z",
            "rssi": -110,
            "snr": -1.2,
            "time": "2023-06-21T10:13:49.287310Z",
            "timestamp": 4037743027,
            "uplink_token": "*****REDACTED*****"
          }
        ],
        "session_key_id": "redacted",
        "settings": {
          "data_rate": {
            "lora": {
              "bandwidth": 125000,
              "coding_rate": "4/5",
              "spreading_factor": 7
            }
          },
          "frequency": "868300000",
          "timestamp": 1567832571
        }
      }
    },
    "headers": {
      "accept-encoding": "gzip",
      "content-length": "1949",
      "content-type": "application/json",
      "user-agent": "TheThingsStack/3.26.1-rc0-SNAPSHOT-71f92a964 (linux/arm64)",
      "x-forwarded-for": "34.255.49.188",
      "x-forwarded-proto": "https",
      "x-real-ip": "34.255.49.188",
      "x-ssl-proto": "TLSv1.3",
      "x-tts-domain": "eu1.cloud.thethings.network"
    },
    "method": "post",
    "path": "/uplink",
    "query": {
    }
  },
  "flowId": "redacted",
  "flowName": "TTN Receiver",
  "flowVersion": "develop",
  "globals": {
    "LORA_NETWORK_SERVER_AUTH_TOKEN": "*****REDACTED*****"
  },
  "relayId": "000000000000000000000000",
  "relayType": "public",
  "time": "2023-06-21T10:13:49.569Z",
  "triggerId": "redacted",
  "triggerType": "webhook"
}

And here is what I have implemented into “Function” block:

payload.data.battery = payload.data.body.uplink_message.decoded_payload.battery;
payload.data.temperature = payload.data.body.uplink_message.decoded_payload.temperature;
payload.data.humidity = payload.data.body.uplink_message.decoded_payload.humidity;
payload.data.rssi = -37;
payload.data.snr = 10;

//payload.data.rssi = payload.data.body.uplink_message.rx_metadata.0.rssi;
payload.data.rssi = payload.data.body.uplink_message.rx_metadata[0].rssi;
payload.data.snr = payload.data.body.uplink_message.rx_metadata[0].snr;

That payload and that Function Node code seems to work fine for me; so are you still having issues or is what we recommended yesterday working for you?

Then I must be doing something stupid.

I will get back to you, thanks.

If you’re hitting an error message then please post it here. While the Function Node code you provided works for this exact payload, it could fail several different ways if the workflow received a request body in a different format - for example, if the property uplink_message or its sub-properties decoded_payload or rx_metadata were undefined. So yes, what you posted works, but some additional error handling should be added to guard against those cases.

I will, as soon as I get something worth posting, I will update you. The testing function I think I misconfigured the simulator.

As I said, I was doing something stupid, sorry about that.

1st mistake is probably misconfiguration of simulated output. 2nd mistake is that I was misspelling the payload packet used to load the data.

I had to accept the solution from the first guy, as he was right all along and I was already making a mess, but your solution is the same and valid.

Thanks for helping.