How to use Raspberry Pi as node in LoRAWAN

What is LoRaWAN?

LoRaWAN is a Medium Access Control (MAC) protocol for wide area networks. It is designed to allow low-powered devices to communicate with Internet-connected applications over long-range wireless connections.

LoRaWAN can be mapped to the second and third layers of the OSI model. It is implemented on top of LoRa or FSK modulation in industrial, scientific, and medical (ISM) radio bands. The LoRaWAN protocols are defined by the LoRa Alliance and formalized in the LoRaWAN specification.

Material Required is as follows:

1.LoRa Bee module

2.LoRa Gateway Router

3.Raspberry Pi

4.The Things Network Account

Circuit Diagram

Pin Details

LoRe Bee

LoRe Bee

physical pin

Raspberry Pi

physical pin

























Step 1: Setup The Things Network Console

Setting up the TTN console consists of three steps:

1. Registering the gateway

2. Adding the application

3. Registering the devices

These steps are described below:

  1. Registering the gateway

First, you have to register the gateway on the things network. Visit:

Log in to your account or sign up for a new account. Click on the profile button in the top right corner and from the dropdown select “Console” option. This is shown in the image below.

From the console page, click on the Gateways option as can be seen in the image below.

Select register gateway

Enter the following details on the form that shows up:

  1. Your Gateway EUI (You can find this on the gateway device itself, or check the manufacturer’s manual)
  2. Check the “I’m using the legacy forwarder” option
  3. Description about the gateway. This can help you identify various gateways if you use multiple gateways
  4. Select the frequency plan as India 865-867MHz
  5. For antenna placement, select the type of gateway, ie. Indoor or Outdoor.

Once these details are entered, click on “Register Gateway”

    2. Adding the application 

Go back to the console page and click on Application. Next, click on “Add Application” option.

C:\Users\ShivCapoor\Pictures\lora temp.png

Enter the following details into the form that shows up:

  1. Unique name under Application ID
  2. Description about the application. This can help you identify various applications.

Once these details are entered, click on Add Application

3. Registering the devices

Open your application and go to the “Devices” section and click on register device

Enter the following details on the forms:

  1. Under Device ID, enter a descriptive name for your devices
  2. To generate your Device EUI, click on the Generate button located on the left side of the text field

Finally, click on Register

After registering the device’s settings, select OTAA as the Activation Method and click on the Save button.

Note- For Gateway setup refer to the manufacturer’s manual

Step2: Code and Library

Open a terminal on the Pi and clone the repository using the following command:

git clone

Install Bcm2835_Library

Download the library using the command given below:


Unzip folder

tar zxvf bcm2835-1.68.tar.gz


 Use the cd command to move into the bcm2835 folder

cd bcm2835-1.68

Build your code



Do not forget to reboot the pi in the end

sudo reboot

Step3: Pin Number Modification in Code

Navigate to ttn-otaa example folder

cd raspi-lmic/examples/ttn-otaa/

nano ttn-otaa.cpp

Pin Mapping

To update pin mapping in the ttn-otaa.cpp file, use physical pin numbers of the Raspberry Pi as shown below.

Step4: Update device EUI and app EUI from TTN device into code

You can find the EUI in your TTN Console under Your Application > Devices > Your Devices

Make sure device EUI and app EUI are copied in little-endian format. (Use the reverse button before copying these) and the App key in big-endian (MSB)


Modified the following lines to add your credentials in the main.c file:

Press Ctrl+X to exit nano. Upon exiting, the save prompt           will be displayed. Press Y and then press the Enter key

Step5: Rebuild the ttn-otaa.cpp file

Every time the code is edited, it needs to be rebuilt in order for the changes to take effect. Use the commands below to clean any previous build files present and to rebuild the source

$ make clean

$ make

Step 6: Running 

pi@raspberrypi:~/raspi-lmic/examples/ttn-otaa $ sudo ./ttn-otaa

After running code uplink will start

After this go to the things network > Application > Device > Data

Here, the uplink, downlink, and acknowledgment  packets can be seen


Step 7: Scheduling Downlink

In the page shown above, click on the Overview tab.

Scroll down to find the Downlink section and enter your payload in hex form

Select Confirmed and click on send

The downlink packet is visible in the Pi terminal.


After running the code if you get the Failure error on the terminal

Check your connections, make sure the connections are correct and not loose. Also, check the code to verify if all pin numbers are correct and the credentials are set correctly.

Leave a comment

Please note, comments must be approved before they are published