Datacake Docs
  • Welcome
  • Get Started
  • Changelog
  • Best practices
    • Best practices: Getting started
    • Best practices: Resolution (Timeframe)
    • Best practices: Dashboards
    • Best practices: Reports
    • Best practices: Grouping Devices
  • Datacake LNS
    • Getting Started
    • Gateways
      • Milesight LoRaWAN Gateway - UG6x
      • RAKwireless WisGate Edge Light 2
    • Devices
    • Add Devices without Gateway
  • Device
    • Product
    • Configuration
    • Claiming
    • Historical Data
    • Database
      • Configuration Fields
      • Fields
        • Manual input
        • Field Roles
        • Formulas
        • Mapping Fields
      • Data retention & Datapoints
      • Examples
        • Mapping 4-20mA Signals
        • Converting Units
  • Dashboards
    • Global Dashboards
      • Setting Homepage
    • Device Dashboards
    • Multi-Device Dashboards
    • Widgets
      • Value Widget
      • Chart Widget
      • Image Map
      • Map Widget
      • Text Widget
      • SOS Widget
      • Boolean Widget
      • iFrame Widget
      • Downlink Widget
      • Set Value Widget
      • Measurement List Widget
      • Heatmap Widget
      • Table Widget
      • Image Widget
  • Portal
    • Multi-Tenancy (Workspaces)
    • Reports
      • Energy Report
    • Administrators
    • Members
      • API Users
    • Security & Privacy
    • Billing
      • Support Packages
      • VAT Exemption / Tax ID
      • SMS Credits
      • Access Invoices
      • Unused time and Remaining time in Invoices (Prorations)
      • Codes
    • White Label
    • Rules
      • Legacy Rule Engine
        • Sending notifications via Telegram
      • New Rule Engine
        • Rule Engine Table Overview
        • Copy/Paste and Template Functionality
        • Advanced Rule Engine E-Mail and Webhook Templates
        • Time Restrictions
    • Zones
  • Cake Red
    • Get Started
    • Overview
  • LoRaWAN
    • Get Started
      • CSV Import
      • Custom LoRaWAN Device
    • Configuring LNS
      • The Things Stack (TTN / TTI) Automated Setup
      • The Things Stack (TTN / TTI) Manual Setup
      • Loriot
      • Kerlink Wanesy
      • Helium
      • ChirpStack
      • Tektelic
      • Actility ThingPark
      • Senet
      • Milesight Gateway
      • KPN
    • Downlinks (LoRaWAN)
      • Set Time Frame
    • Securing Webhooks
    • Payload Decoders
      • Location and GPS
      • Access Gateway Metadata
      • Access Measurements
      • Global Variables
    • Using Cayenne LPP
    • Converting Payload
  • Generic API Devices
    • HTTP Downlinks
  • Integrations
    • MQTT
    • Particle
      • Get Started
      • Adding Integrations
      • Decoding Payloads
      • Calling Functions
      • Templates
        • Particle Tracker One
    • Incoming Webhooks
    • Outgoing Webhooks
      • Securing Outgoing Webhooks in Datacake
    • Golioth
    • Blues Wireless Notecard
    • Sigfox
    • Swarm Asset Tracker
    • Grandcentrix Modbus Cloud Connect
    • YuDash LYNX IoT Gateway
    • Dragino NB-IoT
      • Changing NB-IoT Bands
    • Hardwario CHESTER
    • 1NCE OS
  • API
    • Exporting Data
    • Record Measurements via API
    • Node RED to Datacake
    • Generate Access Token
    • Internal MQTT
      • Get Started
      • MQTT Documentation
      • MQTT over WebSocket
      • Example Code
    • GraphQL API
      • Using GraphQL
      • Device Creation
      • Tutorials
        • Read Group via Tags
  • Guides
    • Python
    • Send Slack Notifications
    • Forward Data to Cake Red
    • Multiple Data Feeds
    • Automated Dynamic Downlinks
    • Ingesting JSON Data into Datacake API Devices
    • Working with Default HTTP Decoder on API Devices and Code Examples
    • Accessing Measurements in Decoders
    • Connecting Datacake to Notion Using Zapier
    • How to set up and use location on non-GPS devices
    • How to integrate with AWS IoT Core
    • How to Schedule Mass-Downlinks (Multicast) using Datacake Rule Engine
    • How to Map Sensor Values to Ranges or Booleans, Strings using Mapping Fields
    • Understanding Internal vs. External MQTT Brokers on Datacake
    • Sending UDP Messages between 1NCE OS and Datacake
    • Concepts of LoRaWAN Payload Decoders on Datacake
    • How to check if a value stays above or below limits for given time
