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

Picture of Use Lora Shield and RPi to Build a LoRaWAN Gateway

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

Picture of 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

Picture of 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

Picture of   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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

    Picture of 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

    Picture of 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:

    Comments

    David_Dragino (author)2016-08-17

    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:

    wakko_one (author)2017-10-29

    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.

    memo4224 (author)2017-10-17

    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?

    badritripathy92 (author)2017-08-30

    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.

    rusti97 (author)2017-08-29

    Hi,

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

    wandanny (author)2017-08-20

    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?

    wandanny (author)2017-08-20

    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

    tejasri19 (author)2017-03-24

    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?

    Hao-TienC (author)2017-03-07

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

    ayudatama (author)2017-01-03

    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 :)

    David_Dragino (author)ayudatama2017-01-08

    Yes,you can do it as what you said.

    ayudatama (author)David_Dragino2017-02-23

    Hi david,

    I already bought the 433MHz version. Do you have any tutorials for this version? Thanks

    leonlee1314 (author)2017-02-21

    Hi, David.

    I have two lora shield and newbie for internet of thing. I would like to know that is that possible to communicate/send the data to one specific Lora shield without using any internet. The lora shield is connect with RPI and sent data to another lora shield connected with arduino. Is it possible and any other methods to achieve it?

    Evekites (author)2017-01-19

    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

    David_Dragino (author)Evekites2017-01-19

    There,have you installed the wiringpi?

    Evekites (author)David_Dragino2017-01-20

    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.

    David_Dragino (author)Evekites2017-02-03

    You can check the hardware resource here:https://github.com/dragino/Lora

    David_Dragino (author)Evekites2017-02-03

    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

    hamvui941 (author)2017-01-21

    Hi David, In my country using 433Mhz, but in the step 5, I can't find this choice. This gateway in TTN for 868 and 915Mhz and don't have the choice for 433Mhz. Can you help me for this problem ? :(

    David_Dragino (author)hamvui9412017-02-03

    The LoRaWan protocol doesn't support 433Mhz,you can click http://www.lora-alliance.org/ for more informations.

    durvesh09 (author)2017-02-01

    where can i get global_conf.json or local_conf.js file ?

    Hao-TienC (author)2017-01-07

    Hi David,

    is there any source code in C for the GPS module? I am trying to integrate GPS and LoRa module together thanks

    Hao-TienC (author)David_Dragino2017-01-09

    I'll check it out thanks

    Hao-TienC (author)2017-01-05

    Hi, I am trying to use GPS HAT and RPi to join network with OTAA, any sample code for OTAA?? thanks.

    Hao-TienC (author)David_Dragino2017-01-09

    thanks!

    Stephen LEE (author)2017-01-05

    It look nice!!

    minostroza1 made it! (author)2016-12-27

    David

    I'm having problems with the TTN web. When I enter to "my profile" isn't the option to add a new gateway, it just say "claim a gateway", as the picture shows. Some other links that you show in the instructable are broken.

    On another hand, I found the console link on TTN (https://console.thethingsnetwork.org/gateways) where I can add gateways and apps but some features are different, I don't know if it will work with simple gateway software. It doesn't work for me, but I could have another problem.

    Could you help me?

    Thanks!

    Copy that,and I will update this intruction after my vacation

    minostroza1 (author)2016-12-13

    Hi! I'm working with the libellium sx1272 ans a cooking hacks shield to connect it with the raspi. I'm having Unrecognizer transceiver problems ¿any suggestion?

    Thanks!

    Uhm,sorry to reply so late,how is it going?Did you check your wiring?

    minostroza1 (author)minostroza12016-12-13

    I had to chage the pins for the following:

    ssPin=10;

    dio0=0;

    RST=7;

    I have to do more tests, but for now it works

    Ok,too busy these days,good luck!

    13128652 (author)2016-12-12

    Hi David, I am doing a final year project similair to this but using LoRa gateway and waspmote. I am trying to use cutecom to configure the gateway but not recieving any information packet in response to the READ command. any help ??

    David_Dragino (author)131286522016-12-25

    Hi,have you finished it ?And I need more details about your project

    FelixKunz (author)2016-12-16

    Hey, is it possible to run the "Single channel gateway packet forward source" automatic at start?

    David_Dragino (author)FelixKunz2016-12-25

    Yes,but you need to make sure your gateway settings is ok.

    mellbratt (author)2016-07-29

    To make the "unrecognized transceiver" errors go away I had to change

    bool sx1272 = true;

    to

    bool sx1272 = false;

    in main.cpp

    minostroza1 (author)mellbratt2016-12-12

    where is that ?

    In the folder single_chan_paket_fwd,there is a file called main.cpp

    JesseW78 (author)2016-12-10

    Hi, David.
    I have bought 2 lora shields. I'm a newbie for network thing, want to know that is it possible to make the multiple Lora shields to communicate/send the data to one specific Lora shield through the method introduced as above. (build a LoraWan gateway) And what if my case is without using any internet, is it any other methods to achieve it?

    David_Dragino (author)JesseW782016-12-11

    Hi JesseW78,as what you said,you can do that,bu it's not "LoRaWan" anymore,and you can use the Radiohead.Uhm,tell me you email and I'll send you the sketches,david@dragino.com,hope it help~

    JesseW78 (author)David_Dragino2016-12-12

    ok, my email-

    jchening@gmail.com

    plusmartin (author)2016-12-07

    Hi, there is an error when checking https://www.thethingsnetwork.org/api/v0/gateways/B...

    using my own ID I get:

    "error":"Cannot connect to database!"

    what is wrong?

    also, how can I use the lora antennas to transmit from my arduino (shield) to my rpi (hat) without all the hassle of TTN and encryption etc? They are making me run before I walk.

    Thank you very much for you help

    mshaz (author)2016-12-02

    I am new to this , my question is what does it mean by single channel gateway?

    SimonR59 (author)2016-07-05

    I've a problem with my gateway:

    I can see that the Gateway receives packages at the terminal of the RPI, but I can't see the messages at the TTN dashboard.
    As a node I use a RN2483.

    Does someone have an idea where the problem could be?

    Thank you.

    FelixKunz (author)SimonR592016-11-30

    I have the same problem, the gateway receives, but i can't see the messages at hte TNN dashboard. Tried 40.114.249.243 as IP but still nothig. Any Ideas?

    About This Instructable

    79,944views

    196favorites

    License:

    More by David_Dragino:Use the LoRa Kit to build your own IoT networkDragino LoRa GPS TrackerHow to get sensor data from a remote Arduino via Wireless Lora Protocol
    Add instructable to: