scoe
(Scoe)
April 15, 2024, 3:20pm
1
Hey folks,
some time ago we added some sensor for monitoring airquality. In Node Red we then prepare the received data (co2, temperature and humidity) to be conform with our data model.
Is there a way to add something like room or building for every sensor and send these data to Node Red as well?
Is this possible with self added attributes?
Best regards
Yes, you can add a device-specific attribute in the console.
However the device-attribute data is not sent with each MQTT uplink message. You need to fetch the attributes in a separate process.
See for example:
scoe
(Scoe)
April 15, 2024, 4:43pm
3
However the device-attribute data is not sent with each MQTT uplink message
Is there some logic behind this? Or what should I expect here?
Thanks your your help so far
kersing
(Jac Kersing)
April 15, 2024, 5:40pm
4
Yes, looking up the data is expensive for an environment handling millions of messages. So it’s delegated to a place with less load (your servers).
So get the data periodically and cache it, don’t issue a lookup on every message…
1 Like
Why do you not just have a lookup table, a MySQL table (for example). Using the eui as a key?
No extra load on the TTN server, and minimal load on yours.
1 Like
To fetch the device attributes, you can use the end device API, as described here: End Device APIs | The Things Stack for LoRaWAN
My application uses the EndDeviceRegistry.List call:
*/
public interface IEndDeviceRegistryRestApi {
// values to be passed to the fieldMask parameter
public static final String FIELD_IDS = "ids";
public static final String FIELD_NAME = "name";
public static final String FIELD_DESCRIPTION = "description";
public static final String FIELD_ATTRIBUTES = "attributes";
public static final String FIELD_VERSION_IDS = "version_ids";
// end device registry
@GET("/api/v3/applications/{application_id}/devices")
Call<EndDevices> listEndDevices(@Header("Authorization") String authToken,
@Path("application_id") String applicationId, @Query("field_mask") String fieldMask);
@GET("/api/v3/applications/{application_id}/devices/{device_id}")
Call<EndDevice> getEndDevice(@Header("Authorization") String authToken,
@Path("application_id") String applicationId, @Path("device_id") String deviceId,
@Query("field_mask") String fieldMask);
@PUT("/api/v3/applications/{application_id}/devices/{device_id}")
application_id = the id of the TTN application
Authorization header with an API key that allows permission to view the device properties (‘view devices in application’, perhaps also ‘view application information’)
field mask set to “ids,attributes”
2 Likes
scoe
(Scoe)
April 18, 2024, 10:09am
7
Sounds reasonable and should be enough for my purpose.