Skip to content

Cookie preferences

We use cookies for our own analytics, to see how our campaigns perform and, if you allow it, to load content from other services such as the Google site search. We never sell your data. Necessary cookies keep the site working and cannot be switched off. See our Cookie Policy for details and our Privacy Policy for how we handle personal data.

Security, load balancing and remembering your cookie choice.

Show us which pages people read, how they find the site and where they get stuck, so we can improve it (Google Analytics, Microsoft Clarity).

Show us which of our ad campaigns bring visitors to the site and remember the campaign or partner link you arrived from (Google Ads, LinkedIn, Meta, partner program). We do not use these cookies to build advertising profiles.

Load the site search from Google when you use it. Google sets its own cookies and shows ads in the search results.

© 2026 The ThingsBoard Authors

Uplink Data Converter

An uplink data converter turns a message received by an integration into data ThingsBoard can store. It runs a decoder script (TBEL or JavaScript) on every uplink message and returns:

  • the device or asset the data belongs to (looked up by name and created if needed),
  • telemetry (time-series values),
  • attributes.

Every integration has exactly one uplink converter. A converter is a standalone entity: one converter can be used by several integrations, and a change to it applies to all of them. To reuse a converter, choose Select existing in the integration wizard (see Create a Converter).

  1. The integration receives a message (an MQTT publish, an HTTP request, a LoRaWAN network server event, and so on) and passes its body and metadata to the converter.
  2. The decoder script parses the payload and returns the result object.
  3. ThingsBoard finds the device or asset by name, creating it if the integration has Allow create devices or assets enabled. See Entity Lookup and Creation.
  4. Telemetry and attributes are sent to the rule engine as POST_TELEMETRY_REQUEST and POST_ATTRIBUTES_REQUEST messages, where the rule chain saves them.
Type Use it for How it works
Generic Any integration type, any payload format The script receives the raw message body and must return the entity name and data itself.
Typed ChirpStack, Loriot, ThingPark, ThingParkEnterprise, The Things Stack Sandbox, The Things Stack Cloud & Enterprise ThingsBoard unwraps the network server message first. The script decodes only the device payload; entity name, profile and network fields are set in the UI.
Library Devices with a ready-made decoder in the converters library Pre-built converter for a vendor and model, loaded from a Git repository. It is saved as a Generic or Typed converter, depending on the library entry.

The UI has no Generic or Typed option: the integration type decides it (see Create a Converter).

Which one to choose:

  • Your device model is in the library → start with Library.
  • You use one of the six LoRaWAN network servers → use Typed.
  • Any other case (MQTT, HTTP, CoAP, TCP, UDP, Kafka, cloud brokers, custom payloads) → use Generic.

Most uplink converters are created in the Uplink data converter step of the integration wizard. It offers:

  • Create new — the same fields as below (Name, Main decoding configuration, Advanced decoding parameters); the integration type comes from the integration and the name is pre-filled.
  • Select existing — shown when the tenant already has an uplink converter for this integration type or for All.
  • Library — shown when the library has converters for the type.

To create a converter on its own:

  1. Go to Integrations ⇾ Data converters and click + Add data converter ⇾ Create new converter.
  2. Leave Converter type set to Uplink.
  3. Select the Integration type. It decides whether the converter is Generic or Typed and can’t be changed later:
    • For a Generic converter, leave it empty (All) or select any other integration type. Some types, such as MQTT or AWS IoT, provide their own sample decoder.
    • For a Typed converter, select one of the six LoRaWAN network servers.
  4. Optionally, use the library: if the integration type has library converters, a Create new / Library toggle appears. Select Library, then the Vendor and the Model. The name, decoder and decoding parameters are filled in from the library, and the TBEL/JS switch is locked. Review or edit them in the next steps.
  5. Enter a Name. The debug button next to it sets what the converter records; see Debug Events.
  6. In Main decoding configuration, select TBEL or JS and adapt the sample decoder. Typed: also set the Entity type and the Device name / Asset name pattern. See Main Decoding Configuration.
  7. In Advanced decoding parameters, review the Update only keys list. For a Generic converter it is usually pre-filled with manufacturer; for a Typed converter, with network fields such as eui, devAddr and fPort. Typed: also review the profile, label, customer, group and metadata keys. See Advanced Decoding Parameters.
  8. Optionally, click Test decoder function (Generic) or Test payload decoder (Typed) to run the script against a sample message.
  9. Click Add.

