Skip to content
The Things Stack documentation home
Getting Started Concepts Cloud Enterprise Integrations API Hardware
Getting Started Concepts
Cloud Enterprise
Integrations API Hardware
Get The Things Stack

    Recent searches

      Popular pages

      • Getting Started
      • Adding Gateways
      • Adding Devices
      • Payload Formatters
      • Webhooks
      • Authentication

      No results for “”.

      • Check the spelling, or try fewer or more general words.
      • Ask the community on The Things Network Forum
      • Contact support
      ↑↓ to navigate ↵ to open Esc to close

      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

      Updated 29 August 2022 Edit on GitHub
      Copy page
      • View as MarkdownThis page as plain text
      • Open in ChatGPTAsk questions about this page
      • Open in ClaudeAsk questions about this page

      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 →

      Sections

      Getting Started

      Concepts

      Cloud

      Enterprise

      Integrations

      API

      Hardware

      Sitemap

      View our Sitemap

      Contributing

      GitHub

      About Us

      The Things Industries

      Privacy Policy

      Cookie settings

      Cookie Settings

      We use cookies to enhance your experience, analyze site traffic and deliver personalized content. Read our Privacy Policy.

      Cookie categories