Skip to content

Create a decoder

Applies to SiteSync StandardEnterprise Management Introduced in 1.0.0 Role: Administrator

A decoder turns a device’s raw LoRaWAN payload into named values SiteSync can model as tags. SiteSync supports two kinds — see Decoder concepts for the difference.

  • Open Data Manager → Decoders and select + New Decoder (or open an existing one to edit it).
  • Give the decoder a clear name — this is what you’ll select on a device profile.
  • At the top of the editor, choose the decoder type: Decoder (JavaScript) or API.

With Decoder selected, provide a JavaScript decode function — paste it in or upload a .js file. It runs inside SiteSync on every uplink from devices using this profile.

At minimum, your code must define a function named Decoder that takes bytes and port:

function Decoder(bytes, port) {
// bytes: the payload as a byte array, e.g. [20, 34, 19, ...]
// port: the LoRaWAN FPort the uplink arrived on, e.g. 10
var data = {};
data.size = bytes.length;
// ...map bytes[] into named fields for this device...
return { data: data }; // optionally add: warnings: [...], errors: [...]
}
  • bytes is the raw payload as an array of byte values; port is the FPort. You can branch on port to decode different message types.
  • Return an object with a data field holding your decoded values. You may also return optional warnings and errors arrays — if errors is non-empty, SiteSync treats the decode as failed.

Test it against a sample payload before assigning it.

With API selected, SiteSync sends each uplink to an external service and uses the decoded response. The Connection tab has three parts:

The endpoint SiteSync posts each payload to — for example http://lab.sitesync.cloud:9080/core. Include the port where your service requires one.

How SiteSync authenticates to that endpoint:

OptionUse
NoneThe endpoint needs no credentials.
BearerSiteSync sends a bearer token in the Authorization header.
BasicSiteSync sends a username and password using HTTP Basic auth.

A JSON template for the request body SiteSync sends to your endpoint. You structure the body however your decode service expects it, and use placeholder variables where the live uplink values should go. SiteSync replaces those placeholders with the message’s values before posting the request, then reads the decoded JSON the service returns.

Two placeholders are substituted from each uplink:

VariableReplaced withNotes
!PAYLOAD!The raw uplink payload, as a hex stringIt’s a string, so keep it inside quotes in the template.
!FPORT!The LoRaWAN FPort the uplink arrived onIt’s a number, so leave it unquoted.

For example, a service that expects a hex string and an FPort would use:

{
"hex": "!PAYLOAD!",
"fport": !FPORT!
}

Because the body is just a template you control, you can point SiteSync at different API decode services and shape the request to match whatever each one expects — the placeholders pipe the values in from the message pipeline.

When the fields are complete, select Save Configuration.

For a JavaScript decoder, the input is Decoder(bytes, port) — bytes is the payload byte array and port is the FPort — and the output is the object you return: a data object of decoded values, plus optional warnings and errors arrays (a non-empty errors means the decode failed).

For an API decoder, SiteSync sends your API Payload Format template to the endpoint and uses the decoded JSON it returns.

Either way, the decoder’s output is a flat set of named fields. Those names are what a device profile’s Primary Value and Display Values reference, and what the assigned UDT maps into tags — so keep the output names stable once devices depend on them.

  1. Select Save Configuration.
  2. Open the Test tab and test the decoder against a sample hex payload. For an API decoder, the Test tab exercises the configured endpoint.
  3. Assign the decoder on the relevant device profile.
Was this page helpful? Report incorrect documentation Last reviewed 2026-10-05