A Generic converter gives the script full control. It receives the message body as bytes and returns the complete result: the entity name and type, plus telemetry and attributes. It works with every integration type. Create it as described in Create a Converter; this section covers the decoder script.

The decoder function is the script that does the work of a Generic converter. ThingsBoard calls it for every message the integration receives. The function reads the message, decides which device or asset the data belongs to, and returns the data to store.

Signature

function decoder(payload, metadata) {
// your code
return result;
}

The editor shows the first and the last line of the function. You write only the body.

Adapt the decoder to your device

A new converter comes with a sample decoder for JSON payloads; some integration types, such as MQTT, provide their own. The sample already returns a valid result, so you usually change only a few parts of it:

To change Edit in the sample decoder
Device name and profile The deviceName and deviceType variables. By default, they are read from the payload fields with the same names.
Nested objects The sample flattens them into dotted keys with toFlatMap, so {"sensor": {"t": 1}} is saved as sensor.t.
Create assets instead of devices Uncomment assetName and assetType, and return them instead of deviceName and deviceType.
Assign a customer or an entity group Uncomment customerName and groupName.
Which values are attributes attributeKeyList. Every other payload field is saved as telemetry.
Timestamp By default, the ts or timestamp payload field, otherwise the current time.
Payload format Replace decodeToJson(payload) with your own parsing for text or binary payloads. See Common Scripting Patterns.

You can also replace the sample with your own code. The function only has to return a result in the Decoder Output format. A minimal decoder for a JSON payload (in JavaScript, keep the helper functions at the end of the sample):

var data = decodeToJson(payload);
return {
deviceName: data.deviceName,
telemetry: { temperature: data.temperature }
};

To check your changes, click Test decoder function, paste a real message, and compare the result with the Decoder Output format: the test shows what the script returns but doesn’t check it against that format. See Testing the Decoder.

The function receives two arguments:

  • payload — the message body as an array of bytes, whatever the content type. Convert it before reading values:

    • JSON: var data = decodeToJson(payload);, then data.temperature
    • Text: var text = decodeToString(payload);
    • Binary: read the bytes directly, for example parseBytesToInt(payload, 0, 2)

    In TBEL, payload holds the raw bytes, and bytes from 0x80 up read as negative numbers (for example, 0xC2 is -62). In JavaScript, a body that is valid UTF-8 arrives as character codes, one per character: the bytes C2 B0 arrive as one value, 176 (°). Other bodies arrive as bytes.

  • metadata — information about the message as key-value pairs. It always contains integrationName and the keys set in the integration’s Metadata settings. Some integrations add their own keys, for example HTTP request headers (Header:content-type) or the MQTT topic. Read a value with metadata.integrationName or metadata['Header:content-type'].

Helper functions. TBEL has built-in helpers for converting payloads (full list in the TBEL reference):

Function Description
decodeToString(bytes) Byte array → UTF-8 string
decodeToJson(bytes) Byte array → parsed JSON object
base64ToBytes(str) / bytesToBase64(bytes) Base64 string ↔ byte array
hexToBytes(str) / bytesToHex(bytes) Hex string ↔ byte array
parseBytesToInt(bytes, offset, length, bigEndian) Reads an integer from a byte range
toFixed(value, precision) Rounds a number to the given number of decimal places
toFlatMap(json, excludeList, pathInKey) Flattens a nested JSON object into one level of keys

In JavaScript, these helpers are not built in. The sample JavaScript decoder defines decodeToString, decodeToJson and toFlatMap(obj, result, excludeList), which fills result instead of returning a map, at the end of the script; keep them, or define your own.

The function returns a result object. It tells ThingsBoard which device or asset the data belongs to and which attributes and telemetry to save. To update several devices or assets from one message, return an array of result objects.

Result structure

