How to send TCP response to actor !?

Hello I am very new to Node-RED and help could be nice:
I ve a some actors sending Json values to my Node-RED.
These actors have a dynamic IP. So I used a TCP node and
listen to the port. I use a function node to get the IP by script.
(this is the part which works)
But I ve no idea how to send at once a response. This must
happen quick, because of battery management reasons the
actors will close the connection very soon.
Can someone tell me which nodes to use and how to config them ?
The response should be setable to put differend commands in
Thanx in advanced!

Define "actor". It sounds like that MQTT would be highly recommended, if those "actors" are capable of sending those messages.

Actors are ESP-12 modules with different sensors like temp. , hum. , light , motion ...aso.
Maybe it was naive but ioBorker and Node-RED are enought new stuff for now so I thought I could skip MQTT to simplifiy the start :slight_smile:

Use MQTT, you will find it simpler after the short initial learning curve. It is easy to install mosquitto (it is in the raspbian repository for example). You can learn about with this tutorial.

For example this would cover most of the bases -

OK, thanks for the fast replys. I took a look at MQTT and I am unsure if MQTT is realy an better solution. The tutorials I saw showed simple light on and off scenarios. For my case I have to use python and push values to a database. At lease what I read now. I am not realy happy with what I saw and with open another building beside FHEM, Node-Red, ioBroker (whats new for me too) and ESP programming.

I have to vte with everyone else. Setup a MQTT broker and spend a little time learning it and you will be amazed what you can do. IOne setup I have with another member of the forum is my wemos ini is sending data via na online MQTT broker ( to the other member and it si then being stored in a MySQL database in the cloud. Both of us can use NR to query the data.

Or how about having a water tank in a greenhouse that has two float switches top and middle. They are conncted to a wemos that sneds the data via MQTT to a NR flow that knows when both valves are low it sends a mqtt msg to a second wemos connected to a water valve and turns on the water. When the two switches are high, a message is send to the wemos (via mqtt) to shutoff the valve.

Take your time and have a read of the tutorial at

remember baby steps. They didn start teaching calculus when you entered first grade :grin:

I also use TCP node for my IOT. You have to use TCP node located on the output group.
at the TCP node, select "reply to TCP". After this point, node-red still won't reply to TCP, you need to provide TCP info in msg to make it work.
in the TCP input node, if you use debug node with complete message, you will see addtional TCP information. The msg._session must be pass to the TCP output to make it response to the client.

the msg send into TCP out node must be:
msg.payload --> your response text message
msg._session --> tcp session id, copy from TCP input node

if you want to response TCP quickly, then

  1. from TCP input node connect directly to TCP output node --> this one text from client will echo back to client. you can manipulate response text by insert function node in between.
  2. from the same TCP input node, connection to another function node. This function node, you can do anything with node-red on server side

Thanx for all the help.
I implementet functions to send values by TCP and MQTT (Mosquitto).
for battery usage the MQTT seems to be a better chose so I try to use that. But anyway thanks for the guide, @tbdltee I think there will be cases to use this.

Currently I grab my values by MQTT input node that works.
Still with MQTT I am remaining with a kind of the same problem:
My sensor reportes values every x minutes and I implemented a 5 sec. time window at the same time to receive messages before the sensor goes to sleep.
I ve no idea what node I should use to implement my use case:
I want to send a reply string "update " to my sensor at once it sends values to the MQTT.
The string should be send as long as a update switch status is "on" (dashboard)
Currently I have to press a botton on the injection node exactly within the time window (else the string will be dropped).
Can you help me with that ?
thx in advanced !

as I understood, you cannot do it directly. MQTT is using subscribe/publish concept, not request/response. The client subscribed to the topic. Any clients publishes a message to the topic, all other clients subscribed in the same topic will hear it.
if you want to use MQTT, you need another MQTT client, in this case, another node-red MQTT client to publish the message to the topic.
In this case, use output/mqtt to publish the "update" message back to your device.

Well, the server and a client is installed on raspi so I guess with the right nodes the arival of the message at the mqtt-raspi-server can trigger the mqtt-raspi-client to do a kind of realtime reaction within my time window?

Click to see what I have now