A simple task for NR/ui_template, but the solution is not obvious to me!?
A text file is to be read and displayed as a list on a dashboard with ui_template.
The list is stored on a RPI and is read by NR ('read file') and converted to an object with '(msg.payload).split("\n")'.
However, in the subsequent 'template' with ng-repeat, the list is not generated as expected!?
Here is the flow:
flow_testfile.png.json (6.6 KB)
The main code part is this: (in 'Function List testing')
let msg1 = null; // INI1 part: test string
let ini1 = ["Zeile 1a", "Zeile 2, 11, 22, 33", "Zeile 3", "Zeile 4, 111, 222, 333, 444", "Zeile 5", "Zeile 6", "Zeile 7"];
let ptype1 = [typeof ini1]
msg1 = {
payload: ini1
}
let msg2 = null; // INI 2 part: handling the test.txt file / object
let ini2 = (msg.payload).split("\n");
let ptype2 = [typeof ini2]
msg2 = {
payload: ini2
}
let msg3 = null; // just check the type together with test text
msg3 = {
payload: [ini2, ptype2]
}
return [msg1, msg2, msg3];
The generated screen:
And Debug Listings with //comments:
node: debug test.txt // read test file
msg.payload : string[118]
"Zeile 1↵ Zeile 2, 11, 22, 33↵ Zeile 3↵ Zeile 4, 111, 222, 333, 444↵ Zeile 5, 5, 55, 555, 5555↵Zeile 6, 66↵Zeile 7, 7↵↵"
node: debug fct 1 // an example string handled in a separate template
msg.payload : array[7]
[ "Zeile 1a", "Zeile 2, 11, 22, 33", "Zeile 3", "Zeile 4, 111, 222, 333, 444", "Zeile 5", "Zeile 6", "Zeile 7" ]
node: debug fct 2 // test file converted to object
msg.payload : array[9]
[ "Zeile 1", " Zeile 2, 11, 22, 33", " Zeile 3", " Zeile 4, 111, 222, 333, 444", " Zeile 5, 5, 55, 555, 5555", "Zeile 6, 66", "Zeile 7, 7", "", "" ]
node: debug ini 1 // example string converted to object
msg.payload : array[7]
[ "Zeile 1a", "Zeile 2, 11, 22, 33", "Zeile 3", "Zeile 4, 111, 222, 333, 444", "Zeile 5", "Zeile 6", "Zeile 7" ]
node: debug ini 2 // output/passthru of 'template'
msg.payload : array[9]
[ "Zeile 1", " Zeile 2, 11, 22, 33", " Zeile 3", " Zeile 4, 111, 222, 333, 444", " Zeile 5, 5, 55, 555, 5555", "Zeile 6, 66", "Zeile 7, 7", "", "" ]
Who can shed some light on this? Any help / explanation is greatly appreciated