Kaa Documentation

LoRaWAN Integration

Overview

This tutorial provides step-by-step instructions for connecting and integrating any LoRaWAN device with the Kaa Platform. It is compatible with The Things Network (TTN), The Things Industries (TTI), as well as self-hosted instances.

In this guide, we use the MikroTik KNOT LR8 Kit as the LoRaWAN gateway. While gateway configuration steps may vary depending on your specific hardware, the integration process for LoRaWAN devices remains mostly the same across different setups.

Preparation

Before starting, make sure you have the following tools and accounts ready:

  1. The Things Network (TTN) account
    You’ll need an account on The Things Network, The Things Industries, or your own self-hosted instance.
    In this tutorial, we’ll primarily use TTN, but the process is similar for TTI and self-hosted TTN setups.

  2. Kaa account
    To forward and process your data in the Kaa Platform, you’ll need an account.

  3. LoRaWAN Device
    For this example, we’ll integrate a Sensative multi-sensor.
    However, any other LoRaWAN-compliant device should work with similar configuration steps.

  4. LoRaWAN Gateway
    We’ll be using the MikroTik KNOT LR8 Kit, which includes a built-in LoRaWAN gateway. You may use a different gateway, but configuration steps may vary.

MikroTik KNOT LR8 Kit Initial Setup

To begin, configure the MikroTik KNOT LR8 Kit:

  1. Power on your MikroTik device and connect it to your LAN network.
  2. Connect the MikroTik directly to your PC via Ethernet to access its web interface.
  3. Access the MikroTik web UI by navigating to http://192.168.88.1 in your browser. The default login is admin with no password.

Note: If you encounter issues accessing the UI, you may need to reset the device to factory settings.
Refer to this official guide for reset instructions.

Leave the default settings as they are for now. We’ll return to them later.
However, it is recommended to set a password by navigating to System -> Password

mikrotik_default_settings

TTN Console

After successfully logging in, navigate to the TTN Console.

You’ll be prompted to choose a regional network cluster, such as:

  • eu1 – Europe
  • nam1 – North America
  • au1 – Australia

Select the cluster according to the gateway (devices) location. Once you’ve selected the network cluster, you’ll be redirected to the TTN Console.

MikroTik Gateway Setup

To register your MikroTik LoRaWAN gateway on The Things Network (TTN), you need to configure both the TTN console and the MikroTik.

Specify Network Server

The first step is to define the LoRaWAN network server that your MikroTik gateway will connect to.

Follow these steps:

  1. Open MikroTik’s LoRa settings and navigate to IoT -> LoRa -> Servers.
    Mikrotik Network Servers Tab

  2. Add a new server:

    • For Name, enter any custom name (e.g., my-server).
    • For Address, enter the domain name of your TTN cluster (e.g., eu1.cloud.thethings.network).
      Use the appropriate address for TTI or your self-hosted instance.
      Mikrotik New Server

Configure MikroTik’s LoRa Gateway

  1. Go to IoT -> LoRa -> Devices, and click on the listed gateway (there should only be one). Mikrotik Lora Gateway List
  2. Configure the following fields:

    • Gateway ID:
      This is the unique identifier used by TTN to register your gateway.
      You can create a custom ID using letters, numbers, and hyphens.

      Important: Do not copy the Gateway ID from the screenshot below. For security reasons, create your own.

    • Network Server:
      Select the my-server you created in the previous step.

    • Channel Plan:
      Select the plan that matches your LoRaWAN device’s frequency band, which is typically printed on the device’s packaging.
      For example, use EU868 for European devices that operate on the 868 MHz band.

    Note: You can find a complete list of supported LoRa frequency plans here.

    Mikrotik Lora Settings

  3. Apply the changes. Important: You cannot modify settings while the gateway is enabled.
    To apply changes:
    • First disable the gateway.
    • Make your configuration changes.
    • Then re-enable the gateway after applying the settings.

TTN Gateway Setup

Now that your MikroTik gateway is configured, it’s time to connect it to The Things Network (TTN).

Follow these steps:

  1. In the TTN Console, navigate to Gateways -> Register Gateway.
    ttn_gateway_ui

  2. Fill in the required fields using the information from your MikroTik gateway settings.
    • Copy the Gateway ID, Frequency Plan, and other relevant settings from the MikroTik UI.
    • Paste them into the corresponding fields in the TTN registration form.
      TTN Gateway Fillup
  3. In the TTN Console UI, scroll down and click Register Gateway.

  4. In the MikroTik UI, ensure the LoRa gateway is enabled.

Your gateway should connect to the TTN server within 1–3 minutes.

If it doesn’t connect:

  • Try restarting your MikroTik router by powering it off and back on. After that, wait another 1–3 minutes.
  • If the issue persists, double-check all fields to ensure they were entered correctly and match your TTN configuration.

TTN Application Setup

