Introduction: Use Lora Shield and RPi to Build a LoRaWAN Gateway


Some changes have been made by the TTN network,I have updated this project in January 15th,more info about the changes please check below links:

If you have any problem with this project,you can connact us by or post the problems on the TTN forum (Special thanks to @CurlyWurly).

Over here,we will use the Lora Shileld,MEGA2560 and Raspberry Pi to build a single channel LoRaWAN gateway.

LoRa Technology is a wireless modulation for long-range, low-power, low-data-rate applications. By achieving a range of more than 15 kilometers in a suburban environment and more than 2 kilometers in a dense urban environment, LoRa technology solutions target multiple application domains, such as Internet-of-Things (IoT), metering, security, and machine-to-machine (M2M).

This single channel LoRaWAN gateway is a proof-of-concept implementation,that can be used for development and node testing. It is not a replacement for a real multi channel/multi SF gateway! It supports some LoRaWAN features, but due to its static nature (single channel) it is not fullyLoRaWAN compatible (and will never be).
By default it works with the TTN backend, for testing and development.
Refer to the summary of Thomas

Step 1: Hardwares

In this project,we use the things as followed list:

  • Two Lora Shields v95-868
  • Raspberry Pi 2(Installed Raspbian)
  • MEGA 2560
  • LED display screen
  • USB cables
  • Antennas(868MHZ)
  • Computer
  • Wireless network card
  • Mouse and keyboard
  • Dupont Lines

Step 2: A Brief Introduction of the Dragino Lora Shield and the Ttn Network

The Dragino Lora Shield is a long range transceiver on a Arduino shield form factor and based on Open source library.The Lora Shield allows the user to send data and reach extremely long ranges at low data-rates.It provides ultra-long range spread spectrum communication and high interference immunity whilst minimising current consumption.

The Lora Shield based on RFM95W/RFM98W targets professional wireless sensor network applications such as irrigation systems, smart metering, smart cities, smartphone detection, building automation, and so on. More info please click here.

The TTN network is based on LoRaWAN,it's a global open crowdsourced Internet of Things data network.We can get more information form

Step 3: Network Structure

The construction of this network is as the photo above.

Lora Node:

The Mega2560 will get sensor data and control the Lora Shield to send this data to the RPi Lora Gateway via Lora wireless protocol.

Lora Gateway:

The RPi Lora Gateway will receive this data and upload it to the TTN network via the Internet.

TTN Server:

The TTN Server will get the data packets from the RPi Lora Gateway and the data will be stored in the corresponding place,so users can take what they need from the Internet.


We can use the PC to get the data and check the status of this Lora Gateway network.

Step 4: Create an Account on TTN Network

Before we start this project we must have a TTN account,we can create one at this page:

You have two options to create the register devices in TTN. Firstly you can use the GUI at, which is straightforward. Secondly, you can use the commandline tool ttnctl. When I started documented this, only ttnctl was available. Basically, follow the guide from Download ttnctl, sign up, create an application. You can use either the GUI Then, use ttnctl to register a personalized device.The specific operation please check above website.

Step 5: Create a Gateway on TTN Network

NOTE: Create your own lora gateway is not necessary, if there are TTN lora gateway around, you don't have to create your own one. in this instruction, we want to demo the full network structure so we create gateway here.

Login the TTN network by your own account and turn to this page:

Click 'add a gateway' and you will enter a page to type your gateway message(such as the first photo and the second one).In the next step,we will get a Gateway ID after we run the packet forward on the RPi.Then type the Gateway ID to the Gateawy EUI column(In hexadecimal, no colons,uppercase letters).

We can see the ruuning result as the 3rd picture in this step,we get a Gateway ID: b8:27:eb:ff:ff:29:4b:3b,so we type B827EBFFFF294B3B to the Gateway EUI column.

By the way,we also need to modify other settings(Select the Frequency plan,select your gateway address and your can config other settings by clicking the settings button),save it and you will see your profile such as the fourth picture at this step.As you can see,the gateway status is connected,it means we just have created a Gateway for our TTN account.

In addition,you can check all the TTN Gateway status at (as the last picture)

Step 6: Create an Application on the TTN Network

In this step,we need to create an application on the TTN network.

1.Open this website :,you will see it as the first picture.

2.Click "create application" to create your own applications and name it.

3.You will see your 'Application Info' at the new created page,App EUI....

