# Sending Simple Data to Antares

In this project you will be directed to send dummy data from **STM32L072 LoRa Discovery Kit B-L072-LRWAN1** to **Antares IoT Platform** using LoRa connectivity with LoRaWAN protocol.

The LoRaWAN protocol is divided into two classes, Class A and Class C, each class has its own advantages and disadvantages, for more details please visit the following page.

{% content-ref url="../esp32-lora/lorawan-class" %}
[lorawan-class](https://docs.antares.id/en/code-and-library-examples/esp32-lora/lorawan-class)
{% endcontent-ref %}

## Prerequisites

The required materials follow the **General Prerequisites** on the previous page. If you have not prepared the requirements on that page, then you can visit the following page.

{% content-ref url="general-prerequisites-stm32-lora-stm32cube-ide" %}
[general-prerequisites-stm32-lora-stm32cube-ide](https://docs.antares.id/en/code-and-library-examples/stm32-lora-stm32cube-ide/general-prerequisites-stm32-lora-stm32cube-ide)
{% endcontent-ref %}

## Follow These Steps

### 1. Open the STM32 Cube IDE application

### 2.Import LoRaWAN Project End\_Node

In this section, we will explain how to import a project into the STM32 Cube IDE from the I-CUBE-LRWAN expansion software.

You can start creating an application using the STM32Cube IDE. The STM32Cube IDE uses workspaces to store the application files that we will create. You can leave it by default, or create a new workspace, as well as select a workspace that you have already created.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FaYZZhjzt1A4yndVcBFTk%2Fimage.png?alt=media&#x26;token=c60635d8-6df3-489c-a885-34e4ccdcc8ac" alt=""><figcaption><p>Selecting a Workspace in STM32CUBE IDE</p></figcaption></figure>

After selecting the directory for the workspace, you can click the launch button until the start page of the STM32 CUBE IDE appears.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2F0alykG3eXEaaEbbCSolb%2Fimage.png?alt=media&#x26;token=08b9d898-e8a0-4177-b275-2f4ad77607e9" alt=""><figcaption><p>STM32CUBE IDE Home Page</p></figcaption></figure>

To use the sample application provided by the I-CUBE-LRWAN expansion software, you can import the application provided in the expansion folder. In this example, we will use the LoRaWAN\_End\_Node example found in the **STM32CubeExpansion\_LRWAN\_V2.1.0\Projects\B-L072Z-LRWAN1\Applications\LoRaWAN\LoRaWAN\_End\_Node\LoRaWAN\App folder.**

In the next step, we need to import the project files in the STM32 Cube Expansion folder into the STM32 Cube IDE software. To import the **files**, click on the file and select **Open Projects from File System.**

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FqCKvUF0mJ2mxd7TzKZTB%2Fimage.png?alt=media&#x26;token=504004c3-bcd1-40a8-ad67-85b7fcb6892b" alt=""><figcaption><p>Import Project</p></figcaption></figure>

Then click **Directory** to select the location of the project to import. For this tutorial, the project to be imported is in the following folder: **STM32CubeExpansion\_LRWAN\_V2.1.0\Projects\B-L072Z-LRWAN1\Applications\LoRaWAN\LoRaWAN\_End\_Nod**e. After that click **finish**.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2F4r9NnMz6WQAd7YKvOaGR%2Fimage.png?alt=media&#x26;token=ee4616bf-ab2c-4f28-984b-b9fc720a70c3" alt=""><figcaption><p>Directory for Import Project</p></figcaption></figure>

After the project is successfully imported, the files in the project will be displayed on the left side of the STM32 Cube IDE as follows.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FfV0TyLvzTpm3LO0YRZ9O%2Fimage.png?alt=media&#x26;token=0f085b08-c2e2-4ca4-9838-6e6d273e0b72" alt=""><figcaption><p>STM32 Cube IDE View after Import Project</p></figcaption></figure>

### 3. Set LoRaWAN Parameters in Programme Code

This section will explain how to integrate the **STM32L072 LoRa Discovery Kit** board with the Antares platform.

Firstly, select the lora\_app.h file located in the **LoRaWAN\_End\_Node/LoRaWAN/App** folder. The sample programme provided in the file does not yet match the LoRaWAN Indonesia frequency. Therefore, you need to customise it.

On line 43 of the programme it says LORAMAC\_REGION\_EU868. To adjust to the LoRaWAN frequency in Indonesia, please change that part to LORAMAC\_REGION\_AS923.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2Fhz3isNUA1iAr7X2G3VAF%2Fimage.png?alt=media&#x26;token=0ca0ce37-4233-4f69-9954-905a37f470d1" alt=""><figcaption><p>Programme snippet before change</p></figcaption></figure>

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FT9Tv5Hx5A0qECFQSwbrx%2Fimage.png?alt=media&#x26;token=8b0eaed2-c83b-4f52-a25f-5d4bb78b4a5a" alt=""><figcaption><p>Programme snippet after change</p></figcaption></figure>

Next, select the lorawan\_conf.h file located in the **LoRaWAN\_End\_Node/LoRaWAN/Target** folder. In the programme in the file there are parts that need to be adjusted which are still related to the LoRaWan frequency in Indonesia. On line 49, it can be seen that the programme code uses **REGION\_EU868** which is not in accordance with the LoRaWan frequency in Indonesia.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FQfsu5yotZMbTa6wpVEvY%2Fimage.png?alt=media&#x26;token=3ab3e011-b812-4fec-a1c1-8c60a1e12fcf" alt=""><figcaption><p>Program Code Before Customisation</p></figcaption></figure>

So for line 49, it can be made into a comment as follows.

```
/*#define REGION_EU868*/
```

Then for this programme, REGION\_AS923 is selected. So that line 44 can be uncommented as follows.

```
#define REGION_AS923
```

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FqLgaKUDSala22RCItoHZ%2Fimage.png?alt=media&#x26;token=fe98d79d-3333-44fb-97ee-77cf0c595427" alt=""><figcaption><p>Program Code After Customisation</p></figcaption></figure>

Next, add the following one line of code to the programme after the define REGION\_AS923 section.

```
#define REGION_AS923_DEFAULT_CHANNEL_PLAN 2
```

Here's how the code looks after adding it.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FBE3xUDfUSS2mAKsLzzPy%2Fimage.png?alt=media&#x26;token=bde4ed22-4ad1-4686-9580-a3bab3ad3570" alt=""><figcaption><p>Code Display</p></figcaption></figure>

You can then build the application using **CTRL+B**, or you can choose the **Project tab > Build All**.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2F1aK3IkDcFTf4uvJ5fDZK%2Fimage.png?alt=media&#x26;token=c0f4ceaf-81e7-4c17-a9bf-b6c1f5bcd3a0" alt=""><figcaption><p>Build Project</p></figcaption></figure>

Then to download the programme into the **B-L072Z-LRWAN** board, you can press F11 on the keyboard or by selecting the **Run > Debug tab.**

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FuqKSTQlFKSZaZOFFeRoI%2Fimage.png?alt=media&#x26;token=c166cb1b-4f2d-47f9-be77-38b64a0ea2b7" alt=""><figcaption><p>Run Debug</p></figcaption></figure>

Then the console will say **"Download verified successfully"** indicating that the programme was successfully downloaded to the board.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FqtfazYNMINJmFnoJTGgk%2Fimage.png?alt=media&#x26;token=5011a171-97b3-43b6-8391-26ee6d89d3d8" alt=""><figcaption><p>Programme download page</p></figcaption></figure>

Once the programme has been downloaded to the board, you can view the programme log by clicking on the **open console** icon in the STM32Cube IDE. Then select **Command Shell Console.**

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FTI4HQOLR5ZtLlYEQihQ5%2Fimage.png?alt=media&#x26;token=28061123-ffde-4d25-bb74-a13e656d707e" alt=""><figcaption><p>Open Console</p></figcaption></figure>

The following is a view of the **Command Shell Console**.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FGYlYkzCY2VRykz5gJrFT%2Fimage.png?alt=media&#x26;token=94e4eb0a-910a-4f0d-a2c4-145c78705e77" alt=""><figcaption><p>Remote Connection</p></figcaption></figure>

Next, in Connection Type, select **Serial Port.**

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FRonCNQSblPAPjPUZ3u7L%2Fimage.png?alt=media&#x26;token=b9d5c15b-d41f-4d6c-88a5-ce0135580616" alt=""><figcaption><p>Set Connection Type</p></figcaption></figure>

Then in the Connection name option, press **New**. It can be seen that the connection name section is still empty. Because the port connection has not been registered, you can freely name this connection. For example, the connection name is COM4 (Adjusts to the serial port). Next, click finish.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FUYhXxyIW31tp26s9OMUt%2Fimage.png?alt=media&#x26;token=4335d4e5-00a8-46d8-a990-e5aec56d2aaa" alt=""><figcaption><p>Connection Name</p></figcaption></figure>

Next, in the connection name, select COM4 that has just been added. Then, click **OK**.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FJfDn44FWCj2FaSBXWpOq%2Fimage.png?alt=media&#x26;token=3cf552cb-20cd-4675-b53f-b328f523adca" alt=""><figcaption><p>Connection Name</p></figcaption></figure>

Here is the view of the console. The console is still empty and does not display anything yet. It can be seen at the top of the console showing that **COM4** (CONNECTED).

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FeaaHPRvo3Ps63KIZDLsu%2Fimage.png?alt=media&#x26;token=399f48f8-167f-4373-8895-178ed48b7f06" alt=""><figcaption><p>Communication Port Display Successfully Opened</p></figcaption></figure>

To be able to get information from the board such as **Application EUI, Device EUI, and Application Key** on the console display, press the reset button of the board once until information about the board appears on the console. The following is the information of the board displayed by the console.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2F8C8DzfaPSmRlI1lIDizq%2Fimage.png?alt=media&#x26;token=c06ad6be-9d2b-42a0-8b44-ea170e1ac7f3" alt=""><figcaption><p>Information Display Board</p></figcaption></figure>

Information from the board is used to connect the board with the Antares platform.

### 4. Set LoRaWAN Parameters in Antares

After logging into the Antares platform, select **Application** and click **Create an Application**.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2F97Iqllxv0cPITfs3Pszk%2Fimage.png?alt=media&#x26;token=bcf37fba-27ca-4973-be66-351b74981aec" alt=""><figcaption><p>Creating Applications in Antares</p></figcaption></figure>

Then fill in the Application Name and Application ID. In this tutorial, let's say the Application Name is LoraSTM32 and the Application ID is 1. Then press **Add**.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FLWL9Vb3eXphkDKVxfBy9%2Fimage.png?alt=media&#x26;token=536ba988-677f-45f9-8243-9c3f9dd7fede" alt=""><figcaption><p>Add Application</p></figcaption></figure>

Next, add a device in the application. In this tutorial, the name of the device created is **Lorawan**. After the device is created, click **Set Lora.**

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FVppRZjmi0Z3MWR9hIf6J%2Fimage.png?alt=media&#x26;token=a357b917-f2d5-4752-a555-dfade187ed57" alt=""><figcaption><p>Set Lora</p></figcaption></figure>

The example programme given earlier uses **class A** with OTAA **activation mode OTAA parameters**, such as **Application EUI**, **Device EUI, and Application Key** can be found in the log as shown in Figure 15.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FasS7zOJ1dljeaU85VBq6%2Fimage.png?alt=media&#x26;token=416efe33-6c2f-4794-bfbf-f39d2f79d61e" alt=""><figcaption><p>Parameter Input on Lora Set Menu</p></figcaption></figure>

### 5. Run Program

To be able to connect the board with devices on the Antares platform, click Run > Run in the STM32 CUBE IDE.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2F5A8LcpJpgPxhqztWUo7W%2Fimage.png?alt=media&#x26;token=0ab05877-449e-4a3d-85a6-646f01a0b361" alt=""><figcaption><p>Running the program</p></figcaption></figure>

After the programme is run, it can be seen on the console that the device is connected to the Antares platform so it says **Joined** as follows.

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FbYp70YbyMQB1BdqgDmue%2Fimage.png?alt=media&#x26;token=99f5fc78-a470-444c-8d7e-423bd1e912b8" alt=""><figcaption><p>Board successfully connected to Antares Platform</p></figcaption></figure>

### 6. Check Data in Antares

Setelah upload program berhasil, selanjutnya buka halaman device antares kemudian lihat apakah data lora sudah berhasil dikirim.&#x20;

<figure><img src="https://3873791589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cujmJ5QHdJaAjH815aZ%2Fuploads%2FFPVmjMKl7Uhg5KHaylkf%2Fimage.png?alt=media&#x26;token=c65976e8-77a0-4f7c-a629-472230366b22" alt=""><figcaption><p>Data Received on the Antares Platform</p></figcaption></figure>

{% hint style="info" %}
Data sent from the **STM32L072 LoRa Discovery Kit B-L072-LRWAN1** are **"counter"**, **"port"**, and a message in the JSON field **"data"**. While other parameters are supporting parameters generated by the Antares LoRaWAN Infrastructure.
{% endhint %}
