Destination Format Scripts

When your IoT devices send data to the platform, it is internally processed and standardized into the SenML (Sensor Measurement Lists) format. By default, when you set up a Destination (such as an HTTP webhook or an MQTT broker) to receive your uplink data, the platform forwards it in this native SenML format.

However, your external applications or third-party systems might require data in a specific structure. Destination Format Scripts allow you to write custom JavaScript code to transform the platform's standard SenML payload into any desired format before it is delivered to your destination.

How It Works

A Destination Format Script acts as a data transformer at the very end of the data processing pipeline.

[IoT Device] ──> [Decoder] ──> [SenML] 
    ──> [Destination Format Script] ──> [Your Custom Format] ──> [Destination]
  • Input: The script receives a valid SenML JSON array containing the device's latest measurements and metadata.

  • Processing: Your custom JavaScript logic parses, filters, or reorganizes this SenML data.

  • Output: The script returns the transformed payload (e.g., a custom JSON object, a string, or a binary buffer) tailored to your external system's specifications.

Script Requirements

To ensure proper execution within the platform, your script must adhere to the following guidelines:

1. JavaScript Environment

The script engine is fully compliant with modern ECMAScript standards (including ES6, ES7, and beyond). You can freely use modern syntax features such as arrow functions, template literals, optional chaining (?.), nullish coalescing (??), destructuring, const/let, and advanced collection types like Set.

The destination format script is executed in a sandbox. As a result you cannot make network requests (e.g., fetch) or import external Node.js/third-party modules.

2. The Main Function Entry Point

Your script must expose a single main function execution block that takes a single string parameter (input). The function itself does not require a specific name and can be written as an anonymous arrow function.

The underlying input argument is a JSON string that, when parsed, reveals an object with the following structural layout:

JavaScript

3. Processing Constraints

To maintain platform stability and performance, the execution environment enforces the following limits:

  • Execution Time: Scripts must complete execution within 100 milliseconds.

  • Memory Limit: Scripts are allocated a maximum of 10 MB of memory.

  • No External Access: For security reasons, scripts run in an isolated sandbox. You cannot make network requests (e.g., fetch) or import external Node.js/third-party modules.

Default Starter Template & Example

When you create a new Destination Format, the Script Editor pre-populates with a robust template. This template contains built-in SenML Utilities to help you handle RFC 8428 data normalization (expanding and merging base fields like bn, bt, etc.) before mapping it to your custom schema.

Template Script

Testing Your Script

Before saving your script, verify its execution using the built-in Script Editor Test Tool:

  1. Paste your JavaScript code into the editor workspace.

  2. Use one of the pre-defined SenML Payload Data inputs in the Tester, or provide a sample JSON test string containing a mock metadata object and payload array into the Test Input field.

  3. Click Run script with test payload.

  4. Review the generated Output block to ensure the data structure matches your target destination parameters, or review the Console Output Logs if a runtime exception is thrown.

Last updated

Was this helpful?