Pass device attributes into uplink JSON

I noted that in the v3 console, you can now define a set of attribute/values for each device.
Would it be possible to forward these attributes in the JSON uplink messages sent over MQTT?

In my use case this would be a very convenient feature.
My application is receiving airborne particulate matter / temperature / humidity telemetry and passing it on to sensor.community and opensensemap.org to display it on their maps.
For opensensemap, I need an id to correlate the measurement to a station defined in their backend.
If I could put the id in an attribute, and receive it in each uplink JSON message that would make my application completely stateless.
Also management of measurement nodes could then be done by someone other than myself: they just enter a new node in the console, by device EUI, add the attribute for opensensemap in an attribute and it all works without my intervention.ttnv3_device_attributes

1 Like

This is probably best achieved by holding a copy of the attributes in your incoming database and refreshing periodically or subscribing to an API feed for any changes.

Adding this in to a WebHook would require the Application server to retrieve the attributes for a device each time an uplink comes in. With about 600 a second on the whole TheThings infrastructure and set to double in the next 12-18 months, that’s a lot of extra database activity.

I searched a bit on the forum and found this older post:

So apparently, this was already possible on v2, I only found about it now. Setting attributes is only accessible through ttnctl, not the console web interface.

Now with v3, I noticed the text in the v3 console “Attributes can be used to set arbitrary information about the entity, to be used by scripts, or simply for your own organization.” However I have no idea how to actually use it in a script. I’m not seeing it in the v3 MQTT uplink message right now. In a way, I think, it’s not so different from other metadata, like the WGS84 position which is sent with the uplink message.

@descartes what kind of API feed could I use for this?

https://www.thethingsindustries.com/docs/reference/api/end_device/

Allows you to read all the data out - as I said, you would need to keep a local copy to link up in your database.

I’ve still got a few more weeks of reviewing the API’s to get the details in to my head so things may change over time.

1 Like

I implemented a REST API call to the device API in my Java application, seems to work fine.

If anyone wants to take a look:

2 Likes

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