Skip to content
NEW AI Solution Creator — get a working IoT prototype in 10 minutes
Stand with Ukraine flag

TCP Integration

TCP Integration connects ThingsBoard to devices that communicate over raw TCP sockets. It listens on a configured port, frames the incoming byte stream into discrete messages, decodes each message through the Uplink Converter, and maps the result to ThingsBoard telemetry and attributes. It also supports downlink — sending messages back to devices over the same TCP connection.

When to use TCP Integration:

  • Devices use a custom binary or text protocol over a raw TCP socket.
  • Firmware already opens a TCP connection to a configurable host and port.
  • You need a persistent, connection-oriented channel for both telemetry and commands.

Before creating the integration, ensure:

  • You have access to a ThingsBoard Professional Edition instance with integration functionality enabled for your tenant.
  • You have permissions to create integrations and data converters.
  • You know the payload format and framing protocol your TCP devices use.
  • Port 10560 (or whichever port you configure) must be open for incoming TCP connections on the machine running the TCP Integration process. The remote process also needs outbound access to ThingsBoard’s gRPC port 9090.
  • The echo command piped to netcat (nc) is available for sending test data over TCP.

In this tutorial, device SN-002 sends temperature and humidity readings to the TCP Integration server on port 10560.

The integration accepts three payload formats:

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

The decoder function receives the raw TCP message bytes as a payload byte array — already extracted from the byte stream by the handler configured in the Connection settings, with framing bytes stripped. 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.

For the full decoder function reference — all input parameters and output fields — see Uplink data converter.

  1. Go to Integrations center ⇾ Data converters.
  2. Click + Add data converter ⇾ Create new converter.

In the Add data converter dialog:

  1. Converter type — leave Uplink (selected by default).
  2. Integration type — in the search field, enter TCP and select TCP from the list.
  3. Name — enter a converter name, for example TCP Uplink Converter.
  4. Main decoding configuration — paste the decoder function from the appropriate tab below, then continue with step 7.

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 the script against a sample payload.
  2. Click Add.
  1. Go to Integrations center ⇾ Integrations and click + Add integration.
  2. Basic settings:
    • Select TCP as the integration type.
    • Enter a name — for example, TCP integration.
    • Enable integration and Allow create devices or assets are on by default.
    • Click Next.
  3. Uplink data converter:
    • Click Select existing and choose the TCP Uplink Converter created in the previous step, or click Create new to define the decoder inline.
    • Click Next.
  4. Downlink data converter:
    • Click Skip for now. You can add a downlink converter later.
  5. Connection settings:
    • Set the Port — default is 10560. This port must be open on the machine running the TCP Integration process.
    • The Execute remotely option is always enabled for TCP. Copy the Integration key and Integration secret — you will need them to start the remote integration process.
    • Configure the Handler Configuration — select the message framing strategy that matches your device protocol. See Handler Configuration below.
    Read more about each parameter in Connection Settings.
  6. Click Add.

Port

The TCP port the integration server will bind to. Default: 10560. The port must be open on the machine running the TCP Integration process and must not be shared with another integration in the same ThingsBoard tenant environment.

Max number of pending connects on the socket

The maximum length of the queue for incoming connections that have not yet been accepted. Default: 128. Increase this value under high connection concurrency.

Size of the buffer for inbound / outbound socket (in KB)

The socket receive and send buffer sizes in kilobytes. Default: 64 KB each. Increase for high-throughput devices that send large payloads.

Enable sending of keep-alive messages on connection-oriented sockets

When enabled, the OS sends TCP keep-alive probes to detect dead connections. Disabled by default. Enable when devices maintain long-lived connections that may silently drop.

Forces a socket to send the data without buffering (disable Nagle’s algorithm)

When enabled, sends each write immediately rather than batching small packets. Enabled by default. Disable only if you send many small messages in rapid succession and want to reduce the number of TCP segments.

Execute remotely

Always enabled for TCP Integration. Shows the Integration key and Integration secret — credentials required to launch the TCP Integration as a standalone remote process. See Remote Integration for full setup instructions.

Advanced settings

FieldDescription
DescriptionOptional free-text description of the integration.
MetadataOptional key–value pairs injected into every message and accessible in converter scripts via the metadata object. Click Add to add a row.

Because TCP is a stream protocol with no built-in message boundaries, the integration must be told how to split the stream into individual messages. Select the handler that matches your device protocol:

Splits the stream into messages using a text delimiter. Suitable for devices that send human-readable strings — CSV, JSON strings, or plain text lines.

ParameterDescription
Max Frame Length (in bytes)Maximum allowed message size. Messages exceeding this size raise an exception. Default: 128.
Strip delimiterWhen enabled (default), the delimiter itself is removed before passing the payload to the converter.
Message separator typeHow messages are delimited: System line separator (\n / \r\n), Nul delimiter (\0), or Custom separator (enter any string in the Separator field).
Charset nameCharacter encoding used to decode the text stream. Default: UTF-8. Set to the encoding your device uses (e.g. ISO-8859-1) if non-ASCII characters appear garbled.

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.