4.Register device.In this project ,we choose the ABP device type,click 'register device'--'ABP'--'Register'.(For an ABP device, you can set the App Session Key and the Network Session key. Both of these can be randomly generated (recommended).)

5.You will see the 'device info' on the new created page,such as Dev EUI,App EUI,Dev Address,NWKSKEY,APPSKEY,etc.So,you can use them at the following steps.

Back to the Application page,you will see all devices that are registered for this application are displayed on the "Devices" colunm.And the Messages that were sent to all devices that are part of this application

There,you can also use the v2 version to setting your Application and Gateway:

Step 7: Build a Single Channel LoRaWAN Gateway

In this step,we will use the RPi and the Lora Shield to build a single channel LoRaWAN Gateway.We should configure the RPi and connect it with the Lora Shield.Complete the operations as following description:


  • Connect the Raspberry Pi to the Internet;
  • Use 'raspi-config ' to ensure that SPI can be used on RPi ;
  • Use 'sudo apt-get install wiringpi' to install the GPIO access library written in C for the BCM2835 used in the Raspberry Pi;
  • Get the single channel Lora Gateway source code from here;
  • Edit the 'main.cpp' to change configuration (look for: "Configure these values!").


    LoRa: SF7 at 868.1 Mhz

    The server_address depends on the region:

    • # EU 433 MHz and EU 863-870 MHz
    • # US 902-928 MHz
    • # China 470-510 MHz and 779-787 MHz
    • # Australia 915-928 MHz

    See more info here

    So,we don't need too change the code here.


    The Dragino Lora Shield ------ Raspberry Pi

    5V ------ 5V(pin#2)

    GND ------ GND(pin#6)

    MISO ------ MISO(pin#21)

    MOSI ------ MOSI(pin#19)

    SCK ------ CLK(pin#23)

    (CS_A)NSS ------ GPIO6(pin#22)

    DIO0 ------ GPIO7(pin#7)

    RST ------ GPIO0(pin#11)

    Connect the Dragino Lora Shield and the RPi as above,run packet forwarder as root. Then we can get a Gateway ID and see the running result on the RPi as the 3rd picture at this step.

    We also can get the Gateway status from . In this URL need to search your own Gateway ID and you will see the uplink&downlink status of your gateway. If you can see the Gateway status is active, it shows the LoRaWAN Gateway is working!

    Note: If the packet forwarder shows the "unrecognized transceiver" message,this mean the RPi can't detect Lora Shield. in this case please further check your pin/wiring configuration.

    Step 8: Connect the Lora Shield and MEGA 2560,upload the Sktech

    Connect the Lora Shield and MEGA 2560,and put the 868MHZ antenna on it.Connect them to the computer via an USB cable.

    Over here,we use the Arduino IDE1.68,we need to install this Arduino-LMIC liabrary.This repository contains the IBM LMIC (LoraMAC-in-C) library, slightly modified to run in the Arduino environment, allowing using the SX1272, SX1276 tranceivers and compatible modules.

    Note:This library requires Arduino IDE version 1.6.6 or above, since it requires C99 mode to be enabled by default.

    After do that,we download the ttn sketch from this link.

    Open and modify this sktech,change the 'DEVADDR' ,'NWKSKEY','APPSKEY' (You can find these device info at Step 6) on line 40th,choose the right port and right board to upload the sktech.We can see the running result on the Serial Monitor if everything is ok.(4th photo)

    At the same time we can also see the corresponding results on RPi.By default,the node is sending at 10 frequencies, the gateway is receiving at only 1, hence the one packet per 10 minutes.

    On a "real" gateway I see all messages (each minute), only with this Single Channel Gateway was this phenomena.
    This is not a real gateway, it is for testing purposes. It is LoRaWAN compatible, but not compliant.

    Refer to and

    If you are using Lora Shield v1.1 version. please wired as below code(such as the last photo at this step):

    // Pin mapping<br>const lmic_pinmap lmic_pins = {
        .nss = 10,// Connected to pin D10
        .rxtx = LMIC_UNUSED_PIN,// For placeholder only, Do not connected on RFM92/RFM95
        .rst = 9,// Needed on RFM92/RFM95? (probably not)
        .dio = {2, 6, 7},// Specify pin numbers for DIO0, 1, 2
    // connected to D2, D6, D7 

    Step 9: Conclusion

    Above all completed,open your Application page,you will see the result as above picture.

    The Lora Shield for RPi will coming soon,For more info about Lora Shield, please refer: or contact us at

    By the way,we can get this Lora Shield from

    Step 10: Reference: