# The Things Stack

The Things Stack is a LoRaWAN network server that provides secure connectivity and management for LoRaWAN devices in production. Widgelix can be integrated with The Things Stack using webhooks. A webhook is an HTTP request (callback) that transfers data when triggered by an event. Once you create a webhook, Widgelix can read/write data from/to its endpoint.

## Configuring Connectivity

In Widgelix, click on Device in the left menu. The Devices page will be displayed, showing all the devices added to your organization.

Click on the device name for which you want to configure its connectivity.

On the **Device** page, click on the **Settings** tab.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FpwsAbUnweRXCyFIjXh6F%2Fdevice-43.png?alt=media&#x26;token=64262a78-8c4f-42db-95df-19b22eccf8df" alt=""><figcaption></figcaption></figure>

In the **Connectivity** section, click on the light blue rectangular area displaying a **disconnected adapter/The Things Stack** icon and the text '**Not Configured**'. The Things Stack is selected by default.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2F4uVnIO7cHmzzWSoM15cT%2Fdevice-44.png?alt=media&#x26;token=b274b389-3f32-4b58-84c5-668d427a4d60" alt=""><figcaption></figcaption></figure>

The **Network Server** model will be displayed.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2Fiq1iPlCyDvuehgDioQfV%2Fdevice-45.png?alt=media&#x26;token=ebbb8bd1-6379-47d3-9a35-b12bb8e43f85" alt=""><figcaption></figcaption></figure>

Click on **The Things Stack** in the list of network servers. The Things Stack is selected by default.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FdbWq7xPPfLasyREsKaOM%2Fdevice-46.png?alt=media&#x26;token=6c4e6cc8-7ebf-4968-a52e-12beda8f5400" alt=""><figcaption></figcaption></figure>

### Configuring Uplink Settings

Configuring uplinks enables The Things Stack to forward uplink messages from the end devices to Widgelix. Widgelix exposes an HTTP(S) endpoint, and its base URL is as follows:

`https://app.widgelix.com/v1/input-node/ttn`

When an uplink event occurs in The Things Stack, the uplink payload will be sent to Widgelix.

In the **Uplink** section, turn on the **Secure** option.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FotswnnakNXhC8Zveeq9N%2Fdevice-47.png?alt=media&#x26;token=ccef58bb-5830-447d-b0fc-43e3520a254c" alt=""><figcaption></figcaption></figure>

