# Split strings (15 lines ASCII, max 20 char each) and store some of the lines in (INFLUX-) DB

**URL:** <https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507>\
**Category:** General\
**Created:** [25 November 2020 10:30 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507 "2020-11-25T10:30:04Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![George16](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/george16/32/32595_2.png) [@George16](https://discourse.nodered.org/u/George16)\
**Post date:** [25 November 2020 10:30 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/1 "2020-11-25T10:30:04Z")

</div>

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: --------  
ABC  
TPD:IP  
08:36:52 25.11.2000  
ABC  
ABC  
L:095630 09h41 25.11.17

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 November 2020 11:17 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/2 "2020-11-25T11:17:16Z")

</div>

Hi George,

firstly, if you have any control over what the TCP node is getting, you should reformat the data into a sensible & extensible format (like JSON) - then part (A) of your task would be super simple.

If you have no say over the format of data, then please explain what you expect that list of strings to become.

e.g.

```auto
ABC --> a payload of ABC
ABC --> a payload of ABC
ABC --> a payload of ABC
ID-Nr:12345 --> topic: "ID-Nr" payload: "12345"
IP:000.000.000.000 --> topic :"IP" payload: "000.000.000.000"
ABC/ABC: 00- 01 --> etc
Adresse:008-000 --> etc
ML1- 8: --------
ML9-16: --------
ABC
TPD:IP
08:36:52 25.11.2000
ABC
ABC
L:095630 09h41 25.11.17

```