{
// Target entity: a device...
deviceName: "Thermometer", // required for a device
deviceType: "thermostat", // optional
// ...or an asset: return assetName and assetType instead
customerName: "Customer A", // optional
groupName: "Thermostats", // optional
attributes: { serialNumber: "SN-12345" },
telemetry: { temperature: 25.5 }
}
Field Required Description
deviceName Yes, for a device Device name, unique within the tenant. ThingsBoard finds the device by this name, or creates it.
deviceType No Device profile name. Default: default.
deviceLabel No Device label.
assetName Yes, for an asset Asset name. Return either deviceName or assetName, not both.
assetType Yes, for an asset Asset profile name.
assetLabel No Asset label.
customerName No Customer to assign the new entity to.
groupName No Entity group to add the new entity to.
attributes No Attributes as key-value pairs.
telemetry No Telemetry values, with or without a timestamp. See the formats below.

Profile, label, customer and group are applied only when the entity is created. See Entity Lookup and Creation.

Telemetry formats

// Values only: saved with the server time
telemetry: { temperature: 25.5, humidity: 61 }
// Values with your timestamp, in milliseconds
telemetry: { ts: 1718000000000, values: { temperature: 25.5, humidity: 61 } }
// Several timestamps in one message
telemetry: [
{ ts: 1718000000000, values: { temperature: 25.5 } },
{ ts: 1718000060000, values: { temperature: 25.7 } }
]

Example

The device sends:

{
"deviceName": "Thermometer",
"deviceType": "thermostat",
"serialNumber": "SN-12345",
"temperature": 25.5,
"ts": 1718000000000
}

The decoder returns:

{
"deviceName": "Thermometer",
"deviceType": "thermostat",
"attributes": { "serialNumber": "SN-12345" },
"telemetry": { "ts": 1718000000000, "values": { "temperature": 25.5 } }
}

ThingsBoard finds the device Thermometer, or creates it with the thermostat profile. It then saves serialNumber as an attribute and temperature as telemetry at the given time. For value types and nested objects, see Telemetry, Attributes, and Timestamps.

The patterns below are for Generic converters and use syntax valid in both TBEL and JavaScript. For Typed converters, see Decoder Script.

Device name from the payload, a constant, or metadata

var data = decodeToJson(payload);
var deviceName = data.serial; // a payload field
// var deviceName = 'Gateway-01'; // constant: all data goes to one device
// var deviceName = metadata.topic; // a metadata key, if the integration provides it

Rename, transform, and read nested fields

// payload: {"id": "S-1", "fw": "2.1.0", "sensor": {"tempC": 22.5, "bat": 0.87}}
var data = decodeToJson(payload);
return {
deviceName: data.id,
attributes: { firmwareVersion: data.fw }, // fw → firmwareVersion
telemetry: {
temperatureF: data.sensor.tempC * 9 / 5 + 32, // Celsius → Fahrenheit
batteryPercent: data.sensor.bat * 100 // 0–1 → 0–100
}
};

Batch of readings with their own timestamps

// payload: {"deviceId": "S-1", "readings": [{"ts": 1718000000000, "temp": 22.5}, {"ts": 1718000060000, "temp": 22.8}]}
var data = decodeToJson(payload);
var telemetry = [];
for (var i = 0; i < data.readings.length; i++) {
telemetry.push({ ts: data.readings[i].ts, values: { temperature: data.readings[i].temp } });
}
return { deviceName: data.deviceId, deviceType: 'thermometer', telemetry: telemetry };

Each entry is stored at its own timestamp.

Several devices in one message

// payload: [{"sn": "A1", "temp": 21.0}, {"sn": "B2", "temp": 23.4}]
var data = decodeToJson(payload);
var result = [];
for (var i = 0; i < data.length; i++) {
result.push({ deviceName: data[i].sn, telemetry: { temperature: data[i].temp } });
}
return result;

Text or CSV payload

// payload: Sensor-01,22.5,60
var parts = decodeToString(payload).split(',');
return {
deviceName: parts[0],
telemetry: { temperature: parseFloat(parts[1]), humidity: parseFloat(parts[2]) }
};

Binary payload

