How to split data from serial communication

How to split data from character 25 to 30 and 31 to 35?

I'm not sure I exactly understand your question, but the split node may be a start.

I mean split characters like my picture below, character number 26-34

image

I fear it is not going to be easy if they are blank or spaces.

Who or what is creating these messages?
It is just it may be easier if you can define a delimiter like a , between the fields

this message got from sensor, so I can't change it.
is there any solution for this problem?

Can you put a debug node where this message comes from and paste the message here (formatted) so I (and others) can see what it really looks like?

Sorry if that is not as easy as it sounds for you. No offense. How good are you with node-red?

[
    {
        "id": "87cdb5b3b0411da1",
        "type": "inject",
        "z": "8708c8565a0e32f0",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "H32022-11- 2 12:14:12 DAT11111111T22222222T33333333L 0 0 0 0 0 0 0V10.0A  0.00O   0.0",
        "payloadType": "str",
        "x": 350,
        "y": 80,
        "wires": [
            [
                "ae23bdfde7f32cd3"
            ]
        ]
    },
    {
        "id": "ae23bdfde7f32cd3",
        "type": "debug",
        "z": "8708c8565a0e32f0",
        "name": "debug 10",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 540,
        "y": 80,
        "wires": []
    }
]
1 Like

i want a function like this, how do i write it in node-red?

OK, thanks.

Let me have a look and I'll get back to you.

Tip:
That is the entire message. Fair enough.
The item of interest is the payload part.
Up near where you copied the message, there should be a little triangle.
Example.

Screenshot from 2022-11-02 15-56-58

Screenshot from 2022-11-02 15-57-08

and finally

Screenshot from 2022-11-02 15-57-21

Then all you get is the payload part.

(OCD sucks)

I think you nearly have what you want in Javascript.

Just something like:
let result = text.substr(1,4);

I'm no javascript person, but if you search for javascript substring I am sure you will get results.

Hi, thanks for your respone, proble solve with the string.slice

const string = msg.payload;
const bits = [["name1",2,5],["name2",5,8],["name3",8,13],["name4",13,19]];
msg.payload = bits.reduce((acc, arr) => {
    return Object.assign(acc, {[arr[0]]:string.slice(arr[1],arr[2])});
},{});
return msg;
let text = "Hello world!";
let result = text.substring(1, 4);

Quick search.

Seems a lot easier / like what you asked.
But if that works. :wink: