Merge incoming tcp msg to a max of 5 lines

Hello community,

Obligatory I am very green in node-red, but I am loving every second of it.
I am currently building an interface that receives intermittent TCP-IN messages, such as this:

19h12m55.301s : XX 3 CMD INPUT : Clear
19h14m24.859s : UI_COLOR_WINDOW::update_items = 0
19h14m49.803s : XX 3 CMD INPUT : Macro 1100

And would like to print on inside a text box those messages.
Here is where I just can't make it work properly:

  1. Ideally, the text box would contain a maximum of 200 new lines, erasing the first messages once 200 lines have been reached to continue printing information on screen.

  2. Having 200 lines may cause issue with the text box size, so I was looking into having a scrollbar to the textbox, but I cannot find any type of information.

  3. Sometimes the line contains more than 200 character, making the text box size constraint fail and the text goes beyond the text box - or part of the message gets clipped.

Any pointers at all will greatly help me I'm sure.
For reference, I've looked into the following:

Join string / Function node with custom JScript to concat the message (I couldn't make any of those work)

Ok, this example takes an input string adds it to a context store array, and limits it to 5 items. It the joins those 5 into a string, 1 item on each line. Hope it helps

[{"id":"fc897e5e.f485a8","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"($ran:=$floor($random()*3);\t[\"19h12m55.301s : XX 3 CMD INPUT : Clear\",\t\"19h14m24.859s : UI_COLOR_WINDOW::update_items = 0\",\t\"19h14m49.803s : XX 3 CMD INPUT : Macro 1100\"][$ran])","payloadType":"jsonata","x":150,"y":2320,"wires":[["6eec52d4.b58b64"]]},{"id":"6eec52d4.b58b64","type":"change","z":"5a245aa1.510164","name":"","rules":[{"t":"set","p":"hold","pt":"flow","to":"$append($flowContext(\"hold\"),[payload])[[-5..-1]]","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$join($flowContext(\"hold\"),\"\\n\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":2320,"wires":[["96985776.50d0c8"]]},{"id":"96985776.50d0c8","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":2220,"wires":[]}]
1 Like

This help me alot! I will keep digging on the change node and figure something out!
Thanks @E1cid

Hmm, it seems the ui_text node does not accept the '\n' special character. I'll try to find an alternative for new lines.

it is html so try <br/>

1 Like

Awesome, the html does work! Thanks alot for the help! Lots more to learn as I can see...