// payload bytes: 4-byte serial number, 1-byte battery, 2-byte temperature × 100
return {
deviceName: 'Sensor ' + parseBytesToInt(payload, 0, 4),
telemetry: {
battery: parseBytesToInt(payload, 4, 1),
temperature: parseBytesToInt(payload, 5, 2) / 100.0
}
};

parseBytesToInt is a TBEL built-in. In JavaScript, define it in the script.

Optional fields

A telemetry or attribute key whose value is null is skipped, so a missing value does not need a guard. Guard only the expressions that would fail on a missing value, such as nested access:

var data = decodeToJson(payload);
var temperature = data.sensor != null ? data.sensor.temperature : null;

A Typed converter is built for one LoRaWAN network server. ThingsBoard knows that server’s message format: it extracts the device payload and network fields before the script runs. In the UI, you configure the entity name, the profile and the network fields to store, and the script decodes only the device payload.

Typed converters are available from ThingsBoard 4.0 for these integration types:

Integration type Guide
ChirpStack ChirpStack
Loriot Loriot
ThingPark ThingPark
ThingParkEnterprise ThingParkEnterprise
The Things Stack Sandbox The Things Stack Community (TTN)
The Things Stack Cloud & Enterprise The Things Stack Industries (TTI)

When you select one of these integration types for a new uplink converter, ThingsBoard creates a Typed converter. Converters created before ThingsBoard 4.0 stay Generic and keep working unchanged. Create a Typed converter as described in Create a Converter; this section covers its configuration.

Entity type — Device or Asset: the entity type the converter creates or updates. Switching it relabels the name field and the advanced parameters (for example, Device profile name becomes Asset profile name).

Device name / Asset name — name pattern. $key is replaced with the value of the metadata key key, so the ChirpStack default Device $eui becomes Device 0004A30B001C1234. The Things Stack Sandbox and The Things Stack Cloud & Enterprise default to $deviceId. A $key with no matching metadata key stays in the name as literal text.

Decoder script — a sample payloadDecoder(payload, metadata) script in TBEL or JavaScript. See Decoder Script.

Before the script runs, ThingsBoard unwraps the network server message:

Parameter Description
payload The device payload as a byte array. If the network server already decoded it (ChirpStack object, TTN/TTI decoded_payload, Loriot decoded, ThingPark payload), payload holds that JSON and metadata.payloadFormat is JSON; read it with decodeToJson(payload). Otherwise, payload holds the raw bytes decoded from base64 or hex, and metadata.payloadFormat is BINARY.
metadata The network fields extracted from the message (for example, eui, devAddr, fPort, fCnt, rssi, snr, frequency, data, decoded), ts, payloadFormat, and the integration metadata (integrationName and the keys configured in the integration). An integration metadata key overrides a network field with the same name. The available keys depend on the network server. To see the full set for a real message, open the test dialog.

metadata.ts is the message time in milliseconds, taken from the network server message (for example, ChirpStack time, or TTN/TTI uplink_message.received_at). If the message has no usable time, it is the time ThingsBoard received the message.

The sample script depends on the integration type. For ChirpStack and ThingPark, it stores the fields of a JSON payload as telemetry and contains a binary example that you replace with your device’s byte layout. For Loriot and ThingParkEnterprise, it contains only the binary example. For The Things Stack Sandbox and The Things Stack Cloud & Enterprise, it stores the fields of a JSON payload as telemetry and sets the device profile itself from the device’s brand and model, so Device profile name has no effect unless you change the script.

Return value — an object, or an array of objects for several entities:

return {
attributes: { sn: parseBytesToInt(payload, 0, 4) },
telemetry: {
ts: metadata.ts,
values: { battery: parseBytesToInt(payload, 4, 1), temperature: parseBytesToInt(payload, 5, 2) / 100.0 }
}
};

attributes and telemetry use the same formats as in the Generic output. The script does not return deviceName or deviceType: the entity name and profile come from the converter configuration. To override them for a message (for example, when the device name is in the payload), set these fields on the result:

Field Overrides
name Device name / Asset name pattern
type Entity type: 'DEVICE' or 'ASSET'
profile Device profile name / Asset profile name
label Device label / Asset label
customer Customer name
group Device group name / Asset group name

