# Merge incoming tcp msg to a max of 5 lines

**URL:** <https://discourse.nodered.org/t/merge-incoming-tcp-msg-to-a-max-of-5-lines/41325>\
**Category:** General\
**Created:** [20 February 2021 00:19 UTC](https://discourse.nodered.org/t/merge-incoming-tcp-msg-to-a-max-of-5-lines/41325 "2021-02-20T00:19:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lumijb](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@lumijb](https://discourse.nodered.org/u/lumijb)\
**Post date:** [20 February 2021 00:19 UTC](https://discourse.nodered.org/t/merge-incoming-tcp-msg-to-a-max-of-5-lines/41325/1 "2021-02-20T00:19:31Z")

</div>

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:

> [@How to concatenate arrays](https://discourse.nodered.org/t/how-to-concatenate-arrays/464):
>
> Hi, How i can to concatenate 2 or 3 output(array 1D) of Modbus TCP client node in one array(1D) ? example : Modbus1 =\> msg.payload =\> [0, 0, 76, 71, 13] and Modbus2 =\> msg.payload =\> [5, 2, 5, 54, 21] Modbus3 =\> msg.payload =\> [9, 9, 9, 9, 9] i want to find in ouput msg.modbus [0, 0, 76, 71, 13, 5, 2, 5, 54, 21,9, 9, 9, 9, 9]. And how i can to change the output name of my modbustcpip, instead of having msg.payload i search to have msg.(Mytitle). Thank you for your help.

> [@Split strings (15 lines ASCII, max 20 char each) and store some of the lines in (INFLUX-) DB](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507):
>
> Gents, I could need a helpful hand in my dashboard-project! The content below shows, what the flow is getting in as strings from the TCP-node. It's a basically a info-package which is always triggered by multiple sensors. Challenges: A) Split these lines and give it each line a name (e.g. by topic, object, array...) B) Store some of the lines in a DB-table (INFLUX or MariaDB) ABC ABC ABC ID-Nr:12345 IP:000.000.000.000 ABC/ABC: 00- 01 Adresse:008-000 ML1- 8: -------- ML9-16: -------…

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [20 February 2021 10:07 UTC](https://discourse.nodered.org/t/merge-incoming-tcp-msg-to-a-max-of-5-lines/41325/2 "2021-02-20T10:07:16Z")

</div>

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

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![lumijb](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@lumijb](https://discourse.nodered.org/u/lumijb)\
**Post date:** [20 February 2021 15:58 UTC](https://discourse.nodered.org/t/merge-incoming-tcp-msg-to-a-max-of-5-lines/41325/3 "2021-02-20T15:58:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lumijb](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@lumijb](https://discourse.nodered.org/u/lumijb)\
**Post date:** [20 February 2021 16:16 UTC](https://discourse.nodered.org/t/merge-incoming-tcp-msg-to-a-max-of-5-lines/41325/4 "2021-02-20T16:16:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 February 2021 16:26 UTC](https://discourse.nodered.org/t/merge-incoming-tcp-msg-to-a-max-of-5-lines/41325/5 "2021-02-20T16:26:38Z")

</div>

it is html so try `<br/>`

---

<div class="post-metadata">

**Author:** ![lumijb](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@lumijb](https://discourse.nodered.org/u/lumijb)\
**Post date:** [20 February 2021 16:57 UTC](https://discourse.nodered.org/t/merge-incoming-tcp-msg-to-a-max-of-5-lines/41325/6 "2021-02-20T16:57:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 April 2021 16:57 UTC](https://discourse.nodered.org/t/merge-incoming-tcp-msg-to-a-max-of-5-lines/41325/7 "2021-04-21T16:57:51Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