Copy the **API Key** by clicking the **Copy** button. You will need this key in the [Configuring The Things Stack](#configuring-the-things-stack) section.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FrjW8cWxA0tKgQckqLfgh%2Fdevice-48.png?alt=media&#x26;token=72a52e19-1c03-454a-85ab-f4e39fb66e17" alt=""><figcaption></figcaption></figure>

### Configuring Downlink Settings

Configuring downlink settings enables Widgelix to send downlink messages to end devices via The Things Stack.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2F4v9fzuQIx7DLp2jB5crd%2Fdevice-55.png?alt=media&#x26;token=3fe5e568-4c77-4ab0-a123-c93ca7c3bf5a" alt=""><figcaption></figcaption></figure>

In the Downlink section, configure the following:

**Device ID** - This is the ID of the device to which you want to send the downlink message. You can find it in the **End devices** list within your **The Things Stack** application, and it's typically prefixed with '**eui**' (e.g., `eui-0004a30b00xxxxxx`).

**URL** - The **server address** for The Things Stack, `https://eu1.cloud.thethings.network`for example. To find the server address for different **The Things Stack deployments**, please refer to the [Server Addresses](https://www.thethingsindustries.com/docs/the-things-stack/concepts/server-addresses/) section in The Things Stack documentation.

**Application  Id** - The Application ID associated with this device in The Things Stack.

**API Key** - The API key you have created with **write downlink application traffic** rights in The Things Stack. Read the [Creating Downlink API Key](#creating-downlink-api-key) section to learn more about that.

**Port** - The frame port (fPort) of the downlink. The default value is 0.

**Webhook Id** - The Webhook ID you have given in The Things Stack for this integration.

## Configuring The Things Stack

The Things Stack offers a webhook template for Widgelix that you can instantiate to set up a new webhook. The webhook you will create enables you to forward your LoRaWAN device data from The Things Stack to Widgelix.

On The Things Stack, click on **Integrations** and then click on **Webhooks**.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FywCPytdeFTo1WTZKsyC0%2Fdevice-49.png?alt=media&#x26;token=fd7852e9-a325-47e4-bbf3-0b24c1fa7de5" alt=""><figcaption></figcaption></figure>

On the **Webhooks** page, click on the **+ Add webhook** button.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2Fdzt3vVuZWHV7UB0JBbth%2Fdevice-50.png?alt=media&#x26;token=cec0ae11-0856-4541-9cd7-12a661869ba0" alt=""><figcaption></figcaption></figure>

Scroll down the page and choose the **Widgelix** webhook template.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FCkMCHY0zvTZUDeSvFnH7%2Fdevice-51.png?alt=media&#x26;token=7a64b3f5-bed2-4b53-8e6a-a5e47c68d70f" alt=""><figcaption></figcaption></figure>

On the **Setup webhook for the Widgelix** page, configure the following mandatory settings.

In the **Webhook ID**  text box, enter a unique name for your webhook, avoiding spaces in the name.

In the **API Key** text box, paste the API Key you have copied from the Widgelix in the previous section.

After configuring, click on the **Create Widgelix webhook** button.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2Fgxo3zQObUqcHz6n4YenV%2Fdevice-52.png?alt=media&#x26;token=d8a56db3-7c6e-49d8-b47b-4eb33567ecd9" alt=""><figcaption></figcaption></figure>

You will be navigated to the **Webhooks** page and your newly created webhook can be found in the webhooks list.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FqXaeR0DV9XiAsSIPPOYJ%2Fdevice-53.png?alt=media&#x26;token=6960f8b4-a043-43e8-8fda-202ca6983f3e" alt=""><figcaption></figcaption></figure>

Now Widgelix can accept **uplinks** from your LoRaWAN end device.&#x20;

To confirm, navigate to the **Devices** page on **Widgelix**, and then click on your **device's name**. You'll be able to see that your device is online (check the 'Last seen' status) and that the dashboard is populated with incoming uplink data (if you have added any widgets to the dashboard).

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2Fz5WbCyFgJQc1F4IWDvJP%2Fdevice-54.png?alt=media&#x26;token=d4e38f32-8785-4555-b4e6-05f351e0dea6" alt=""><figcaption></figcaption></figure>

### Creating Downlink API Key

To send downlinks from Widgelix, first, you should create an API key with the downlink traffic writing rights in The Things Stack console.

In your The Things Stack application, click on **API keys** in the left menu.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FrTvJDgSok6lZtm3kJILO%2Fdevice-56.png?alt=media&#x26;token=83c4aa19-8615-4f50-9f4b-d40d6f9b84d4" alt=""><figcaption></figcaption></figure>

Click on the **+ Add API key** button.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2F4kx4aDVatRRCsmah7DCG%2Fdevice-57.png?alt=media&#x26;token=2f148008-bea2-4f89-8a10-11d934d21e14" alt=""><figcaption></figcaption></figure>

On the **Add API Key** page, under **Rights**, click on the **Grant individual rights** option, and then select the **Write downlink application traffic** option. Afterwards, click the **Create API Key** button.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2F3FjIQJBpHABXEIHPxZ9p%2Fdevice-58.png?alt=media&#x26;token=c685a6d4-919a-4bda-82fc-036213a37101" alt=""><figcaption></figcaption></figure>

The API key information modal will be displayed. Click on the **Copy** button to copy the API key. Make sure to save the copied API key in a text file because you will need it to [configure the downlink](#configuring-downlink) settings in Widgelix.

After copying the API key, click on the **I have copied the key** button.

{% hint style="danger" %}
Make sure to save the API key now, as it won't be recoverable once you navigate away from this page.
{% endhint %}

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2F40FEQrS5ylUzUTqwx6EH%2Fdevice-59.png?alt=media&#x26;token=5f46ed97-88bf-4bc4-bda8-97878abc3fb6" alt=""><figcaption></figcaption></figure>

You will be navigated to the **API keys** page, where you can see your newly created API **Key ID** with the '**write downlink application traffic**' rights.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2F0mEJYkBLx30qYE3zZr1h%2Fdevice-60.png?alt=media&#x26;token=731e3d6a-c65a-4626-bad0-c768e04b3bf9" alt=""><figcaption></figcaption></figure>