An empty or null value falls back to the configured one.

The pre-filled values depend on the integration type. For ChirpStack, for example, Device profile name is $deviceProfileName and Device label is $deviceName. Fields that accept a pattern support $key placeholders, like the name.

Field Description
Device profile name / Asset profile name Profile for a new entity. If empty, default is used.
Device label / Asset label Label for a new entity.
Customer name Customer to assign a new entity to.
Device group name / Asset group name Entity group to add a new entity to.
Telemetry Metadata keys to add to the telemetry, for example rssi, snr, fCnt.
Attributes Metadata keys to add to the attributes, for example eui, devAddr, fPort.
Update only keys list See Update Only Keys List.

The Telemetry and Attributes lists copy values from metadata into the result:

  • They do not filter what the script returns: everything the script returns is kept.
  • A listed key is skipped when the script already returned a key with the same name.
  • Metadata telemetry uses the timestamp of the script’s {ts, values} object. If the script returns a telemetry array, the metadata values are added to the entry whose ts equals metadata.ts, or as a separate entry at metadata.ts if there is none.
  • If the script returns no telemetry, or values without ts, metadata telemetry gets the server time.
  • String network fields added by these lists keep their string type.

The converters library provides ready-to-use uplink converters for popular device models. Instead of writing a decoder yourself, select the device vendor and model, and ThingsBoard fills in the converter: the decoder script, the decoding parameters and a sample payload for testing.

The library is available for these integration types: HTTP, ChirpStack, Loriot, ThingPark, ThingParkEnterprise, The Things Stack Sandbox and The Things Stack Cloud & Enterprise. The vendors and models offered depend on the selected integration type.

Library converters are maintained in the public thingsboard/data-converters GitHub repository, and new devices are added regularly.

A library converter can be edited before you add it, but its language switch is locked: the converter keeps the language of the library entry.

If your exact model is not listed, start from a similar model and edit the decoder.

Click Test decoder function (Generic) or Test payload decoder (Typed) in the converter editor. The test runs the script on the server with a sample input. It does not create entities or store data.

The test dialog contains:

  • Payload — the sample input and its Payload content type (JSON, Text, Binary (Base64) or Binary (Hex)). The content type only controls how the dialog encodes your input; the script always receives a byte array.
  • Metadata — the key-value pairs passed as metadata.
  • Decoder — the script, editable.
  • Test — runs the script and shows the result.
  • Save — copies the edited script back to the converter editor; Cancel discards it. The converter itself is saved only when you click Add or apply your changes.

The sample payload and metadata are taken from the converter’s latest debug event if there is one, otherwise from a built-in sample for the integration type. For a library converter, the library’s sample payload is used.

Generic converters show the returned object in Output.

Typed converters add:

  • Updated RAW payload — opens the complete network server message. Edit it and click Apply to unwrap it into a new payload and metadata, exactly as the integration would.
  • Two result tabs: Decoder output (what the script returned) and Converter output (the final result after the name pattern, profile, metadata telemetry and attributes, and script overrides are applied).

This section applies to Generic, Typed and Library converters alike.

ThingsBoard looks up the device or asset by name within the tenant:

  • Found — only telemetry and attributes are processed. Profile, label, customer and group from the converter are ignored, even if they differ from the entity’s current values. Change them on the entity itself.
  • Not found, and the integration has Allow create devices or assets enabled — the entity is created with the converter’s profile, label, customer and group. A profile, customer or entity group that does not exist is created. The group is created under the entity’s owner: the customer, if one is set, otherwise the tenant.
  • Not found, and creation is disabled — the message fails with Creating devices is forbidden! (or Creating assets is forbidden!), and its data is not stored.
  • Value types — strings, numbers and booleans are stored as is. With the default JSON_TYPE_CAST_ENABLED=true, a string that contains a number (for example, "22.5") is stored as a number. Nested objects and arrays are stored as JSON values. Keys whose value is null are skipped.
  • Timestamps — ts must be a Unix time in milliseconds. Telemetry without ts gets the server time of conversion. An object is treated as timestamped only when it has both ts and values. Otherwise, ts is stored as an ordinary telemetry key.
  • Attributes are posted to the rule engine as a POST_ATTRIBUTES_REQUEST message. The rule chain’s save-attributes node decides the attribute scope.