After the integration is created, send a test uplink and confirm that ThingsBoard received the message, decoded it correctly, and provisioned the device.

Once the TCP Integration process is running, the TCP server starts and listens for device connections. Use netcat (nc) to simulate a device sending data.

Select your payload type:

Send a message:

Terminal window
echo -e 'SN-002,default,temperature,25.7' | nc -q0 localhost 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 localhost 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 localhost 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 localhost 10560
Terminal — two text messages sent; connection kept open with -w60 to receive a downlink response

Go to Integrations center ⇾ Integrations, open TCP integration, and click the Events tab. Each successfully processed uplink appears as a row with status OK.

To inspect converter processing, go to Integrations center ⇾ Data converters, click TCP Uplink Converter, and open its Events tab:

  • In — what the integration received (the raw payload bytes)
  • Out — what the converter returned
  • Error — error text, if any

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

Downlink allows ThingsBoard to send messages back to devices over TCP — for example, in response to an RPC call or a shared attribute update. The message is delivered over the same TCP connection the device used to send its last uplink.

The downlink converter transforms a Rule Engine message into the bytes sent back to the device. The integration appends a \n newline after every downlink payload — device-side parsers should expect and strip this trailing byte.

  1. Go to Integrations center ⇾ Integrations and open the TCP integration.
  2. Click the pencil icon to enter edit mode.
  3. In the Downlink data converter field, click Create new.
  4. Enter a name, paste the encoder script shown below, then click Add.
  5. Click Apply changes.

Select your script language:

/** 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;

To send downlinks through the integration, modify the Root Rule Chain:

  1. Go to Rule chains and open the Root Rule Chain.
  2. Find the integration downlink node in the node library panel on the left. Drag it onto the canvas.
  3. In the node configuration dialog, enter a name (e.g. Downlink to TCP integration) and select your TCP integration. Click Add.
  4. Connect the message type switch node to the newly created integration downlink node using the Post attributes and Attributes Updated relation types to trigger downlinks whenever shared attributes are created or updated.
  5. Apply the changes.

Open a persistent TCP connection to receive the downlink and keep it open:

Terminal window
nc localhost 10560

Then type uplink manually and press Enter:

Terminal window
SN-002,default,temperature,25.7

Do not close the terminal.

Trigger a downlink by adding a shared attribute to the device:

  1. Go to Entities ⇾ Devices, open SN-002, and navigate to the Attributes tab.
  2. Select Shared attributes, click + to add a new attribute.
  3. Set the key (e.g. powerState) and value (e.g. on).
  4. Click Add.

The Rule Engine routes the attribute creation message to the Integration Downlink node, which encodes it and sends it to the device. The terminal will print:

Terminal window
john@doe:~$ nc localhost 10560
SN-002,default,temperature,25.7
{"powerState":"on"}

To inspect the exchange, open the downlink converter’s Events tab:

  • In shows the Rule Engine message
  • Out shows the encoded payload sent to the device
  • Metadata shows additional context
SymptomCauseFix
No device created after sending datadeviceName is empty or undefinedCheck Events → Out on the uplink converter; verify the decoder correctly extracts deviceName from the payload
Error in converterTBEL or JavaScript exceptionOpen Events → Error on the uplink converter and inspect the stack trace; use Test payload decoder to validate against a sample payload
Messages split or merged incorrectlyHandler type mismatchVerify the Handler Configuration matches your device’s framing protocol; use a packet capture to inspect raw TCP bytes
Integration process fails to connect to ThingsBoardWrong host, port, key, or secretVerify host, port, routingKey, and secret in tb-remote-integration.yml; ensure ThingsBoard gRPC port 9090 is reachable from the remote integration host
Port already in useAnother process is using the same portChoose a different port in Connection settings and restart the remote integration process
Device does not receive downlinkConnection closed after uplinkThe device must keep the TCP connection open; single-shot nc closes immediately — use -w60 or a persistent client for testing
Data present but timestamp is wrongDevice sends ts in secondsConvert before assigning: ts: data.ts * 1000
Telemetry not savedConverter returns {} or []Ensure telemetry contains at least one key-value pair
  • Integrations Overview — how ThingsBoard connects to external platforms and how uplink/downlink flow works
  • Uplink Data Converter — full decoder function reference: input parameters, output fields, and scripting patterns
  • Downlink Data Converter — full encoder function reference for sending commands to devices
  • Remote Integration — install and run the TCP Integration as a standalone process outside the ThingsBoard server
  • TBEL scripting reference — built-in functions and operators for writing converter scripts
  • Rule Engine — how uplink messages are processed after the converter runs