how to integrate rak gateway with thingsboard via mqtt

Learn how to integrate LoRaWAN® data from the RAK gateway built-in Network Server into ThingsBoard using MQTT for quick, cost‑effective IoT setups. This guide explains how to integrate application data from the built-in Network Server (NS) of the RAK gateway into ThingsBoard, a popular open-source IoT platform, using the MQTT protocol. 

By utilizing the built-in NS, users can bypass the complexity and cost associated with deploying a separate LoRaWAN network server. This solution is ideal for small-scale industrial deployments that require low latency, minimal infrastructure, and a quick setup.

Node to Server Road Map
Figure 1: Node to Server Road Map

In this example, a public MQTT broker, HiveMQ, is used to bridge the data between the RAK gateway and ThingsBoard.

Prerequisites

Before you begin, ensure the following prerequisites are met:

Configure the RAK Gateway

Set Gateway Work Mode and Add Device

Before proceeding, ensure that your gateway is configured to use the built-in LoRaWAN network server and your node has been added to an application.

For detailed instructions, refer to the WisGateOS User Manual.

Configure MQTT Integration

  1. Navigate to LoRa® > Configuration > Integration Interface Parameters in the gateway’s Web UI.
  2. Enable the Integration Interface option and select Generic MQTT as the Integration mode.
  3. Configure the following MQTT parameters:
  • MQTT Broker Address: Enter the hostname of your MQTT server. Example: broker.hivemq.com
  • MQTT Broker Port: 1883
  • Set up the topic fields according to your application and device configuration.
WisGateOS 2 MQTT Parameters
Figure 2: WisGateOS 2 MQTT Parameters
  1. Click Save changes to apply the configuration.

Configure the ThingsBoard

  1. Log in to your ThingsBoard instance. If you don't have an account, create one before proceeding.
Login to ThingsBoard
Figure 3: Login to ThingsBoard
  1. After successfully logging in, you will be taken to the ThingsBoard homepage.
ThingsBoard Home Page
Figure 4: ThingsBoard Home Page
  1. Click Integration Center > Data Converters in the left navigation tree to create a data converter for the uplink.
ThingsBoard Data converters page
Figure 5: ThingsBoard Data converters page
  1. Click the icon + and choose the Create new converter option.
Create new data converter in ThingsBoard
Figure 6: Create new data converter in ThingsBoard
  1. In the configuration interface, keep the Converter type set to Uplink (default). Select MQTT for the Integration type, enter a name for the decoder in the Name field (e.g., Uplink Decoder), and then choose JS (JavaScript) for the decoding configuration.

ThingsBoard Decoder Page
Figure 7: ThingsBoard Decoder Page
  1. Paste your device-specific decoder script into the code editor, then click Add to save.
🗒️
NOTE

The script below is for reference only. Please adjust it according to your device’s payload format.

 

/** Decoder **/

// decode payload to string

var payloadStr = decodeToString(payload);
var data = JSON.parse(payloadStr).data;
var bytes = atob(data).split('').map(function (c) {
  return c.charCodeAt(0);
});

var values = {};

let i = 0;
while (i < bytes.length) {

var channelId = (bytes[i] << 8) | bytes[i + 1];
var value = (bytes[i + 2] << 8) | bytes[i + 3];
i += 4;

switch (channelId) {

  case 0x01BE:
  values.wind_speed = value / 100;
break;

  case 0x02BF:
  values.wind_direction = value;
break;

  case 0x0367:
  values.temperature = value / 10.0;
break;

  case 0x0470:
  values.humidity = value / 10.0;
break;

  case 0x0573:
  values.pressure = value / 10.0;
break;

default:
break;

}
}

var integrationName = 'MQTT Integration';
var deviceName = 'dev_ac1f09fffe08f2a9';

var result = {
  deviceName: deviceName,
  attributes: {
  integrationName: metadata['integrationName'],

    wind_direction: values.wind_direction,
    wind_speed: values.wind_speed,
    temperature: values.temperature,
    humidity: values.humidity,
    pressure: values.pressure,

},

};

/** Helper functions **/

function decodeToString(payload) {
  return String.fromCharCode.apply(String, payload);
}

return result;

 

  1. Navigate to the Integration Center > Integrations menu and click the icon + to add the MQTT integration.
ThingsBoard Integrations Page
Figure 8: ThingsBoard Integrations Page
  1. Enter the name of the integration (for example, MQTT Integration) in the Name field and select MQTT from the Integration type drop-down menu. Click Next to proceed.
ThingsBoard Add MQTT Integration 
Figure 9: ThingsBoard Add MQTT Integration 
  1. In the Uplink data converter options, click Select existing to choose the previously created decoder (Uplink Decoder), and then click Next.