Also, if you a expecting to write this to a DB, then you probably want all values in one object (so read up on the [`join` node](https://cookbook.nodered.org/basic/join-streams) for how to join messages into one object.

* * *

As for part (B) - worry about that later.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 November 2020 18:15 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/3 "2020-11-25T18:15:29Z")

</div>

Is that multiple lines in one message, or multiple messages?  
The best thing is to feed it into a debug node and show us what it looks like, then there should be less confusion. Also tell us what the result should look like.

---

<div class="post-metadata">

**Author:** ![George16](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/george16/32/32595_2.png) [@George16](https://discourse.nodered.org/u/George16)\
**Post date:** [25 November 2020 19:19 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/4 "2020-11-25T19:19:19Z")

</div>

Steve,  
thank you and here my feedback. Your example looks great. Yes, one object is what i want.  
Sry, I have problems to share my feedback in the same prof. format as you did...but I hope it's sufficient.

ABC --\> topic: "Info" payload: "Text"  
ABC --\> topic: "CustomerName" payload: "Text"  
ABC --\> topic: "Branch" payload: "Text"  
ID-Nr:12345 --\> topic: "ID-Nr" payload: "12345"  
IP:000.000.000.000 --\> topic :"IP" payload: "000.000.000.000"  
ABC/ABC: 00- 01 --\> topic: "GER/BER" payload: "12345"  
Adresse:008-000 --\> topic: "Adress\_008" payload: numeric (3)  
ML1- 8: -------- --\> topic: "ML1" payload: "12345678", mixed e.g. -1----7- or 123-567-  
ML9-16: -------- --\> topic: "ML9" payload: "12345678", mixed e.g. -1----7- or -23-5---8  
ABC --\> topic: "Status" payload: "Text"  
TPD:IP --\> topic :"TPD:IP" payload: "000.000.000.000"  
08:36:52 25.11.2000 --\> topic :"EMA\_DateTime" payload: numeric  
ABC --\> topic: "UGType" payload: "Text"  
ABC --\> topic: "Slot" payload: "Text"  
L:095630 09h41 25.11.17 --\> topic: "MessageID" payload: numeric "Text" (straight to DB-field)

---

<div class="post-metadata">

**Author:** ![George16](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/george16/32/32595_2.png) [@George16](https://discourse.nodered.org/u/George16)\
**Post date:** [27 November 2020 19:14 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/5 "2020-11-27T19:14:43Z")

</div>

Yes Colin, I will provide the payload by tomorrow (CET).

---

<div class="post-metadata">

**Author:** ![George16](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/george16/32/32595_2.png) [@George16](https://discourse.nodered.org/u/George16)\
**Post date:** [28 November 2020 10:34 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/6 "2020-11-28T10:34:57Z")

</div>

Gents, I very much appreciate your support!  
Here two examples from the payload and my feedback to Steve...now finally in a correct format.

Final goal is to store each line's content filtered (Steve) into DB-fields and publish it via INFLUXDB and GRAFANA and publish the whole message on one single status line in a dashboard.

Regarding those 8 digits in "ML1- 8:" and ML9-16:  
Each number reflects a status. So every digit needs it's field in in the DB.

**Example 1:**  
msg : Object  
oemphasized textbject  
topic: ""  
payload: "ML1- 8: ---4---- "  
\_session: object  
\_msgid: "ccd362ee.9476b"

**Example 2:**  
msg : Object  
object  
topic: ""  
payload: "L:096699 12h00 28.11.17 "  
\_session: object  
\_msgid: "21e210a1.d1a9"

```auto
ABC --> topic: "Info" payload: "Text"
ABC --> topic: "CustomerName" payload: "Text"
ABC --> topic: "Branch" payload: "Text"
ID-Nr:12345 --> topic: "ID-Nr" payload: "12345"
IP:000.000.000.000 --> topic :"IP" payload: "000.000.000.000"
ABC/ABC: 00- 01 --> topic: "GER/BER" payload: "12345"
Adresse:008-000 --> topic: "Adress_008" payload: numeric (3)
ML1- 8: -------- --> topic: "ML1-8" payload: "12345678", mixed e.g. -1----7-
ML9-16: -------- --> topic: "ML9-16" payload: "12345678", mixed e.g. -1----7-
ABC --> topic: "Status" payload: "Text"
TPD:IP --> topic :"TPD:IP" payload: "000.000.000.000"
08:36:52 25.11.2000 --> topic :"EMA_DateTime" payload: numeric
ABC --> topic: "UGType" payload: "Text"
ABC --> topic: "Slot" payload: "Text"
L:095630 09h41 25.11.17 --> topic: "MessageID" payload: numeric

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 November 2020 12:16 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/8 "2020-11-28T12:16:19Z")

</div>

Are you getting that sequence of messages one at a time via TCP or have you split them up from a single packet?

If they are individual messages how to you know which of the ABC messages is which?

---

<div class="post-metadata">

**Author:** ![George16](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/george16/32/32595_2.png) [@George16](https://discourse.nodered.org/u/George16)\
**Post date:** [28 November 2020 12:33 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/9 "2020-11-28T12:33:00Z")

</div>

TCP: I am getting that sequence of messages one at a time. So a 15-string sequence comes in.  
Triggers of this sequence of messages are external sensors.  
ABC 1-3: Each one needs a topic as described in Steve's example / my update.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 November 2020 14:04 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/10 "2020-11-28T14:04:47Z")

</div>

OK, so it is the order that matters. I would start by using a Join node to combine them all into a 15 element array. Then I think you will just have to write code in a Function node to go through the array and build a message for each one and send it on. You will need some error checking to recognise when there is one missing and presumably discard the lot in that case.

---

<div class="post-metadata">

**Author:** ![George16](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/george16/32/32595_2.png) [@George16](https://discourse.nodered.org/u/George16)\
**Post date:** [28 November 2020 16:21 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/11 "2020-11-28T16:21:42Z")

</div>

Thx Colin, so I have added the Join-node (mode manually, array, 15) and that looks already good.  
I have no experience in writing the code for the Function-node.  
Maybe you or anybody has the mood & time and would help me with that or shows me the direction.

---

<div class="post-metadata">

**Author:** ![George16](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/george16/32/32595_2.png) [@George16](https://discourse.nodered.org/u/George16)\
**Post date:** [23 December 2020 08:56 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/12 "2020-12-23T08:56:45Z")

</div>

Gents, a Python script is the current solution and it works pretty well.  
But I could need your help in how to extract the "\_value" which is in this example a 0 (zero).

![Bildschirmfoto 2020-12-23 um 09.38.34 (1)](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/ac783d53bc0077ede815e76aa3fa1c3511960535.jpeg)

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [23 December 2020 09:58 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/13 "2020-12-23T09:58:16Z")

</div>

If you hover over this in the debug window you will see there is an option to copy the path for each of the elements - which it will put into the clipboard.

You can then use a change node to move it to message payload etc

Craig

---

<div class="post-metadata">

**Author:** ![George16](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/george16/32/32595_2.png) [@George16](https://discourse.nodered.org/u/George16)\
**Post date:** [23 December 2020 10:14 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/14 "2020-12-23T10:14:11Z")

</div>

Craig, that works perfectly fine. Thank you very much👍

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [27 December 2020 00:38 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/15 "2020-12-27T00:38:39Z")

</div>

No worries - glad to help

Craig

---

<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:** [10 January 2021 00:38 UTC](https://discourse.nodered.org/t/split-strings-15-lines-ascii-max-20-char-each-and-store-some-of-the-lines-in-influx-db/36507/16 "2021-01-10T00:38:40Z")

</div>

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