Ga naar hoofdinhoud
DIY LoRa-WAN gateway

You can make yourself a LoRa-WAN gateway using a Raspberry Pi Model B+ and a LoRa concentrator board RAK831.

Step 1: connect RAK831 to Raspberry Pi

TTN LoRaWAN gateway based on Raspberry Pi Model B+ and the RAK831 concentrator board.

Make these connections:

Step 2: prepare the Raspberry Pi
  1. Download raspbian_stretch_lite: http://director.downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2018-04-19/2018-04-18-raspbian-stretch-lite.zip
  2. Unzip and write image file to 4Gb micro SD-card using Etcher (https://etcher.io/).
  3. Within /boot directory create a new file ssh (without extension). This will activate ssh during first boot.
  4. Start up Raspberry. Default username/op: pi/raspberry.
  5. Look up the Raspberry’s IP-adres by using advanced-ip-scanner (http://www.advanced-ip-scanner.com/nl/).
  6. Install putty on your PC: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html and create a shortcut to putty.exe on your desktop.
  7. Open putty.exe and in the Host Name field fill in Raspberry’s IP-address (see step 6, in my case 192.168.2.6).
  8. Type passwd to change the default password.
  9. Type sudo raspi-config (you can past this to Putty using the right mouse button).
  10. Select 5 Interfacing Options > P4 SPI and select ‘Yes’.
  11. Select 7 Advanced Options > A1 Expand Filesystem and choose <Select> using the Tab-button).
  12. Select <Finish> and reboot.
  13. Use putty to contact via SSH again and check if SPI is enabled: ls /dev/*spi*
    Raspberry’s response:  /dev/spidev0.0  /dev/spidev0.1
  14. Update, upgrade and install git: sudo apt-get update && sudo apt-get upgrade && sudo apt-get install git -y
  15. Install TTN software: git clone https://github.com/ttn-zh/ic880a-gateway.git ~/ic880a-gateway
  16. Open this new directory: cd ic880a-gateway
  17. Ask for Gateway EUI: sudo ./install.sh spi
    Stop here and copy the given EUI code (for example: B827EBFFFED8B28D).
  18. Register your gateway on TTN: https://www.thethingsnetwork.org/
    1. Gateway EUI: fill in EUI code (see step 18)
    2. I’m using the legacy packet forwarder: Yes
    3. Description: choose your own
    4. Frequency Plan: Europe 868MHz
  19. Via SSH: Do you want to use remote settings file: N
  20. Fill in:
    1. Gateway EUI: fill in EUI code (see step 18)
    2. Descriptive name: see step 19
    3. Contact email: your e-mail address
    4. Latitude: copy this from TTN
    5. Longitude: copy this from TTN
    6. Altitude: copy this from TTN
  21. After a few minutes the Raspberry will reboot and your gateway is on line!
  22. Shutdown Raspberry: sudo shutdown
Adding ‘save shutdown button’

To prevent the SD-card getting corrupted you could add a button to shutdown the Raspberry Pi safely.
Open Terminal (via SSH or local) and type:

cd
mkdir Scripts
cd Scripts
touch shutdown_pi.py

 

Edit python script:

nano shutdown_pi.py


Type the script content:

#!/bin/python
# Simple script for shutting down the raspberry Pi at the press of a button.
# by Inderpreet Singh  

import RPi.GPIO as GPIO
import time
import os  

# Use the Broadcom SOC Pin numbers
# Setup the Pin with Internal pullups enabled and PIN in reading mode

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)  

# Our function on what to do when the button is pressed  

def Shutdown(channel):

   os.system(“sudo shutdown -h now”)  

# Add our function to execute when the button pressed event happens  

GPIO.add_event_detect(18, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)  

# Now wait!  

while 1:  

   time.sleep(1)

 

Save file by pressing CTRL+X, type y and Enter.

Connect a push button between Raspberries GND and GPIO18  (Pin 12 and 14).

Test the the python script:

sudo python shutdown_pi.py


Add python script to startup:

sudo nano /etc/rc.local


Add after fi:

python /home/pi/Scripts/shutdown_pi.py

Save file by pressing CTRL+X, type y and Enter.

Reboot:

sudo reboot

Adding ‘Shutting gateway down safely button’

Removing power source to fast may lead to data corruption.
Connect LED (with 470 Ohm resistor in series) between Pin 6 (GND) and Pin 8 (TXD) of the Raspberry Pi.

Only when the LED is out it’s safe to remove power source.

Adding ‘Reboot button’

Connect Raspberry Pin 5 to ground.
Total boot time (from idle): 50 s.

Adding 3G-connection

Just add a 3G dongle to the Raspberry Pi. Be aware of the rather high power consumption of the 3G connection. Better use a powered USB-hub.

Connecting RAK831 and Raspberry Pi Model B+
Back To Top