v3.23.1

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
  • Storage Integration
  • Webhooks

Creating Payload Formatters

This section explains how to set up Payload Formatters using the Console or CLI.

  • Console
  • CLI

Create an Application Payload Formatter in the Console

To create an Application payload formatter, navigate to the Applications tab and choose your application.

Within the Application Overview, select the Payload Formatters dropdown in the left menu.

Choose Uplink or Downlink.

Choose a Formatter type.

See the Javascript, CayenneLPP, and Device Repository payload formatter documentation for an explanation of the diffent types of payload formatters.

Application

Create a Device Specific Payload Formatter

To create a device specific payload formatter, navigate to the Applications tab. Choose your application.

Within the Application Overview, select End Devices in the left menu.

Choose your End Device.

Within the End Device Overview, select the Payload Formatters tab in the top menu.

Choose Uplink or Downlink.

Choose a Formatter type.

See the Javascript, CayenneLPP, and Device Repository payload formatter documentation for an explanation of the diffent types of payload formatters.

Device

We define some user parameters that will be used below:

APP_ID="app1" 
API_KEY="NNSXS.VEEBURF3KR77ZR.."
GTW_EUI="00800000A00009EF"
USER_ID="admin"

Make sure to modify these according to your setup.

Create an Application Payload Formatter using the CLI

To create an application specific payload formatter, use the following command when linking an application. If creating a Javascript payload formatter, save your Encoder and Decoder functions to files and load them using the formatter-parameter-local-file parameter:

ttn-lw-cli applications link set $APP_ID \
  --api-key $API_KEY
  --default-formatters.down-formatter FORMATTER_JAVASCRIPT \
  --default-formatters.down-formatter-parameter-local-file "encoder.js" \
  --default-formatters.up-formatter FORMATTER_JAVASCRIPT \
  --default-formatters.up-formatter-parameter-local-file "decoder.js"

To create a CayenneLPP or Device Repository application payload formatter, use the FORMATTER_CAYENNELPP or FORMATTER_DEVICEREPO constants. No formatter-parameter-local-file parameter is needed.

Create a Device Specific Payload Formatter

We first define some device-related user parameters:

DEVICE_ID="dev1-with-formatter"
DEV_EUI="0004A30B001C0530"
APP_EUI="800000000000000C"
FREQUENCY_PLAN="EU_863_870"
APP_KEY="752BAEC23EAE7964AF27C325F4C23C9A"
LORAWAN_VERSION="1.0.3"
LORAWAN_PHY_VERSION="1.0.3-a"

Make sure you modify these according to your setup.

It is possible to assign a device specific payload formatter when creating a device using the CLI. Use the following parameters during device creation, and if creating a Javascript payload formatter, save your Encoder and Decoder functions to files and load them using the formatter-parameter-local-file parameter:

ttn-lw-cli end-devices create $APP_ID $DEVICE_ID \
  --dev-eui $DEV_EUI \
  --app-eui $APP_EUI \
  --frequency-plan-id $FREQUENCY_PLAN \
  --root-keys.app-key.key $APP_KEY \
  --lorawan-version $LORAWAN_VERSION \
  --lorawan-phy-version $LORAWAN_PHY_VERSION \
  --formatters.down-formatter FORMATTER_JAVASCRIPT \
  --formatters.down-formatter-parameter-local-file "encoder.js" \
  --formatters.up-formatter FORMATTER_JAVASCRIPT \
  --formatters.up-formatter-parameter-local-file "decoder.js"

To create a CayenneLPP or Device Repository device payload formatter, use the FORMATTER_CAYENNELPP or FORMATTER_DEVICEREPO constants. No formatter-parameter-local-file parameter is needed.

Edit a Device Specific Payload Formatter

To change the payload formatter for an existing device, use the end-devices update command:

ttn-lw-cli end-devices set $APP_ID $DEVICE_ID \
  --formatters.down-formatter FORMATTER_JAVASCRIPT \
  --formatters.down-formatter-parameter-local-file "encoder.js" \
  --formatters.up-formatter FORMATTER_JAVASCRIPT \
  --formatters.up-formatter-parameter-local-file "decoder.js"

To unset the payload formatters, use the --unset flag. The command below will unset all device specific payload formatters:

ttn-lw-cli end-devices set $APP_ID $DEVICE_ID \
  --unset "formatters"

It is also possible to unset the uplink or downlink formatters separately:

ttn-lw-cli end-devices set $APP_ID $DEVICE_ID \
  --unset "formatters.up-formatter,formatters.up-formatter-parameter"
← Payload Formatters CayenneLPP →

On this page

  • Create an Application Payload Formatter in the Console
  • Create a Device Specific Payload Formatter
  • Create an Application Payload Formatter using the CLI
  • Create a Device Specific Payload Formatter
  • Edit a Device Specific Payload Formatter

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 23 Dec 2021.
doc: Remove $ character from code blocks, add variables (#678)

Edit on Github