Foxbat
Foxbat

Reputation: 352

How to Access New Telemetry Data in ThingsBoard Rule Chain Using JavaScript?

Body: I am working with ThingsBoard and trying to access the latest telemetry data in a rule chain when there is a new change. I'm using a script connected via the "Attributes Updated" connection type in my rule chain setup. While I can view user metadata successfully, I am unable to access the telemetry information.

For example, I have telemetry data with the key my_value, and its value is true. I need to access this value in a script within the rule chain. Here is my current setup:

Telemetry Key: my_value
Value: true

enter image description here

Rule Chain Configuration: Script and Attributes Updated However, the telemetry data does not appear to be processed or visible in the rule chain. Could someone guide me on how to properly configure my rule chain to access and process this telemetry data?

Updated :

Actually, I am planning to filter devices based on the user. Imagine there is a main user; this user allows other users to see information about certain devices or not. I am planning the following:

I created a table that is appeared in each device detaied state , that shows the username, and next to it, a checkbox that allows the main user to grant this user access to a device ( to which in you in deatied state). If it is true, the name of the device is written on the user's new telemetry or added because there could be more devices. Afterthat , I plan to filter the table based on the user telemetry information (device names) so that some users can see information about only some devices ( which the main user allowed).

Upvotes: 0

Views: 709

Answers (1)

Oluwafemi Sule
Oluwafemi Sule

Reputation: 38982

You can enrich telemetry information with server attributes configured for your device in Thingsboard cloud following these steps.

  1. Configure an outbound relation for your device.

    Set "From" relation to match your device name. This allows the rules engine to lookup the device through its device profile and read its server attributes as we'll come to see in the next step.

    Device relation

  2. Add a rule chain to enrich the device telemetry data.

    flow graph

    Configure the relation query for the device in the related device attributes node to query where "From originator Contains default". You can replace "default" with your device profile.

    Also select the server attributes configured for your device that you'd like to use for enrichment.

    device relation

  3. Add the enrichment rule chain in the root rule chain for the "Post Telemetry" message type.

    update root rule chain

    You can delete the "Save Timeseries" action for the "Post Telemetry" message
    in the root rule chain since this action is performed by the enrichment rule chain.

  4. Looking in the Latest telemetry for your device, you can find it to include your selected server attribute with the attribute name prefixed with "ss_"

    latest telemetry

Upvotes: 1

Related Questions