Update only keys list is available for every converter type in Advanced decoding parameters. For each listed key, the converter forwards a telemetry or attribute value only if it differs from the last value it forwarded for the same entity. Use it for values sent with every message that rarely change, such as firmware version, devAddr or fPort.

Each converter records debug events on its Events tab. Click the debug button next to the converter name (in edit mode), or in the converter row, to choose what is recorded. The panel has two toggles:

  • Failures only (24/7) — records failed messages.
  • All messages (15 min) — records every message for a limited time, 15 minutes by default. When that time ends, only failures are recorded, and only if Failures only is on.

With both toggles off, the button shows Disabled and nothing is recorded.

A converter created on the Data converters page starts with Failures only. A converter created in the Add integration wizard or from the library starts with All messages.

On the Events tab, each Debug event shows the input (In), the script result (Out), the Metadata, and the reason in the Error column if the message failed. The integration’s Events tab shows the same failed message with the status ERROR.

With All messages on, at most 50,000 converter debug events are recorded per tenant per hour by default. When the limit is reached, one event with the error Converter debug rate limits reached! is recorded. Each field of an event (In, Out, Metadata, Error) is cut to 4,096 characters by default, so a large payload copied from a debug event into the test dialog may be incomplete.

If the script throws an error or returns an invalid result, the message’s data is not stored.

Error or symptom Cause Fix
Either 'deviceName' or 'assetName' should be present in the converter output! A Generic script returned neither field, for example because the payload field was missing. Check the field name in a debug event’s In column.
Both 'deviceName' and 'assetName' can't be present in the converter output! A Generic script returned both. Return only one.
Asset type is not set! assetName returned without assetType. Add assetType.
Failed to get device or create device … Creating devices is forbidden! The device does not exist, and the integration does not allow creation. The converter itself succeeds, so this error is shown only on the integration’s Events tab. Create the device, or enable Allow create devices or assets in the integration.
Device name contains $eui or another $key literally Typed converter: the key is not in the metadata. Use a key shown in the test dialog’s Metadata.
Data is decoded from the wrong bytes A Generic converter on a LoRaWAN integration is reading the network server envelope. Extract the device payload from the envelope, or use a Typed converter.
Can't compile script: …, then Can't compile uplink converter script The script has a syntax error. The first message shows the details; later messages show the short text. Fix the script in the test dialog and save the converter.
Can't compile script: … Script body exceeds maximum allowed size of 50000 symbols, then Can't compile uplink converter script The script is longer than the limit. Shorten the script.
Script input arguments exceed maximum allowed total args size of … symbols The payload and metadata are larger than the script input limit. The payload counts as Base64 text, about 4/3 of its size. Split large batches into smaller messages before sending them. See Script limits.
Script invocation result exceeds maximum allowed size of … symbols The script result, as JSON, is larger than the result limit. Return less data per message. See Script limits.
Script invocation is blocked due to maximum error count … The script exceeded its input size, result size, memory, or time limit several times in a short period. Every message, including valid ones, then fails until the block ends. Find the errors recorded right before the block and fix their cause, like a script that takes too long. Saving the converter clears the block right away. See Script limits.
Can't parse value: {...} A telemetry entry could not be parsed, for example ts is null or an array, or values is not an object. Return ts as a number of milliseconds and values as an object, or omit ts to use the server time.

Integrations ⇾ Data converters lists all converters with their creation time, name, type, integration type and description.

  • Edit — open the converter and switch to edit mode. Converter type, integration type and the Generic/Typed version cannot be changed after the converter is saved. Converter names must be unique among converters of the same type (uplink or downlink).
  • Export — Export converter downloads the converter as JSON.
  • Import — click + Add data converter ⇾ Import converter and select the JSON file. Name, type, integration type, script and decoding parameters are restored.
  • Delete — a converter used by any integration cannot be deleted. Assign another converter to the integration, or delete the integration first.