# Decoding RSSI value from TTN?

**URL:** <https://forums.losant.com/t/decoding-rssi-value-from-ttn/5117>\
**Category:** Help\
**Tags:** workflow\
**Created:** [June 18, 2023, 8:16am UTC](https://forums.losant.com/t/decoding-rssi-value-from-ttn/5117 "2023-06-18T08:16:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![IgorP](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@IgorP](https://forums.losant.com/u/IgorP)\
**Post date:** [June 18, 2023, 8:16am UTC](https://forums.losant.com/t/decoding-rssi-value-from-ttn/5117/1 "2023-06-18T08:16:57Z")

</div>

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](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/a/aab9e4f7c6bbeb252220a50064b8edcb1e5d9e46.png)

So when I try to get this data it looks like this:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/b/b9b6b0ed0708fb14060ac0080585a3c2a8111368.png)

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…

---

<div class="post-metadata">

**Author:** ![Vander\_Maziero](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/vander_maziero/32/3428_2.png) [@Vander\_Maziero](https://forums.losant.com/u/Vander_Maziero)\
**Post date:** [June 19, 2023, 12:30am UTC](https://forums.losant.com/t/decoding-rssi-value-from-ttn/5117/2 "2023-06-19T00:30:55Z")

</div>

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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors#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:

```javascript
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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators) and [Accessing Payload Data](https://docs.losant.com/workflows/accessing-payload-data/) in Losant Documentation to facilitate development on the platform.

---

<div class="post-metadata">

**Author:** ![IgorP](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@IgorP](https://forums.losant.com/u/IgorP)\
**Post date:** [June 19, 2023, 5:54am UTC](https://forums.losant.com/t/decoding-rssi-value-from-ttn/5117/3 "2023-06-19T05:54:50Z")

</div>

Hello,

unfortunatelly it did not work for me?

![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/5/5b92d530b4d46464799a93eb9a808ecd852ef2f5.png)

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/0/0f54499fa1af92ce0423285d514454baca55619c.png)

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [June 20, 2023, 1:55pm UTC](https://forums.losant.com/t/decoding-rssi-value-from-ttn/5117/4 "2023-06-20T13:55:46Z")

</div>

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

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

```

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

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

```

---

<div class="post-metadata">

**Author:** ![IgorP](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@IgorP](https://forums.losant.com/u/IgorP)\
**Post date:** [June 21, 2023, 10:05am UTC](https://forums.losant.com/t/decoding-rssi-value-from-ttn/5117/5 "2023-06-21T10:05:11Z")

</div>

Hello,

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

```auto
{
  "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…

```auto
{
  "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:

```auto
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;

```

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [June 21, 2023, 12:32pm UTC](https://forums.losant.com/t/decoding-rssi-value-from-ttn/5117/6 "2023-06-21T12:32:34Z")

</div>

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?

 ![Screenshot 2023-06-21 at 8.32.16 AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/6/6885c5806741ac8233c219927c48965fce7d7752.jpeg)

---

<div class="post-metadata">

**Author:** ![IgorP](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@IgorP](https://forums.losant.com/u/IgorP)\
**Post date:** [June 21, 2023, 1:41pm UTC](https://forums.losant.com/t/decoding-rssi-value-from-ttn/5117/7 "2023-06-21T13:41:45Z")

</div>

Then I must be doing something stupid.

I will get back to you, thanks.

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [June 21, 2023, 1:45pm UTC](https://forums.losant.com/t/decoding-rssi-value-from-ttn/5117/8 "2023-06-21T13:45:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![IgorP](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@IgorP](https://forums.losant.com/u/IgorP)\
**Post date:** [June 21, 2023, 1:58pm UTC](https://forums.losant.com/t/decoding-rssi-value-from-ttn/5117/9 "2023-06-21T13:58:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![IgorP](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@IgorP](https://forums.losant.com/u/IgorP)\
**Post date:** [June 21, 2023, 2:48pm UTC](https://forums.losant.com/t/decoding-rssi-value-from-ttn/5117/10 "2023-06-21T14:48:17Z")

</div>

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.
