Skip to content
Stand with Ukraine flag

TCP Integration

TCP Integration streams data from devices over the TCP transport protocol into ThingsBoard and converts device payloads to the ThingsBoard format. TCP Integration always runs as a remote integration — it can run on the same machine as your ThingsBoard instance or on a separate machine with network access to it.

TCP integration overview diagram

This tutorial uses:

  • A ThingsBoard Professional Edition instance running locally.
  • TCP Integration running as a remote integration connected to the ThingsBoard instance. Port 10560 must be open for incoming connections on the machine running TCP Integration.
  • The echo command piped to netcat (nc) to send data over TCP.

The example device SN-002 publishes temperature and humidity readings to the TCP Integration on port 10560.

Three payload formats are demonstrated — select the one that matches your device:

SN-002,default,temperature,25.7\nSN-002,default,humidity,69

TCP uses a generic uplink converter. The uplink converter receives the raw TCP message bytes as a payload byte array — already framed and stripped by the handler configured in the connection settings. It must return an object with at least deviceName and deviceType. Optionally, it can include telemetry (time-series measurements) and attributes (device properties) as flat key-value maps.

  1. Go to Integrations center ⇾ Data converters.
  2. Click + Add data converter ⇾ Create new converter.
  3. Set Converter type to Uplink (default).
  4. Select Integration type: TCP.
  5. Enter a converter name: TCP Uplink Converter.
  6. Paste the decoder function from the tab below.

Select the tab matching your payload type:

/** Decoder **/
// decode payload to string
var strArray = decodeToString(payload);
var payloadArray = strArray.replaceAll("\"", "").replaceAll("\\n", "").split(',');
var telemetryPayload = {};
for (var i = 2; i < payloadArray.length; i = i + 2) {
var telemetryKey = payloadArray[i];
var telemetryValue = parseFloat(payloadArray[i + 1]);
telemetryPayload[telemetryKey] = telemetryValue;
}
// Result object with device attributes/telemetry data
var result = {
deviceName: payloadArray[0],
deviceType: payloadArray[1],
telemetry: telemetryPayload,
attributes: {}
};
/** Helper functions 'decodeToString' and 'decodeToJson' are already built-in **/
return result;

The handler delivers one logical record per decoder invocation (split by the configured message separator). The decoder expects a comma-separated string: position 0 is the device name, position 1 is the device type, followed by alternating telemetry key/value pairs.

To adapt this converter to your device:

  • Change the separator by replacing split(',') with your delimiter (e.g. split(';')).
  • If the device name or type is at a different position, adjust the payloadArray[0] / payloadArray[1] index.
  • If telemetry keys are fixed rather than embedded in the payload, replace the loop with explicit assignments: telemetryPayload['temperature'] = parseFloat(payloadArray[2]);.
  • To extract attributes instead of telemetry, move fields from the telemetry map to the attributes map.
  1. Optionally, click Test payload decoder to validate.
  2. Click Add.
  1. Go to Integrations center ⇾ Integrations and click + Add integration.
  2. Basic settings:
    • Set Integration type to TCP.
    • Enable integration and Allow create devices or assets are on by default.
    • Click Next.
  3. Uplink data converter:
  4. Downlink data converter:
    • Click Skip — the downlink converter can be added later.
  5. Connection settings:
    • Port10560 by default; change if needed.
    • Copy the Integration key and Integration secret — required when configuring the remote TCP Integration service.
    • Select your payload type and configure the frame handler — see Handler configuration below.
  6. Click Add to save the integration.
Handler configuration

The frame handler controls how TCP reads the incoming byte stream and extracts individual messages. Select the handler matching your payload format:

ParameterValueDescription
Max Frame Length128Maximum length of a decoded frame.
Strip DelimiterenabledDrops the newline delimiter from the decoded payload.
Message SeparatorSystem Line SeparatorNewline (\n) used as the message delimiter.
Port
ParameterDefaultDescription
Port10560TCP port the integration listens on for incoming device connections.
Integration key and secret