hingsBoard add integrations for uplink decoder
Figure 10: ThingsBoard add integrations for uplink decoder
  1. In the Downlink Data Converter interface, no configuration is necessary; simply click Skip to bypass this setup.

  2. Enter the address broker.hivemq.com in the Host field, and enter the port number 1883. Click the Add Topic Filter button to configure the subscription topic.

Configure the connection options
Figure 11: ThingsBoard final parameters for integration

Subscription topics:

SUBSCRIPTION TOPIC DESCRIPTION
application/{{application_name}}/device/{{device_EUI}}/join Device join event
application/{{application_name}}/device/{{device_EUI}}/rx Uplink data
application/{{application_name}}/device/{{device_EUI}}/tx Downlink sent
application/{{application_name}}/device/{{device_EUI}}/ack Acknowledgment of downlink
application/{{application_name}}/device/{{device_EUI}}/status Device status update
🗒️
NOTE

Replace application_name and device_EUI with your actual application ID and device EUI. All topic values must be lowercase.

 

  1. Click the Add button to save and finalize the settings.
  2. Once the device has joined and is sending uplink data, check the uplink data in ThingsBoard > Integrations > Your Integration > Events.
ThingsBoard Integrations Events
Figure 12: ThingsBoard Integrations Events

Visualize Data in ThingsBoard

After successfully creating the data converter, completing the integration, and receiving uplink data (visible in the Events tab), follow these steps to visualize your device data:

  1. Navigate to Entities > Devices > Groups.
  2. Click the group named All in the Device groups menu. The device should automatically appear based on your decoder logic.
ThingsBoard Devices Page
Figure 13: ThingsBoard Devices Page
  1. Click on the device and go to the Attributes tab to view real-time values such as temperature, humidity, wind speed, etc.
ThingsBoard Devices Attributes
Figure 14: ThingsBoard Devices Attributes
  1. To visualize the data, select a specific data field (e.g., humidity) by checking the corresponding box.
ThingsBoard Attributed Selected
Figure 15: ThingsBoard Attributed Selected 
  1. Click Show on widget.
  2. In the Current bundle dropdown, select a widget category (e.g., Analog gauges), then click Add to dashboard.
ThingsBoard Select Gauge for Attribute
Figure 16: ThingsBoard Select Gauge for Attribute
  1. In the Add Widget to Dashboard window:
  • If no dashboard exists, select Create New Dashboard, then enter a name (e.g., Sensor Hub).
  • Optionally, enable Open Dashboard to view it immediately after adding the widget.
🗒️
NOTE

If you don’t check Open Dashboard, you can later access the dashboard via Dashboard Groups  - All - [Group Name].

  1. Click Add to save and apply the configuration.
ThingsBoard add widget to the dashboard
Figure 17: ThingsBoard add widget to the dashboard

 

ThingsBoard dashboard with the widget
Figure 18: ThingsBoard dashboard with the widget 
  1. To visualize additional data (e.g., temperature, pressure):
  • Repeat the steps above.
  • When prompted, choose Select existing dashboard, then select your previously created dashboard (e.g., Sensor Hub).
ThingsBoard final dashboard with all the widgets
Figure 19: ThingsBoard final dashboard with all the widgets

Troubleshooting

ISSUE CAUSE SOLUTION
No data in the ThingsBoard Events tab MQTT is not connected or has wrong topic filters Verify broker URL, port (1883), and topic format
Decoder returns empty values Incorrect JavaScript logic or unexpected payload Debug using TBEL/JS preview in ThingsBoard
Gateway fails to connect to MQTT No internet access or DNS resolution failure Check the gateway’s network and DNS settings

FAQs

  1. Can I use a private MQTT broker instead of HiveMQ?
    Yes, simply replace the broker address with your own MQTT broker hostname.
  2. Why choose the built-in NS instead of a cloud-based LNS?
    The built-in NS is ideal for quick prototyping or isolated deployments, as it reduces infrastructure requirements and simplifies installation.
  3. Can I perform downlink commands from ThingsBoard?
    Yes, this is possible with additional configuration for a downlink decoder and appropriate topics.
  4. Why is my device not joining the network despite proper configuration?
    Double-check the device’s EUI and AppKey, and ensure that the gateway has adequate LoRa® coverage and correct frequency settings.
  5. Why does the gateway show as connected but no data appears in ThingsBoard?
    Check the following:
  • MQTT broker connection (is the address and port correct?)
  • Topic format (must match the actual application and device EUI, all in lowercase)
  • Decoder script (must correspond to the device’s payload format)
  • Also, ensure that the Integration Interface is enabled on the
    gateway.

Changelog
  • Version 1.1 - Added UTM links
    • Date Published: 09/01/2025
  • Version 1 - How to Integrate RAK WisGate Lite 2 with ThingsBoard via MQTT
    • Date Published: 08/14/2025


 

Updated