v3.20.0

Getting Started Devices Gateways Integrations Reference
Get The Things Stack

Integrations

    Overview
  • Adding Applications
  • Adding Integrations
  • Cloud Integrations
  • MQTT Server
  • Pub/Sub
  • LoRa Cloud
  • Node-RED
  • IFTTT
  • Payload Formatters
    • Creating Payload Formatters
    • CayenneLPP
    • Device Repository
    • Javascript
      • Uplink Decoder
      • Downlink Encoder
      • Downlink Decoder
  • Storage Integration
  • Webhooks

Javascript

Javascript payload formatters allow you to write your own functions to encode or decode messages. Javascript functions are executed using an JavaScript ECMAScript 5.1 engine.

Tips:

  • The payload formatters should be simple and lightweight.
  • Use arithmetic operations and bit shifts to convert binary data to fields.
  • Avoid using non-trivial logic or polyfills.
Note:
Payload formatters use ECMAScript 5 (2009), which has some distinct differences compared to newer, commonly used ECMAScript revisions. See here for a quick comparison. Notably, let, const, and arrow functions are not supported by ES5.
Note:
For security, the runtime does not support modules, require syntax, or any input/output other than defined below.
Warning:
The maximum size of a user-defined Javascript payload formatter is 40KB (40960 characters), unless the source of the payload formatter is Device Repository.

There are three different types of The Things Stack JavaScript payload formatters:

  • Uplink Decoder
  • Downlink Encoder
  • Downlink Decoder

Read the documentation below to further learn about these formatters and find associated examples.

Uplink Decoder

The Javascript decodeUplink() function is called when a data uplink message is received from a device. This function decodes the binary payload received from the end device to a human-readable JSON object that gets send upstream to the application.
Read

Downlink Encoder

The encodeDownlink() function is called when a downlink message, with a payload in JSON format, is scheduled to be sent to the end device. The encodeDownlink() function encodes the JSON object of the downlink message to binary payload that gets transmitted to the end device.
Read

Downlink Decoder

The decodeDownlink() function is called to decode a downlink message to JSON format, if it was scheduled with payload as bytes, or if it was scheduled with human-readable JSON payload but also was encoded with the encodeDownlink() function.
Read
← Device Repository Uplink Decoder →

On this page

The Things Stack

Getting Started

Devices

Gateways

Integrations

Reference

Contributing

GitHub

Forum

About Us

The Things Network

The Things Industries

About this page

Last changed by Nejra Selimović on 08 Jun 2022.
doc: Add payload formatter maximum size info (#882)

Edit on Github