Generated automatically when Execute remotely is enabled. Required when starting the remote TCP Integration service — copy both values before closing the wizard.

Socket options
ParameterDescription
Max number of pending connectsMaximum backlog queue length for incoming connections.
Size of the buffer for inbound socketReceive buffer size in KB.
Size of the buffer for outbound socketSend buffer size in KB.
Enable keep-alive messagesSends periodic probes to detect and drop stale connections.
Disable Nagle’s buffering algorithmSends data immediately without waiting to fill a buffer.
Downlink cache
ParameterDescription
Cache SizeMaximum number of downlink messages stored per TCP client.
Cache time to live in minutesHow long queued downlink messages are retained before being discarded.

Install and run the remote TCP Integration

Section titled “Install and run the remote TCP Integration”

Follow the remote integration guide to install and start the TCP Integration service. Use the Integration key and Integration secret from the connection settings step above.

Once the TCP integration is active, the TCP server starts and listens for device connections.

Select your payload type:

Send a single message:

Terminal window
echo -e 'SN-002,default,temperature,25.7' | nc -q0 127.0.0.1 10560
Terminal — single text message sent to the TCP integration; no output indicates successful delivery

Multiple messages (newline-delimited):

Terminal window
echo -e 'SN-002,default,temperature,25.7\nSN-002,default,humidity,69' | nc -q1 -w1 127.0.0.1 10560
Terminal — two newline-delimited text messages sent; connection closes after 1 s

To receive a downlink response, keep the connection open:

Terminal window
echo -e 'SN-002,default,temperature,25.7' | nc 127.0.0.1 10560
Terminal — single text message sent; connection kept open to receive a downlink response

Multiple messages with open connection:

Terminal window
echo -e 'SN-002,default,temperature,25.7\nSN-002,default,humidity,69' | nc -w60 127.0.0.1 10560
Terminal — two text messages sent; connection kept open with -w60 to receive a downlink response

Go to Entities ⇾ Devices. Device SN-002 is auto-created on the first uplink. Open the Latest Telemetry tab to confirm temperature = 25.7.

To send messages from ThingsBoard back to a device, add a downlink converter to the integration and configure a rule chain to forward attribute changes to it.

The downlink converter encodes outgoing ThingsBoard messages into the format expected by the device.

The encoder used in this tutorial:

/** Encoder **/
var data = {};
data.tempFreq = msg.temperatureUploadFrequency;
data.humFreq = msg.humidityUploadFrequency;
data.devSerialNumber = metadata['ss_serialNumber'];
var result = {
contentType: "JSON",
data: JSON.stringify(msg),
metadata: {
topic: metadata['deviceType'] + '/' + metadata['deviceName'] + '/upload'
}
};
return result;
  1. Go to Integrations center ⇾ Integrations, open the TCP integration, and click the edit (pencil) icon.
  2. In the Downlink data converter field, enter a name and click Create new converter.
  3. Paste the encoder script and click Add.
  4. Click Apply changes.
  1. Go to Rule chains and open the Root Rule Chain.
  2. Find the Integration Downlink node, drag it onto the canvas, name it TCP integration downlink, select the TCP integration, and click Add.
  3. Connect the Message Type Switch node to the Integration Downlink node using the Attributes Updated relation type and click Apply changes.
  1. Go to Entities ⇾ Devices, open device SN-002, and click the Attributes tab.
  2. Switch to Shared attributes and click +.
  3. Enter an attribute key and value (e.g. key: firmware, value: v1.1) and click Add.

To receive the downlink response, keep the connection open with -w60 and send an uplink:

Terminal window
echo -e -n '{"deviceName": "SN-002", "deviceType": "default", "temperature": 25.7, "humidity": 69}' | nc -w60 127.0.0.1 10560

To verify the downlink, go to Integrations center ⇾ Data converters, open the downlink converter, and check the Events tab. The In block shows the incoming message from the rule chain; the Out block shows the encoded payload sent to the device. When the TCP connection stays open for an extended time, only one downlink message is delivered immediately — subsequent messages are queued and sent on the next uplink.