First of all we need to create Application on the TTN. In The Things Network (TTN), an Application is a logical container that groups one or more LoRaWAN devices. It defines how devices are managed, identified, and how their uplink/downlink messages are routed to integrations or external platforms.
Follow these steps to set it up:

  1. Navigate to the Applications tab and click Add Application.

    ttn_application_ui

  2. Create a new application:

    • Enter a unique Application ID (you can choose any name).
    • The App Name and Description are optional.

Register New TTN Device

When the Application is created, we can go to the Device creation. In this section, we’ll register a Sensative Multi-Sensor as an example.
Even if you’re using a different LoRaWAN device, the steps will be mostly the same.

Start by navigating to your previously created TTN Application.
From there, click Register end device.

Register New Device UI

  1. Register your device:
    • Search for your device’s manufacturer (for Sensative sensors, it’s Sensative AB).
    • Select the correct sensor model (e.g., Strips).
    • Choose the appropriate Profile (Frequency) Region. For Sensative sensors, it’s EU 868.

    TTN Device Basic Settings

  2. Obtain device credentials: You’ll need the following three identifiers:
    • APP_EUI (also called JOIN_EUI)
    • DEV_EUI
    • APP_KEY

    These are usually printed on the box or a card inside your device packaging.
    If you can’t find them or they seem invalid, contact the manufacturer.

  3. Enter the credentials: Paste the APP_EUI, DEV_EUI, and APP_KEY into their respective fields in the TTN UI and complete the device registration.

  4. Prepare your sensor: If possible, reboot or reset the device so it initiates a join request to the TTN network.

  5. Check live data:
    • Open the Live Data tab in TTN and look for join requests or uplinks.
    • If no data appears, try restarting your device and manually sending data. Also, check the logs in your LoRa gateway.
    • If payloads appear but aren’t decoded, navigate to the device page -> Payload formatters. Select “Use device repository formatters” from the dropdown.
    • If decoding still fails, click View formatter code, copy it, and paste it into the Custom JavaScript Formatter section for manual tweaking.
    • If all else fails, search your manufacturer’s documentation or forums for the correct payload formatter code.

Create a TTN API Key

To be able to configure data forwarding from TTN to the Kaa Platform, first of all, you need to create an API key with the appropriate permissions.

Follow these steps:

  1. In the TTN Console, go to API keys -> Add API key. TTN Create API Key
  2. Grant the key all available permissions to allow Kaa full access to fetch data from TTN.

    Note: Minimal required permissions are: view devices in application, view application information, link Application to a Network Server for traffic exchange.

TTN Full Access API Key

  1. Click Create, then copy the API key. It will not be shown again after this step.

Integrating TTN Device with Kaa

Follow these steps:

  1. Create a New Application
    In the Kaa UI, navigate to the Applications tab and click Create application.

    KaaIoT Application Setup

  2. Add a LoRaWAN Application Integration
    Go to the LoRaWAN -> Device integrations and click Add integration.

    KaaIoT Integration

  3. Register the Application Integration
    In the popup dialog, enter the required application integration details.
    Follow the instructions shown in the screenshot.
    For TTN API Key, paste the key you created earlier.

    Kaa LoRa Integration

  4. Complete the Integration
    If all credentials are correct, the application integration should be created successfully.

  5. Add Your Device
    • Click on the newly created application integration.
    • Click Add a new device.
    • In the popup menu, select the default application version and the device you’ve connected.
      You can identify it by the DEV_EUI you entered during TTN registration.

    KaaIoT Create Device

  6. View Your Device
    Open the Devices tab to view your registered device, monitor payloads, and access real-time graphs.

    KaaIoT Devices

This completes the integration of your TTN device with the Kaa Platform.

Fix the Payload (Optional)

Often, data is nested several levels deep within objects.
Since different devices send varying payload formats, Kaa provides tools to handle this complexity.
We can use the Rule Engine to parse and transform the payload into a more manageable format.

Note: While you can modify payload formatting on the TTN side, it’s often better to keep the original formatter code intact and perform transformations within Kaa.

To keep things simple, we’ll create a rule that parses incoming data for every device in the application whenever data is received. Follow these steps:

  1. Navigate to the Rules tab on the sidebar and create a new rule.

  2. Create an Endpoint data sample updated trigger.
    This trigger will activate the rule whenever any device in the Kaa application receives new data. Leave the endpoint field empty to apply the rule to all devices.

    Create Trigger

  3. Create a condition: Since we don’t need a specific condition to parse data, set the condition to return true.

    Create Condition

  4. Create an action: Finally, define the action that will parse the data. This action will unpack nested values one level deep. Use the following code:

     // Transform the data
     const transformObject = obj => {
       const result = {};
       for (const key in obj) {
           result[key] = obj[key]?.value || obj[key]
       }
       return result;
     };
    
     // Extract the data samples object
     const dataSamplesArray = ctx.trigger.endpointDataSamplesReceived.dataSamples;
     const dataSamples = dataSamplesArray[1];
    
     // Apply transformation
     const transformedData = [transformObject(dataSamples)];
     return transformedData;
    

    Create Action

  5. Final step: Create the rule, then return to your device page to verify that additional values are now displayed.

    Device Page