Skip to content
Stand with Ukraine flag

UDP Integration

UDP Integration streams data from devices that use a UDP transport protocol to ThingsBoard Edge, converting payloads into telemetry and attributes. It also supports downlink — sending messages back to devices over the same UDP socket.

In this tutorial we will use:

  • A ThingsBoard PE Edge instance.
  • The UDP Integration running as a remote service on port 11560.
  • The echo command and netcat (nc) utility to simulate a device sending data.

The example device SN-001 publishes temperature and humidity readings to UDP Integration on port 11560. Depending on your device capabilities, you can use one of four payload formats:

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

Converter and integration templates are created on the Cloud (ThingsBoard PE server). Log in as Tenant administrator.

The uplink converter decodes the incoming UDP payload into ThingsBoard telemetry and attributes.

  1. In the Cloud, go to Edge management > Converter templates and click +, then Create new converter. Set type to Uplink and enable Debug mode.

  2. Paste the decoder script for your payload type into the function Decoder field, then click Add.

    /** Decoder **/
    // decode payload to string
    var strArray = decodeToString(payload);
    var payloadArray = strArray.replace(/\"/g, "").replace(/\s/g, "").replace(/\\n/g, "").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: {}
    };
    function decodeToString(payload) {
    return String.fromCharCode.apply(String, payload);
    }
    return result;

To edit the converter later, open it from the Converter templates page, click the pencil icon, update the script, and click the checkmark to save.

The downlink converter encodes outbound messages (e.g. attribute updates) into the format sent back to the device.

  1. On the Converter templates page, click +, then Create new converter. Set type to Downlink and enable Debug mode.

  2. Paste the following script into the function Encoder field, then click Add:

    // Encode downlink data from incoming Rule Engine message
    // msg - JSON message payload
    // msgType - e.g. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST'
    // metadata - key/value pairs with message metadata
    // integrationMetadata - key/value pairs defined in the Integration
    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;
  1. Go to Edge management > Integration templates and click +. Select UDP as the type, name it, and attach the uplink and downlink converters.

  2. In the Connection block, set the Port to 11560 (or another available port). Set the Handler Configuration for your payload type:

    • Handler type: Text
    • Charset Name: UTF-8

    Additional Connection settings:

    SettingDescription
    Size of the buffer for inbound socket (in KB)Socket receive buffer size.
    Cache SizeMaximum number of cached UDP sessions.
    Cache time to live in minutesHow long a UDP session is kept in cache.
    Enable broadcastWhen enabled, the integration accepts packets sent to the broadcast address.

    Copy the Integration key and Integration secret — you will need them when running the remote service.

  3. Click Add to save the integration template.

To send downlink messages from ThingsBoard Edge to devices, add an integration downlink node to the Edge Root Rule Chain.

Install and run the remote UDP Integration

Section titled “Install and run the remote UDP Integration”

Use the Integration key and Integration secret from the integration page to configure the remote service.

Pull the image:

Terminal window
docker pull thingsboard/tb-pe-tcp-udp-integration:4.3.1.1PE

Create a log volume:

Terminal window
mkdir -p ~/.tb-pe-tcp-udp-integration-logs && sudo chown -R 799:799 ~/.tb-pe-tcp-udp-integration-logs

Run the integration (replace placeholders with your values):

Terminal window
docker run -it -p 11560:11560/udp \
-v ~/.tb-pe-tcp-udp-integration-logs:/var/log/tb-tcp-udp-integration \
-e "RPC_HOST=mytbedge" \
-e "RPC_PORT=9090" \
-e "INTEGRATION_ROUTING_KEY=YOUR_ROUTING_KEY" \
-e "INTEGRATION_SECRET=YOUR_SECRET" \
--name my-tb-pe-tcp-udp-integration \
--network NETWORK_NAME \
--restart always \
thingsboard/tb-pe-tcp-udp-integration:4.3.1.1PE
ParameterDescription
mytbedgeHostname of the ThingsBoard Edge service
9090Integration RPC port (INTEGRATIONS_RPC_PORT in tb-edge.yml)
-p 11560:11560/udpMaps local UDP port 11560 to the container port
YOUR_ROUTING_KEYIntegration routing key from the integration page
YOUR_SECRETIntegration secret from the integration page
NETWORK_NAMEDocker network where mytbedge runs. Check with docker network ls

To detach from the terminal without stopping the container, press Ctrl+p then Ctrl+q.

Useful container commands:

Terminal window
docker attach my-tb-pe-tcp-udp-integration # reattach to logs
docker stop my-tb-pe-tcp-udp-integration
docker start my-tb-pe-tcp-udp-integration

Once the UDP Integration is running, the UDP server starts listening on port 11560.

  1. Send a test uplink using echo and nc. Choose the command for your payload type:

    Terminal window
    echo -e 'SN-001,default,temperature,25.7,humidity,69' | nc -w5 -u 127.0.0.1 11560
  2. On the Edge, go to Integration center > Integrations, open the UDP integration, and select the Events tab. A message with status OK should appear.

  3. Go to Entities > Devices to see the newly created device and its latest telemetry.

  4. To inspect how the Uplink Converter processed the message, go to Integration center > Data converters, open the uplink converter, and select the Events tab.

  1. Send another uplink with -q120 so nc waits 120 seconds for the downlink response:

    Terminal window
    echo -e 'SN-001,default,temperature,25.7,humidity,69' | nc -q120 -u 127.0.0.1 11560
  2. Within 120 seconds, go to Entities > Devices, select device SN-001, and open the Attributes tab. Under Shared attributes, click + and add a new attribute — for example, key firmware, value v1.0. Save.

  3. Verify the downlink was sent by opening the integration’s Events tab.

  4. The terminal will show the response returned by ThingsBoard Edge.