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:
Read the documentation below to further learn about these formatters and find associated examples.