NodeRed TCP OUT Node Success Response

I have created a flow on nodered. NodeRed instance is receiving a request on MQTT broker and sending a request to TCP server. How Can I configure TCPOUT node to reply the response and send back the received message to mqtt broker if message is sent successful and send back. Please help I am blocked.

Use the TCP request instead of the TCP out node then connect that to an MQTT out.

1 Like

Hi Steve, Thanks for your reply.

When I am using the TCP request node, How can I recreate the complete request json. I submit the packet data to tcp. Do I need to maintain the temporary local cache or queue.
Request Json contain paramname, deviceId and other parameters, How can I send back the request json with success message.

I don't understand. In your first post you said you want to send the response from TCP to MQTT.

Now you are saying you want to send the data you transmitted to the TCP request to MQTT

I am not following.

Maybe you could do a sketch or flow chart that describes what you are trying to do. Or perhaps write this out in steps.

Also please include some sample data.

Hi Steve, Apologies for not being clear about my query. Let me explain you.
My Flow is
MQTTBroker -> TCPServer -> MQTTBroker
So I am getting a list of sensors and parameters list through mqtt broker. I need to update the sensor values using tcp protocol for which I am using TCP request node as you mentioned. After updating the sensor I want to send the response back with the success, error status.
Please find below the JSON. I have trying to do it using Complete Node, Catch Node, TCP Request Node, Split for list iteration but not able to configure complete end to end flow.
Request JSON

{
    "sensorList": [
        {
            "sensorId": "6131a8d409e2162ea1df532e",
            "protocol": "tcp",
            "paramList": [
                {
                    "paramName": "voltage",
                    "opValue": "220"
                }
            ]
        },
        {
            "sensorId": "6131a8d409e2162ea1d423432e",
            "protocol": "tcp",
            "paramList": [
                {
                    "paramName": "temp",
                    "opValue": "220",
                }
            ]
        }
    ]
}

Response JSON
{
    "sensorList": [
        {
            "sensorId": "6131a8d409e2162ea1df532e",
            "protocol": "tcp",
            "paramList": [
                {
                    "paramName": "voltage",
                    "opValue": "220",
                    "successCode": "",
                    "errorCode": ""
                }
            ]
        },
        {
            "sensorId": "6131a8d409e2162ea1d423432e",
            "protocol": "tcp",
            "paramList": [
                {
                    "paramName": "temp",
                    "opValue": "220",
                    "successCode": "",
                    "errorCode": ""
                }
            ]
        }
    ]
}

