Use Lora Shield and RPi to Build a LoRaWAN Gateway

103,672

202

109

Hi,guys,

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:

https://www.thethingsnetwork.org/forum/t/new-addre...

https://www.thethingsnetwork.org/wiki/Backend/Migr...

If you have any problem with this project,you can connact us by support@dragino.com 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 http://thethingsnetwork.org/

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.

PC:

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: http://thethingsnetwork.org/signup/

You have two options to create the register devices in TTN. Firstly you can use the GUI at https://staging.thethingsnetwork.org, 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 https://www.thethingsnetwork.org/wiki/Backend/ttnctl/ttnctl. 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: https://console.thethingsnetwork.org/gateways

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 https://staging.thethingsnetwork.org/gatewaystatus/ (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 :https://staging.thethingsnetwork.org/applications,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: https://console.thethingsnetwork.org/

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:

Configuration

  • 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!").

Defaults:

    LoRa: SF7 at 868.1 Mhz

    The server_address depends on the region:

    • router.eu.thethings.network # EU 433 MHz and EU 863-870 MHz
    • router.us.thethings.network # US 902-928 MHz
    • router.cn.thethings.network # China 470-510 MHz and 779-787 MHz
    • router.au.thethings.network # Australia 915-928 MHz

    See more info here

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

    Connections:

    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 https://staging.thethingsnetwork.org/gatewaystatus... . 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 tohttp://forum.thethingsnetwork.org/t/single-channel-gateway/798/17 and http://forum.thethingsnetwork.org/t/single-channel-gateway/798/19

    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:http://wiki.dragino.com/index.php?title=Lora_Shield or contact us at info@dragino.com

    By the way,we can get this Lora Shield fromhttp://www.aliexpress.com/store/all-wholesale-products/1390863.html

    Step 10: Reference:

    5 People Made This Project!

    Recommendations

    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • Big and Small Contest

      Big and Small Contest
    • Toys Contest

      Toys Contest

    109 Discussions

    0
    None
    DavidGuo

    2 years ago

    Hi,all,

    In this project, you can see how to "Use Lora Shield + Arduino set up a Lora Node“,You can also get how to "Use Lora/GPS HAT + RaspberryPi to set up a Lora Node" as below:

    1 reply
    0
    None
    freefox

    Question 6 months ago on Step 8

    Hello,

    An updated version of this tutorial would be nice:

    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
    };

    We are now at 1.4 version of this shield. Are the pin numbers the same? There are for example some jumpers on the board, I didn't touch any. There are too many things which can go wrong with the setup and you cannot easily debug it step by step what is wrong, like tinkering with a black box.

    Also in your code:

    // LoRaWAN NwkSKey, network session key
    // This is the default Semtech key, which is used by the prototype TTN
    // network initially.
    static const PROGMEM u1_t NWKSKEY[16] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C };

    // LoRaWAN AppSKey, application session key
    // This is the default Semtech key, which is used by the prototype TTN
    // network initially.
    static const u1_t PROGMEM APPSKEY[16] = { 0xA6, 0x5B, 0xD7, 0xBC, 0xD2, 0xBF, 0x20, 0xD1, 0x25, 0x89, 0x71, 0x26, 0xAF, 0x9D, 0x05, 0xF7 };

    // LoRaWAN end-device address (DevAddr)
    // See http://thethingsnetwork.org/wiki/AddressSpace
    static const u4_t DEVADDR = 0x09984507 ; // <-- Change this address for every node!

    in the ttn-otaa:

    // This EUI must be in little-endian format, so least-significant-byte
    // first. When copying an EUI from ttnctl output, this means to reverse
    // the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
    // 0x70.
    static const u1_t PROGMEM APPEUI[8]={ 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x00, 0xEF, 0xDD };
    void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}

    // This should also be in little endian format, see above.
    static const u1_t PROGMEM DEVEUI[8]={ 0x00, 0x93, 0xAC, 0x06, 0xBC, 0xDB, 0x1A, 0x69 };
    void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}

    // This key should be in big endian format (or, since it is not really a
    // number but a block of memory, endianness does not really apply). In
    // practice, a key taken from ttnctl can be copied as-is.
    // The key shown here is the semtech default key.
    static const u1_t PROGMEM APPKEY[16] = { 0xA6, 0x5B, 0xD7, 0xBC, 0xD2, 0xBF, 0x20, 0xD1, 0x25, 0x89, 0x71, 0x26, 0xAF, 0x9D, 0x05, 0xF7 };
    void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);}

    These keys are just for test, will be replaced but you can see my problem. Your values are even different in size 16,16,??? vs 8,8,16. At least in the example you know what is what from getting these directly from the Things network "Device Overview" tab.

    Please update your code and project. Thank you.


    0
    None
    SufyanA11

    9 months ago

    hy all,

    when i click on the '' register gateway '' after filling all boxes then it show an error that

    '' a gateway with id eui-000000ffff000000 already exists.''

    plz help me to remove this error.

    thnks in advance

    Untitled.jpg
    0
    None
    wakko_one

    1 year ago

    Hi David, I've recently read your post and it is excelent. I'm trying to build just the gateway but I'm using Lora/GPS shield v1.2 (LoRa BEE v1.1 [RF96 chip]). I'm sure that the pins connections are good. It suppose that should be detected as a SX1276, but I'm getting "Unrecognized transceiver."

    What could it be happening?

    Thanks.

    lorashield.jpg
    1 reply
    0
    None
    Evekites

    1 year ago

    Some of the Gateway connections were not clear to me and without connecting 3.3V on both Shield and RPI and the 5V on both shield and RPI the radio was not recognized.

    So below are the Dragino Shield pins I used to get the Gateway working:

    - ICSP header pins 4, 1 & 3 for MOSI, MISO and SCK (using D11, D12 & D13 on the shield didn't work!)

    - I used both 3.3V as well as 5V, otherwise the PWR LED didn't burn and the shield would not function at all (probably because of the level shifters)

    - RFM header pins 1 and 7 to connect DIO0 and RST

    - D10 for NSS

    - GND for GND

    5 replies
    0
    None
    LucasR124Evekites

    Reply 1 year ago

    Evekites, Thank you so much for your help!!

    0
    None
    DavidGuoEvekites

    Reply 1 year ago

    There,have you installed the wiringpi?

    0
    None
    EvekitesDavidGuo

    Reply 1 year ago

    Yes I've installed wiringpi.

    I don't have any problems, after using the connections as described in my reply, since for me that part of your instructions were not clear.

    You described to use the SPI connections (MOSI, MISO and SCK), but since you can find them on the ICSP header AND on D11, D12 & D13, I found out that only the ICSP worked for me.

    You described to use 3.3V, but I found that the level shifters needed both 5V and 3.3V.

    Using the RFM header for DIO0 and RST was obvious.

    NSS on D10 was not clear for me.

    I've added a picture showing the connections I used.

    Dragino.tiff
    0
    None
    DavidGuoEvekites

    Reply 1 year ago

    Uhm,I think you need to follow the connections as above article and cheeck your wiring ,don't use 3.3V on the LoRa Shield

    0
    None
    memo4224

    1 year ago

    Hi,

    "default,the node is sending at 10 frequencies, the gateway is receiving at only 1, hence the one packet per 10 minutes." Is it possible to change receiving frequency from 1 / 10 min to 1 per minute?

    0
    None
    badritripathy92

    1 year ago

    Hey,

    I just started with LoRa and i wanted to ask what kind of device(A B or C) is implemented for Uplink Downlink schedules, i cannot clearly see it in the sketch for the Node.

    0
    None
    rusti97

    1 year ago

    Hi,

    Is it possible to connect a Aruino Uno with RN2483 microchip, as node, to the single gateway with Lora Shield?

    0
    None
    wandanny

    1 year ago

    hi,

    i have a problem to built the gateway by using rasberry pi, when i want to run the tranceiver do not recognised i do not know why? i follow this link https://www.hackster.io/ChrisSamuelson/lora-raspberry-pi-single-channel-gateway-cheap-d57d36, please help me?

    WhatsApp Image 2017-08-20 at 22.38.45(2).jpeg
    0
    None
    wandanny

    1 year ago

    i also want to build the single channel gateway but i had a little prob to run because the tranceiver do not recognised, i do not know why

    WhatsApp Image 2017-08-20 at 22.38.45(2).jpeg
    0
    None
    tejasri19

    1 year ago

    Hey david,

    Im from thailand.Operating frequency for lora shields is within 920-925 Mhz. But available shields are of only 433,868,915 Mhz. Can we tune 915 ones to 920 which should be compatible with raspberry pi?

    0
    None
    Hao-TienC

    1 year ago

    How do I configure the gateway code with 915MHz in Australia??

    0
    None
    ayudatama

    1 year ago

    Hi David,

    I just ordered my first three LoRa shield from Dragino (2 for RPi and 1 for Arduino). Before I start the project I just want to ask is it possible that I have 2 nodes sending sensor data (1 RPi + 1 Arduino) to 1 gateway (RPi) and then send the data to the internet (MQTT possibly). I ask this question because you mentioned in this tutorial that this is to develop single channel LoRaWAN gateway.

    Sorry, I'm totally newbie with this LoRa things.

    Thanks in advance :)