How to setup a flow to continuously read serial data

Hi all,

I'm a beginner at using Node-Red and I'm trying to set up a flow for reading data from an elm327 device. I'm looking for some guidance on how to set up multiple conditions where, when met, a specific set of requests (around 5-6) are sent to the device and the corresponding responses are continuously read, at a rate of 1 second let's say, as long as the condition is true.

For example, if condition 1 is met, send requests 1, 2, and 3 and continuously read their responses.

If condition 2 is met, send requests 4, 5, and 6 and continuously read their responses.

I would really appreciate any help or tips anyone can provide on this topic. Thank you in advance for your time and expertise!

Welcome to the forum @leb986

I don't understand what you mean by continuously read their responses, or do you mean you want to repeatedly send requests 1, 2 and 3 and get the response to each?

If so then which bits don't you know how to do? Have you successfully sent a request and recieved the response? If not then get that going first.

Then you could use two inject nodes, that trigger the sending of 1,2, 3 and 4,5,6, and use node-red-contrib-simple-gate to block the ones you don't want when the conditions are not right.

Correct, I would like to send an x number of requests and then read their responses all together at once. I do have this flow setup now that I am experimenting with

[
    {
        "id": "1836e27233fc6038",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "5938a26858a18295",
        "type": "inject",
        "z": "1836e27233fc6038",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "2",
        "topic": "",
        "payload": "ath0",
        "payloadType": "str",
        "x": 390,
        "y": 140,
        "wires": [
            [
                "06da870bcfea3f9e"
            ]
        ]
    },
    {
        "id": "9e69878382db4963",
        "type": "debug",
        "z": "1836e27233fc6038",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 950,
        "y": 160,
        "wires": []
    },
    {
        "id": "06da870bcfea3f9e",
        "type": "serial request",
        "z": "1836e27233fc6038",
        "name": "",
        "serial": "92c4fb6c.c8bcd8",
        "x": 730,
        "y": 160,
        "wires": [
            [
                "9e69878382db4963"
            ]
        ]
    },
    {
        "id": "be209b6af2ef617d",
        "type": "inject",
        "z": "1836e27233fc6038",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "1",
        "topic": "",
        "payload": "ATZ",
        "payloadType": "str",
        "x": 390,
        "y": 60,
        "wires": [
            [
                "06da870bcfea3f9e"
            ]
        ]
    },
    {
        "id": "49c8a7cb6d7cac62",
        "type": "inject",
        "z": "1836e27233fc6038",
        "name": "OneSec",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": true,
        "onceDelay": "1",
        "topic": "",
        "payload": "0110",
        "payloadType": "str",
        "x": 400,
        "y": 220,
        "wires": [
            [
                "06da870bcfea3f9e"
            ]
        ]
    },
    {
        "id": "f4ef79a93ebe4f88",
        "type": "inject",
        "z": "1836e27233fc6038",
        "name": "OneSec_1",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": true,
        "onceDelay": "1",
        "topic": "",
        "payload": "010C",
        "payloadType": "str",
        "x": 410,
        "y": 280,
        "wires": [
            [
                "06da870bcfea3f9e"
            ]
        ]
    },
    {
        "id": "75105030b834af7f",
        "type": "inject",
        "z": "1836e27233fc6038",
        "name": "OneSec_2",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": true,
        "onceDelay": "1",
        "topic": "",
        "payload": "010D",
        "payloadType": "str",
        "x": 410,
        "y": 340,
        "wires": [
            [
                "06da870bcfea3f9e"
            ]
        ]
    },
    {
        "id": "92c4fb6c.c8bcd8",
        "type": "serial-port",
        "serialport": "COM4",
        "serialbaud": "230400",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "waitfor": "",
        "dtr": "high",
        "rts": "high",
        "cts": "low",
        "dsr": "high",
        "newline": "\\n",
        "bin": "false",
        "out": "char",
        "addchar": "\\r\\n",
        "responsetimeout": "1000"
    }
]

However, if you notice from the gif, the responses are being outputted one at a time and not all at once. Also, the serial request node keeps saying "timeout" although it is outputting a response.

Flow

Ideally, I would like to have multiple "sets" of nodes just like the one I have and execute each set of sending commands based on a condition.

You have used the serial request node, that sends a request, waits for a reply, and passes on the reply to the flow. If you want to send the requests without waiting for a reply use separate serial in and out nodes.

I do want to read the response right after sending a request. I was just confused about why the serial request node is saying "timeout" but it's actually responding with the data. Also, what node can I use before all these injects and only have those injects send the commands if the node is True?

That confused me, as it appears to say you want to send them then receive the responses.

Your screenshot is completely unreadable on my machine, the debug output is much too small. Does it wait for 1 second before returning the response? If so that suggests that it is not finding the termination character (\n) so it sends it to you after the timeout, but I can't see what you are getting so I don't know.

See my previous post

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