Powered by GitBook
On this page
  • Access LNS Decoder Values
  • TTN Example
  • Helium Example
  • Converter for TTN Decoder

Was this helpful?

  1. LoRaWAN

Converting Payload

Access LNS Decoder Values

It may be that you already have Devices on your LoRaWAN Network Server (like TTN or Helium) and that you already have a working Payload Decoder set up and running.

So instead of copying your Payload Decoder to Datacake, you can access the decoded fields directly and use the payload decoder section of Datacake to convert this information.

In this article, we show you how this goes.

Let's assume you have already implemented an application on an LNS (TTN in this example) and already have a usable payload. This would look something like the following:

TTN Example

{
  "app_id": "my-sensod",
  "dev_id": "00137a1000006482",
  "hardware_serial": "00137A1000006482",
  "port": 6,
  "counter": 4085,
  "payload_raw": "AQQBHwAGAAAAAAA=",
  "payload_fields": {
    "battery": 3.1,
    "light": 6,
    "loudness": 45.2,
    "co2": 563
  },
  "metadata": {
    // ...
  },
  "downlink_url": "..."
}

The above example shows you the payload of a webhook forward on TTN. The following information is important for us:

"payload_fields": {
  "battery": 3.1,
  "light": 6,
  "loudness": 45.2,
  "co2": 563
}

You can access these fields from within the payload decoder section of Datacake.

For this, you can access the payload coming over webhook via the global rawPayload variable. This would look like this:

function Decoder(bytes, port) {

    // Access the decoded field like this:
    // var battery = rawPayload.payload_fields.battery;
     
    return [
        {
            field: "BATTERY",
            value: rawPayload.payload_fields.battery
        },
        {
            field: "LIGHT",
            value: rawPayload.payload_fields.light
        },
        {
            field: "LOUDNESS",
            value: rawPayload.payload_fields.loudness
        },
        {
            field: "CO2",
            value: rawPayload.payload_fields.co2
        }
    ];
}

The rawPayload also allows access to many other values coming over the Webhook.

Please note that if you change the LoRaWAN Network Server, the rawPayload is differently structured. You can use the "normalizedPayload" instead but this won't give you access to the decoded fields.

Helium Example

{
   "app_eui":"001122334455667788",
   "dc":{
      "balance":22,
      "nonce":22
   },
   "decoded":{
      "payload":{
         "battery":2.34,
         "humidity":23.4,
         "temperature":22.20
      },
      "status":"success"
   },
   "dev_eui":"DEADBEEF00112233",
   "devaddr":"000000",
   "downlink_url":"",
   "fcnt":2034,
   "hotspots":[
   ],
   // ...
}

Decoder on Datacake

function Decoder(bytes, port) {
     
    return [
        {
            field: "BATTERY",
            value: decoded.payload.battery
        },
        {
            field: "HUMIDITY",
            value: decoded.payload.humidity
        },
        {
            field: "TEMPERATURE",
            value: decoded.payload.temperature
        }
    ];
}

Converter for TTN Decoder

When you have a Payload Decoder on TTN and you want to bring that on Datacake, you can copy and paste these decoders 1:1 in most of the cases.

You would, however, need to modify the Decoder in such a way that it returns the Data in a different way.

But instead of rewriting the existing decoder, you could use the following snippet to convert the output of the existing decoder into an output that is compatible with the Datacake API.

function Decoder(bytes, port) {
    
    // decode Payload from Sensor
    var decoded = ... // {temperature:23.2, co2:234, humidity:34, vdd:2345}
    
    // Array where we store the fields that are being sent to Datacake
    var datacakeFields = []
    
    // take each field from decodedElsysFields and convert them to Datacake format
    for (var key in decoded) {
        if (decoded.hasOwnProperty(key)) {           
            datacakeFields.push({field: key.toUpperCase(), value: decoded[key]})
        }
    }      
    
    // forward data to Datacake
    return datacakeFields;
}

Last updated 2 years ago

Was this helpful?