1

I would like to see if they can help me with the creation of a variable, where I can change the labels of the MQTT message that is sent from my IoT devices, in order to make it easier and to select the correct parameters when creating a dashboard. .

Example:

This is the message received to my server.

[{"n": "model", "d": "iot-zigbee1783"}, {"n": "Relay", "ap": true}, {"t": "gateway", "ma": "0035DDf45VAIoT215"}]

What I want is to change the label "d" for "deviceIoT" and "ap" for "door sensor" also if it is possible to change the true or false of the door sensor for open and closed.

gre_gor
  • 6,669
  • 9
  • 47
  • 52
  • I think you could do this with the help of thingsboards rule chain. There is a rule-node called _script_ which can be used to transform messages. – lupz May 07 '20 at 09:43
  • Yes, that is what I am trying to do but I cannot get the script to run correctly. in the 2 messages that I want to change. Thank you for your answer. – Krlos Kmarillo May 07 '20 at 14:47

1 Answers1

0

You can do this with the help of Thingsboards rule-chain.

There is also an official tutorial for this:

https://thingsboard.io/docs/user-guide/rule-engine-2-0/tutorials/transform-incoming-telemetry/

They use the transformation-rule-node called script to convert temperatures from [°F] to [°C]. While this is not your use case, it shows you how to handle incoming telemetry before it is saved to the database.

You could do a mapping of value-keys like this:

var theCustomizedMessage = {};

theCustomizedMessage['customizedKey'] = msg['originalIncomingKey'];

return {msg: theCustomizedMessage, metadata: metadata, msgType: msgType};

Keep in mind that this might be contra-productive since you have to update the rule-node scripts, when something changes.

As an alternative option you can rename the key labels in the widget configuration. This will not help your dashboard developers. But a documentation document will do :)

I strongly recommend against the replacement of boolean values with strings ('closed', 'opened'). This is a job for the widgets (e.g. their value format functions).

lupz
  • 3,620
  • 2
  • 27
  • 43
  • Thank you very much for the help, I will consider managing the data from the script or from the dashboard and test which one works best for me. Once again, thank you so much. – Krlos Kmarillo May 08 '20 at 18:38