Hey guys!
I need some help with this javascript function. You can see in the first picture that I have a payload with an: id, timestamp and value. But I want to change only the id to a better name then "104". In the second picture u see the payload that I want.
===>
To change from "104" to "Battery_Current" I have to use a Json payload where i can vind the correspnding name to the number.
I have wirten this code but ofcourse it doesn't work because I have no idea how to write something like this.
What does the code need to do: The payload comes in and stores the id ("104") then it looksup in the TMPmetaTable where id "104" is and then it gives me the corresponding namen. After it found the name the program replaces the current id "104" with the new "Battery_Current".
var TMPmetaTable =
{"Metadata":
{"0":{"name":"drive0_CurrentRPM","id":"101"},
"1":{"name":"drive1_CurrentRPM","id":"102"},
"2":{"name":"Battery_Voltage","id":"103"},
"3":{"name":"Battery_Current","id":"104"}}
};
var dataId = msg.payload.id;
var val = TMPmetaTable.Metadata.indexOf(dataID);
msg.payload.id = TMPmetaTable.Metadata[val].name;
return msg;
Thank you for helping and kind regards,
AxelD