admin edit - surround code with triple backticks ``` to preserve formatting

Thanks in advance.

Sorry - I can't import your NR flow.
Might be a good idea to read this and try again.

To export a Node-RED flow, you can use the built-in export feature, which allows you to save your flows as a JSON file. This JSON file can be imported into another Node-RED instance or shared with others. Here's how you can do it:

  1. Open Node-RED: Make sure you have Node-RED running and access it through your web browser.

  2. Access the Node-RED Editor: Open the Node-RED editor in your web browser by navigating to the appropriate URL (usually http://localhost:1880 or the URL of your Node-RED server).

  3. Select the Flow: In the Node-RED editor, select the flow or flows that you want to export. You can click and drag your mouse to select multiple nodes or click on a blank space in the workspace to deselect any selected nodes.

  4. Open the Export Dialog:

    • Right-click on one of the selected nodes or the blank workspace.
    • Click on the "Export" option in the context menu.
  5. Choose the Export Type:

    • You will see several export options. Choose the one that suits your needs:
      • Clipboard: This option copies the selected flow to your clipboard as JSON text.
      • File: This option allows you to save the selected flow as a JSON file to your local machine.
  6. Export to Clipboard:

    • If you chose "Clipboard," the JSON representation of your flow will be copied to your clipboard. You can then paste it into a text editor or share it with others.
  7. Export to File:

    • If you chose "File," a file dialog will open. Choose a location on your local machine to save the JSON file and provide a name for the file.
  8. Save the JSON File:

    • Click the "Save" or "Export" button to save the JSON file to your specified location.

Your Node-RED flow is now exported as a JSON file. You can share this file with others or import it into another Node-RED instance using the import feature. To import a flow, open the Node-RED editor, right-click on the workspace, and select "Import." Then, choose the JSON file you exported and follow the import instructions.

ok, that makes much more sense.

  1. Are you managing, with the TCP Request node, to actually perform the updates?

  2. Show us an example of TCP request reply then

    • an update succeeds
    • an update fails
  3. Show us exactly WHAT should be sent to MQTT when

    • update is successful
    • update fails
1 Like
  1. Yes, I am making TCP request to perform updates.
  2. Below are the two cases:
    Success : When I am able to write values to sensor than update is successful
    Failure : If the update fail due to connection issue , or tcp server is down , the request is failed
    I get the below request over MQTT Broker. Where I need to update the two sensor mentioned values over tcp protocol
Request JSON
{
    "sensorList": [
        {
            "sensorId": "6131a8d409e2162ea1df532e",
            "protocol": "tcp",
            "paramList": [
                {
                    "paramName": "voltage",
                    "opValue": "220"
                }
            ]
        },
        {
            "sensorId": "6131a8d409e2162ea1d423432e",
            "protocol": "tcp",
            "paramList": [
                {
                    "paramName": "temp",
                    "opValue": "220",
                }
            ]
        }
    ]
}
  1. Once the update operation is performed, I need to send the response back in the same json based on success and failure status.
Response JSON
{
    "sensorList": [
        {
            "sensorId": "6131a8d409e2162ea1df532e",
            "protocol": "tcp",
            "paramList": [
                {
                    "paramName": "voltage",
                    "opValue": "220",
                    "successCode": "",
                    "errorCode": ""
                }
            ]
        },
        {
            "sensorId": "6131a8d409e2162ea1d423432e",
            "protocol": "tcp",
            "paramList": [
                {
                    "paramName": "temp",
                    "opValue": "220",
                    "successCode": "",
                    "errorCode": ""
                }
            ]
        }
    ]
}

This is the flow I am trying.

Thanks in advance.

Can you post a demo flow without MQTT nodes (use an inject with sample data). For the TCP node, you can either leave it in and simulate the endpoint with a separate "TCP-in -> something/function -> TCP out" flow OR just use a function node to fake the TCP request and reply with realistic data.

Once you have done that, I (or someone) can take a shot at this for you.

Sample Flow


[
    {
        "id": "408c50b493cacaff",
        "type": "tab",
        "label": "Flow 4",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "2b0772d7c3e60c0b",
        "type": "inject",
        "z": "408c50b493cacaff",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{ \t\"deviceId\":\"DV101\",     \"sensorList\": [         {             \"sensorId\": \"6131a8d409e2162ea1df532e\",             \"protocol\": \"tcp\",             \"paramList\": [                 {                     \"paramName\": \"voltage\",                     \"opValue\": \"220\"                 }             ]         }     ] }",
        "payloadType": "json",
        "x": 130,
        "y": 140,
        "wires": [
            [
                "4e5e2ac2f32b1577",
                "d0ef906867ef10e5"
            ]
        ]
    },
    {
        "id": "4e5e2ac2f32b1577",
        "type": "function",
        "z": "408c50b493cacaff",
        "name": "function 11",
        "func": "console.log(msg.payload);\nconst obj = msg.payload.sensorList[0].paramList[0].opValue;\nmsg.payload = obj;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 310,
        "y": 120,
        "wires": [
            [
                "47d4f63baf757a22",
                "d0ef906867ef10e5"
            ]
        ]
    },
    {
        "id": "47d4f63baf757a22",
        "type": "tcp request",
        "z": "408c50b493cacaff",
        "name": "noderedtcp",
        "server": "localhost",
        "port": "8733",
        "out": "time",
        "ret": "string",
        "splitc": "100",
        "newline": "",
        "trim": false,
        "tls": "",
        "x": 510,
        "y": 140,
        "wires": [
            [
                "aaf77fd995ad323e"
            ]
        ]
    },
    {
        "id": "aaf77fd995ad323e",
        "type": "function",
        "z": "408c50b493cacaff",
        "name": "function 12",
        "func": "//Response JSON\n//{ \"_msgid\": \"ddc851200e518367\", \"payload\": { \"deviceId\": \"DV101\", \"sensorList\": [{ \"sensorId\": \"6131a8d409e2162ea1df532e\", \"protocol\": \"tcp\", \"paramList\": [{ \"paramName\": \"voltage\", \"opValue\": \"220\" , \"successCode\":\"\",\"errorCode\":\"\" }] }] } }\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 690,
        "y": 120,
        "wires": [
            [
                "21dda0c2d1aa80fa"
            ]
        ]
    },
    {
        "id": "d0ef906867ef10e5",
        "type": "debug",
        "z": "408c50b493cacaff",
        "name": "debug 25",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 500,
        "y": 100,
        "wires": []
    },
    {
        "id": "f98dafd5380a171c",
        "type": "complete",
        "z": "408c50b493cacaff",
        "name": "",
        "scope": [
            "47d4f63baf757a22"
        ],
        "uncaught": false,
        "x": 270,
        "y": 180,
        "wires": [
            [
                "1797345b30eb2d4d",
                "bd04fd0313a3ea7a"
            ]
        ]
    },
    {
        "id": "1797345b30eb2d4d",
        "type": "debug",
        "z": "408c50b493cacaff",
        "name": "debug 27",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 480,
        "y": 220,
        "wires": []
    },
    {
        "id": "bd04fd0313a3ea7a",
        "type": "function",
        "z": "408c50b493cacaff",
        "name": "function 13",
        "func": "//Response JSON\n//{ \"_msgid\": \"ddc851200e518367\", \"payload\": { \"deviceId\": \"DV101\", \"sensorList\": [{ \"sensorId\": \"6131a8d409e2162ea1df532e\", \"protocol\": \"tcp\", \"paramList\": [{ \"paramName\": \"voltage\", \"opValue\": \"220\" , \"successCode\":\"\",\"errorCode\":\"\" }] }] } }\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 490,
        "y": 180,
        "wires": [
            [
                "5ff106c3636a8b3f",
                "21dda0c2d1aa80fa"
            ]
        ]
    },
    {
        "id": "5ff106c3636a8b3f",
        "type": "debug",
        "z": "408c50b493cacaff",
        "name": "debug 28",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 220,
        "wires": []
    },
    {
        "id": "21dda0c2d1aa80fa",
        "type": "mqtt out",
        "z": "408c50b493cacaff",
        "name": "mqtt out",
        "topic": "device/sensor",
        "qos": "2",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "7efc68e1a8b9d197",
        "x": 820,
        "y": 180,
        "wires": []
    },
    {
        "id": "7efc68e1a8b9d197",
        "type": "mqtt-broker",
        "name": "mqtt in",
        "broker": "test.mosquitto.org",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]

Sorry, that sample flow is not entirely clear what you are expecting to send to MQTT AFTER success/fail.

For example, you have not created a tcp-in -> send_fake_but_valid_data ->tcp-out

Good - ok. I understand that.

If you get a "list of sensors" then how do you "update the sensor"?
What is the relevant parts of the incoming data?
What is the data to be sent to TCP (an exact example please)
Are you expecting the each sensor to go to 1 TCP server or different TCP servers?

What EXACTLY is "the response" a string of "ok" a JS object containing xyz?
please add an example to your demo flow.


NOTE: I realise that some of the answers may already be posted in previous posts but I dont want to assume anything.

[quote="Steve-Mcl, post:13, topic:81256, full:true"]
Sorry, that sample flow is not entirely clear what you are expecting to send to MQTT AFTER success/fail.

For example, you have not created a tcp-in -> send_fake_but_valid_data ->tcp-out

I am sending back the exact same request json with additional variables of successCode in case of success and errorcode in case of error. I have added sample response json in function node

Good - ok. I understand that.

If you get a "list of sensors" then how do you "update the sensor"?
What is the relevant parts of the incoming data?
What is the data to be sent to TCP (an exact example please)
Are you expecting the each sensor to go to 1 TCP server or different TCP servers?

1. After getting the request json I am updating the sensor through TCP protocol. I will have predefined tcp nodes and based on sensor id , I will send response to tcp server.
2. I will be sending opValue to tcp server based on sensorId. all parts are relevant and need to send back same request json with success code.
3. opValue
4. Multiple sensor can have same server or multiple. It depends but currently as first step I am trying to update the same tcp server.

What EXACTLY is "the response" a string of "ok" a JS object containing xyz?
please add an example to your demo flow.

TCP server may or maynot send the response. If Server update is successful and I dont get any error, I need the send the same request json with additional parameters succiessCode and ErrorCode in paramList.

**Response JSON**
**{**
**    "sensorList": [**
**        {**
**            "sensorId": "6131a8d409e2162ea1df532e",**
**            "protocol": "tcp",**
**            "paramList": [**
**                {**
**                    "paramName": "voltage",**
**                    "opValue": "220",**
**                    "successCode": "",**
**                    "errorCode": ""**
**                }**
**            ]**
**        },**
**        {**
**            "sensorId": "6131a8d409e2162ea1d423432e",**
**            "protocol": "tcp",**
**            "paramList": [**
**                {**
**                    "paramName": "temp",**
**                    "opValue": "220",**
**                    "successCode": "",**
**                    "errorCode": ""**
**                }**
**            ]**
**        }**
**    ]**
**}**

NOTE: I realise that some of the answers may already be posted in previous posts but I dont want to assume anything.
[/quote]

Thanks for giving your time in understanding and trying to help. I am blocked and needs to get it done asap.

That info is a lot clearer - but there are still some things not 100% clear - but there was enough there to let me take some artistic liberties and give you something that will hopefully get you unblocked.

[{"id":"2b0772d7c3e60c0b","type":"inject","z":"408c50b493cacaff","name":"DV101","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"deviceId\":\"DV101\",\"sensorList\":[{\"sensorId\":\"6131a8d409e2162ea1df532e\",\"protocol\":\"tcp\",\"paramList\":[{\"paramName\":\"voltage\",\"opValue\":\"220\"}]},{\"sensorId\":\"6131a8d409e2162ea1d423432e\",\"protocol\":\"tcp\",\"paramList\":[{\"paramName\":\"temp\",\"opValue\":\"220\"}]}]}","payloadType":"json","x":110,"y":40,"wires":[["f7b4a40dde770d17"]]},{"id":"4e5e2ac2f32b1577","type":"function","z":"408c50b493cacaff","name":"generate payload for param/opval","func":"const forTCP = {\n    device: msg.deviceId,\n    sensor: msg.sensorId,\n    parameter: msg.payload.paramName,\n    setValue: msg.payload.opValue\n}\nmsg.payload = JSON.stringify(forTCP);\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":200,"y":160,"wires":[["bd64c5f41edd3fd5"]]},{"id":"f98dafd5380a171c","type":"complete","z":"408c50b493cacaff","name":"","scope":["54218381f574f42b","d3ff24e94a906b7f"],"uncaught":false,"x":170,"y":300,"wires":[["bd04fd0313a3ea7a","a953cb944cbb0726"]]},{"id":"bd04fd0313a3ea7a","type":"function","z":"408c50b493cacaff","name":"setup MQTT topic/payload","func":"msg.topic = 'device/' + msg.deviceId + '/' + msg.sensorId\n\nmsg.payload = JSON.parse(msg.payload) // parse the string from TCP back into an object\nmsg.payload.success = true\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":300,"wires":[["5ff106c3636a8b3f","fd854389e94ce9d9"]]},{"id":"5ff106c3636a8b3f","type":"debug","z":"408c50b493cacaff","name":"success to MQTT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":300,"wires":[]},{"id":"ce7672aafd434bd2","type":"tcp in","z":"408c50b493cacaff","name":"","server":"server","host":"","port":"8101","datamode":"stream","datatype":"buffer","newline":"","topic":"","trim":false,"base64":false,"tls":"","x":310,"y":560,"wires":[["aaf77fd995ad323e"]]},{"id":"d61a6fcb51916276","type":"tcp out","z":"408c50b493cacaff","name":"","host":"","port":"","beserver":"reply","base64":false,"end":false,"tls":"","x":650,"y":560,"wires":[]},{"id":"aaf77fd995ad323e","type":"function","z":"408c50b493cacaff","name":"function 12","func":"msg.payload = \"OK\"\nreturn msg\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":560,"wires":[["d61a6fcb51916276"]]},{"id":"f7b4a40dde770d17","type":"change","z":"408c50b493cacaff","name":"move sensorList to payload","rules":[{"t":"set","p":"deviceId","pt":"msg","to":"payload.deviceId","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.sensorList","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":40,"wires":[["e318643372fe29f9"]]},{"id":"e318643372fe29f9","type":"split","z":"408c50b493cacaff","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":570,"y":40,"wires":[["ada5a1c9fab17d1b","68f5bff51366e296"]]},{"id":"ada5a1c9fab17d1b","type":"debug","z":"408c50b493cacaff","name":"split sensors","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":40,"wires":[]},{"id":"68f5bff51366e296","type":"change","z":"408c50b493cacaff","name":"move paramList to payload","rules":[{"t":"set","p":"sensorId","pt":"msg","to":"payload.sensorId","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.paramList","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":80,"wires":[["fde69494dd1ac86e"]]},{"id":"fde69494dd1ac86e","type":"split","z":"408c50b493cacaff","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":570,"y":80,"wires":[["d7423c716afa7292","4e5e2ac2f32b1577"]]},{"id":"d7423c716afa7292","type":"debug","z":"408c50b493cacaff","name":"split params for this sensor","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":800,"y":80,"wires":[]},{"id":"87cada212c4003e3","type":"switch","z":"408c50b493cacaff","name":"Which device?","property":"deviceId","propertyType":"msg","rules":[{"t":"eq","v":"DV101","vt":"str"},{"t":"eq","v":"DV102","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":680,"y":160,"wires":[["54218381f574f42b"],["d3ff24e94a906b7f"]]},{"id":"54218381f574f42b","type":"tcp request","z":"408c50b493cacaff","name":"TCP for Device 101","server":"localhost","port":"8101","out":"time","ret":"string","splitc":"100","newline":"","trim":false,"tls":"","x":890,"y":140,"wires":[[]]},{"id":"d3ff24e94a906b7f","type":"tcp request","z":"408c50b493cacaff","name":"TCP for Device 102","server":"localhost","port":"8102","out":"time","ret":"string","splitc":"100","newline":"","trim":false,"tls":"","x":890,"y":180,"wires":[[]]},{"id":"e3c681597874022f","type":"tcp in","z":"408c50b493cacaff","d":true,"name":"","server":"server","host":"","port":"8102","datamode":"stream","datatype":"buffer","newline":"","topic":"","trim":false,"base64":false,"tls":"","x":310,"y":620,"wires":[["17b5221260ff8c9e"]]},{"id":"17b5221260ff8c9e","type":"function","z":"408c50b493cacaff","name":"function 14","func":"msg.payload = \"OK\"\nreturn msg\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":620,"wires":[["a8f80b8f4e4d4675"]]},{"id":"a8f80b8f4e4d4675","type":"tcp out","z":"408c50b493cacaff","name":"","host":"","port":"","beserver":"reply","base64":false,"end":false,"tls":"","x":650,"y":620,"wires":[]},{"id":"ed8f7fa6b905b8a0","type":"inject","z":"408c50b493cacaff","name":"DV102","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"deviceId\":\"DV102\",\"sensorList\":[{\"sensorId\":\"6131a8d409e2162ea1df532e\",\"protocol\":\"tcp\",\"paramList\":[{\"paramName\":\"voltage\",\"opValue\":\"220\"}]},{\"sensorId\":\"6131a8d409e2162ea1d423432e\",\"protocol\":\"tcp\",\"paramList\":[{\"paramName\":\"temp\",\"opValue\":\"220\"}]}]}","payloadType":"json","x":110,"y":80,"wires":[["f7b4a40dde770d17"]]},{"id":"5a52203ce70b5a6f","type":"catch","z":"408c50b493cacaff","name":"","scope":["54218381f574f42b","d3ff24e94a906b7f"],"uncaught":false,"x":150,"y":420,"wires":[["1b92040eb3c0e36e","636380673a5c452f"]]},{"id":"fd854389e94ce9d9","type":"mqtt out","z":"408c50b493cacaff","name":"publish results to MQTT","topic":"device/sensor","qos":"2","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"214ab9a6ce4e03b0","x":690,"y":360,"wires":[]},{"id":"1b92040eb3c0e36e","type":"function","z":"408c50b493cacaff","name":"setup MQTT topic","func":"msg.topic = 'device/' + msg.deviceId + '/' + msg.sensorId\n\nmsg.payload = JSON.parse(msg.payload) // parse the string from TCP back into an object\nmsg.payload.success = false\nmsg.payload.error = msg.error.message\nmsg.payload.errorDetail = msg.error.source\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":420,"wires":[["fef57f4ff68f2876","fd854389e94ce9d9"]]},{"id":"fef57f4ff68f2876","type":"debug","z":"408c50b493cacaff","name":"error to MQTT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":660,"y":420,"wires":[]},{"id":"636380673a5c452f","type":"debug","z":"408c50b493cacaff","name":"error","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":330,"y":380,"wires":[]},{"id":"a953cb944cbb0726","type":"debug","z":"408c50b493cacaff","name":"success","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":340,"y":260,"wires":[]},{"id":"668d49e8143fe6b1","type":"comment","z":"408c50b493cacaff","name":"fake TCP servers - for simulation/testing","info":"","x":410,"y":520,"wires":[]},{"id":"bd64c5f41edd3fd5","type":"delay","z":"408c50b493cacaff","name":"limit 1 msg/100ms","pauseType":"rate","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"0.1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":470,"y":160,"wires":[["87cada212c4003e3"]]},{"id":"214ab9a6ce4e03b0","type":"mqtt-broker","name":"","broker":"test.mosquitto.org","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"5","keepalive":"45","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]


1 Like

Thank you so much for your help. Let me try and will update you. Thanks a lot again.

This is exactly what I needed. It would have taken me days to come to this solution as I have just started working on NodeRed. I was trying by putting request json in message queue or cache and get it from queue while sending response.

Just 1 query, Why we need delay Node?
Thanks

1 more query

There is still one doubt. If the TCP server doesn't send the acknowledgement back or I just need to send the msg.payload.opValue value to the tcp server, How will I send the response with all the below details?

const forTCP = {
    device: msg.deviceId,
    sensor: msg.sensorId,
    parameter: msg.payload.paramName,
    setValue: msg.payload.opValue
}
  1. To avoid flooding network and nodejs event queue
  2. Because some oddity of the catch node not triggering when the requests came in without a gap.

You could trim it down - potentially to 0.01 sec (10ms)

1 Like

Understood, Thank you for your swift response. :+1:

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