'How to use Enrichment Nodes in Thingsboard
Solution 1:[1]
I got my device attributes using originator attributes Enrichment Node in ThingsBoard
Solution 2:[2]
thank you for answer, I have successfully fetched server attributes of my device. Here are some materials how I did it for someone in the future:
Images:
Part of rule chain Enrichment - originator attributes
Script testing: (stackoverflow is trowing me some errors for not properly formatting code, so go on this): https://i.stack.imgur.com/85Cwi.png and https://i.stack.imgur.com/na1LK.png
Code from script (comments are in Croatian language if you wish to translate them):
//metadata.ImpFor_delta_hour je povjesna varijabla
//msg.ImpFor_delta_hour je upravo izracunati satna delta od ImpFor-a
if (typeof metadata.ImpFor_delta_5 !== 'undefined' && typeof metadata.ss_delta_ImpFor_min !== 'undefined' && typeof metadata.ss_delta_ImpFor_max !== 'undefined') { //ako nam nije dostavljen povjesni podatak ili nisu definirane granice
//ImpFor_delta_hour dolazi u obliku \"17\" (tocno s tim znakovima, nisam nista dodao)
var HIST_ImpFor = metadata.ImpFor_delta_5; //mozda nepotrebno, ali lakse je za raditi s varijablom
HIST_ImpFor = HIST_ImpFor.replace(/\"/g, ''); //micemo visak oko broja
HIST_ImpFor = parseInt(HIST_ImpFor); //string->integer
//po povjesnoj vrijednosti se stvaraju granice
var histDGranica = HIST_ImpFor * (metadata.ss_delta_ImpFor_min/100); //granice se definiraju za svaki node individualno u njihovim server atributes
var histGGranica = HIST_ImpFor * (metadata.ss_delta_ImpFor_max/100); //granice su deinirane kao % u server atributes, ali nam ovdje treba /100 (55%/100=0.55)
if (msg.ImpFor_delta_5 > histDGranica && msg.ImpFor_delta_5 < histGGranica){ //da li je nova delta unutar granica
return true;
}else{
return false;
}
}else{
return true; //ako nemamo povjesnog podatka ne mozemo procjeniti da li je ili nije unutar granica pa nema smisla dizati alarm
}
//throw new Error(HIST_ImpFor); //ako zelis isprintati neku variablu u error popup
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | shiyaz t |
Solution 2 |