Getting Started Concepts The Things Stack Cloud The Things Stack Enterprise Integrations API Hardware
Get The Things Stack

Integrations

    Overview
  • Adding Applications
  • Data Formats
  • Payload Formatters
    • Creating Payload Formatters
    • CayenneLPP
    • Device Repository
    • JavaScript
      • Uplink
      • Downlink
  • Webhooks
  • Storage Integration
  • Integrate with popular IoT platforms
  • Other integrations
  • Application Packages
  • Examples

JavaScript

JavaScript payload formatters allow you to write functions to encode or decode messages. JavaScript functions are executed using an JavaScript ECMAScript 5.1 runtime.

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.1 (2009), which has some distinct differences compared to newer, commonly used ECMAScript revisions. See here for a quick comparison.

For security, the runtime does not support modules (require syntax) or any network or file system access.

Warning:
The maximum size of a JavaScript payload formatter is 40KB (40,960 bytes). Payload formatters loaded from the Device Repository can be larger.

Learn more about payload formatters and examples:

  • Uplink
  • Downlink

Uplink

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. If present, the normalizeUplink() function is called to normalize the decoded payload in a common data structure.
Read

Downlink

The encodeDownlink() function is called when a downlink message with decoded payload is scheduled to be sent to the end device. The encodeDownlink() function encodes the JSON object of the downlink message to binary payload for transmission to the end device. The decodeDownlink() function does the opposite of encodeDownlink(): it decodes the binary payload back to decoded payload.
Read
← Device Repository Uplink →

On this page

Sections

Getting Started

Concepts

The Things Stack Cloud

The Things Stack Enterprise

Integrations

API

Hardware

Sitemap

View our Sitemap

Contributing

GitHub

About Us

The Things Industries