...
The lines below will take the payload's 14th and 15th octets and "re-structure" the values from "ABCD" to "0xCDAB" (per our example from the Introduction section, from "5019" to "0x19501950") → basically structure the message with temperature in hexadecimal format:
:local tempf [:pick ($adv->"data") 28 32]
:local temp ("0x".[:pick $tempf 2 4].[:pick $tempf 0 2])
Your second option is to convert the temperature from hexadecimal to decimal format using RouterOS (if you want to keep hexadecimal format - ignore this step). This can be achieved by "commenting" (adding "#") to the previous line (or removing it altogether) and "uncommenting" (removing the "#") from the upcoming line, like so:
# :local temp ("0x".[:pick $tempf 2 4].[:pick $tempf 0 2])
:local temp [$from88 [:pick $ad 28 32]]
...
You will be able to verify the results under the Latest telemetry section under the device you have created for ThingsBoard (in our example, we called the "device" KNOT):
The result is a successful MQTT post! From the screenshot above, we can see that the temp parameter is in hexadecimal format.
...
Select the value you wish to display in the widget (in our example, tempt temp) and click on the "Show on widget" button:
You will be able to browse the widgets in the window that pops up:
Click on the "Add to dashboard" button:
Select a new dashboard to be created or choose an existing dashboard that you already have pre-installed/pre-made. Click on "Add".
...
We have also added a second table and, as a result, our test dashboard looks like this:
In case we post the date in hexadecimal format
Our first table will display the value in the hexadecimal format as "0x192a" (raw value as we've sent it from the KNOT → the javascript for the table did not convert it to a decimal value yet) and our second table will display the value in a decimal format as "6442" (the javascript used for the table did convert the value from "0x192a" to "6442").
Because of the fact that the values in our tag's payload are in signed 8.8 fixed point format, we will need to divide the result by "256".
Enter the "Edit" mode and click on the "Edit widget" button:
Click on the "edit" button to edit the parameter temp:
In the popup window "Data key configuration" enable the checkbox "Use data post-processing function" and divide the returned value by 256 (return value/256;):
...
function f(p){
this.p = p;
}
f.prototype.calculate = function(mes){
let intValue = parseInt(mes, 16);
let sign = 1;
if(intValue & 0x8000) {
intValue = (~intValue + 1) & 0xFFFF;
sign = -1;
}
intValue = sign * intValue / Math.pow(2, this.p);
return intValue;
}
let res = new f(8);
return (res.calculate(value));
Our first table will display the value in the hexadecimal format as "0x192a" (raw value as we've sent it from the KNOT → the javascript for the table did not convert it to a decimal value yet) and our second table will display the value in a decimal format as "6442" (the javascript used for the table did convert the value from "0x192a" to "6442").
Because of the fact that the values in our tag's payload are in signed 8.8 fixed point format, we will need to divide the result by "256".
Enter the "Edit" mode and click on the "Edit widget" button:
Click on the "edit" button to edit the parameter temp:
In the popup window "Data key configuration" enable the checkbox "Use data post-processing function" and input the code shown below:
The code:
function f(p){
this.p = p;
}
f.prototype.calculate = function(mes){
let intValue = parseInt(mes, 16);
let sign = 1;
if(intValue & 0x8000) {
intValue = (~intValue + 1) & 0xFFFF;
sign = -1;
}
intValue = sign * intValue / Math.pow(2, this.p);
return intValue;
}
let res = new f(8);
return (res.calculate(value));
Save and apply the changes.
...