Skip to content
Stand with Ukraine flag

UDP Integration

UDP Integration allows you to stream data from devices using the UDP protocol to ThingsBoard and convert device payloads to the ThingsBoard format.

UDP integration overview diagram

This tutorial uses:

  • A ThingsBoard Professional Edition instance running locally.
  • UDP Integration running as a remote integration connected to the ThingsBoard instance.
  • The echo command to produce a line of text, piped to netcat (nc) to send it over UDP.

The example sensor device SN-001 publishes temperature and humidity readings to UDP Integration on port 11560.

Four payload formats are demonstrated. Select the one that matches your device:

SN-001,default,temperature,25.7,humidity,69

UDP uses a generic uplink converter. The decoder function receives the raw UDP datagram as a payload byte array. 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.

Unlike HTTP or MQTT integrations, UDP provides no transport-level metadata — device identity must come entirely from the payload itself.

  1. Go to Integrations center ⇾ Data converters.
  2. Click + Add data converter and select Create new converter.
  3. Set Converter type to Uplink (default).
  4. Select Integration type: UDP.
  5. Enter a name, e.g. UDP Uplink Converter.
  6. Select TBEL (recommended) or JavaScript.
  7. Clear the default script and paste the decoder function 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 decoder expects a comma-separated string where position 0 is the device name, position 1 is the device type, and positions 2–N are alternating telemetry key/value pairs: deviceName,deviceType,key1,value1,key2,value2,...

To adapt this converter to your device:

  • Change the separator by replacing split(',') with your delimiter (e.g. split(';') or 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 report device properties instead of measurements, move fields from the telemetry map to the attributes map.
  1. Optionally, click Test decoder function to validate.
  2. Click Add.
  1. Go to Integrations center ⇾ Integrations and click + Add integration.
  2. Basic settings:
    • Set Integration type to UDP.
    • 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:
    • Port11560 by default; change if needed.
    • Copy the Integration key and Integration secret — required when configuring the remote UDP Integration service.
    • Select your payload type and configure the handler — see Connection settings below.
  6. Click Add to save the integration.
Handler configuration

The handler determines how the integration interprets the incoming UDP datagram. Select the handler matching your payload format:

ParameterValueDescription
Charset NameUTF-8Encoding used to convert the datagram bytes to a string.
Port
ParameterDefaultDescription
Port11560UDP port the integration listens on for incoming datagrams.
Integration key and secret

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

Network settings
ParameterDescription
Enable broadcastAccepts UDP packets sent to the broadcast address. Enabled by default.
Downlink cache
ParameterDescription
Cache SizeMaximum number of downlink messages stored per UDP client.
Cache time to live in minutesHow long queued downlink messages are retained before being discarded.

Install and run the remote UDP integration

Section titled “Install and run the remote UDP integration”

Refer to the remote integration guide to install and start the UDP Integration service.

Use the Integration key and Integration secret from the integration’s Connection settings when configuring the service.

Once the UDP integration is active, the UDP server starts and waits for device data.

Select your payload type:

Terminal window
echo -e 'SN-001,default,temperature,25.7,humidity,69' | nc -w5 -u 127.0.0.1 11560
Terminal — text payload sent to UDP integration on port 11560; no output indicates successful delivery

Go to Entities ⇾ Devices. Device SN-001 is auto-created on the first uplink. Open it and confirm the Latest Telemetry tab shows temperature = 25.7 and humidity = 69.

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

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

The encoder used in this tutorial:

// Result object with encoded downlink payload
var result = {
// downlink data content type: JSON, TEXT or BINARY (base64 format)
contentType: "JSON",
// downlink data
data: JSON.stringify(msg),
// Optional metadata object presented in key/value format
metadata: {}
};
return result;

To assign the downlink converter to the integration:

  1. Go to Integrations center ⇾ Integrations, open the UDP 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 UDP Downlink, select the UDP integration, and click Add.
  3. Connect the Message Type Switch node to the Integration Downlink node using both Attributes Updated and Post Attributes relation types and click Apply changes.
  1. Go to Entities ⇾ Devices, open device SN-001, 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 -w10 and send an uplink:

Terminal window
echo -e 'SN-001,default,temperature,25.7,humidity,69' | nc -w10 -u 127.0.0.1 11560
Terminal — uplink sent with nc -w10, downlink response {"firmware":"v1.1"} received