LoRaWAN

 
 
LoRaWAN (Long Range Wide Area Network) is a specification for a telecommunication network suitable for long-distance communication with little power. The technology is used for machine-to-machine communication (Internet of Things).

The architecture consists of gateways, network servers and application servers. There are RF chips from Semtech used to transmit a spread spectrum.

More information about LoRaWAN can be found at:
https://www.lora-alliance.org/
https://www.thethingsnetwork.org/







Install Semtech Basic Station on RAK831



Information
Basic station information:
Guide: https://doc.sm.tc/station/index.html
Github: https://github.com/lorabasics/basicstation

Procedure

Step A. Prepare the Raspberry Pi 3.
  1. This guide is part of LoRa/LoRaWAN tutorial 52, see presentation lora_part52.pdf

    This guide uses a RAK831 gateway, see presentation LoRa/LoRaWAN tutorial 28.1
    The RAK831 gateway uses a Raspberry Pi 3 as the Micro Controller Unit (MCU).

  2. This guide assumes that you have already done the following.
    For instructions, see LoRa/LoRaWAN tutorial 28.1:
    • Raspbian Lite is installed. In this guide I have installed Raspbian Buster Lite.
    • The system date, timezone and locale are correctly set.
    • SPI is enabled.
    • In this guide the gateway will operate in the Netherlands in the 863-870 MHz frequency band (EU863-870), and the gateway has ip address: 192.168.1.11.

  3. To access the RAK831 gateway from a computer:
    Open a terminal
    Type: ssh [email protected]
Step B. Install Semtech Basic Station.
  1. ATTENTION:
    THE BASICSTATION IN THIS GUIDE WILL NOT USE A CUPS SERVER.
    IT USES A LOCAL (MOCK) LNS SERVER: ws://localhost:6090
    AND A STATION TO PACKET FORWARDER PROTOCOL BRIDGE (st2pkfwd)

    THE BASICSTATION SENDS PACKAGES TO THE THINGS NETWORK USING THE UDP PROTOCOL.

    THIS SETUP IS ***NOT*** THE CORRECT WAY TO USE THE BASICSTATION BUT IT WILL HELP YOU TO UNDERSTAND HOW BASICSTATION WORKS! USE THIS GUIDE MERELY FOR EDUCATIONAL PURPOSE. DO NOT USE IT IN PRODUCTION ENVIRONMENT.


    More information about st2pkfwd, see: https://github.com/lorabasics/basicstation/tree/master/examples/station2pkfwd

  2. Make sure you have done step A before you continue.

  3. Upgrade the Raspberry Pi packages.
    Type: cd ~
    Type: sudo apt-get update && sudo apt-get upgrade -y

  4. Clone my basicstation_setup git repository.
    Type: git clone https://github.com/robertlie/basicstation_setup.git

  5. Execute install.sh as root. You must be root!
    Type: cd basicstation_setup
    Type: sudo ./install.sh

    This install.sh script, does the following. All commands should be executed as root:
    • Create /opt/semtech directory.
      Type: mkdir /opt/semtech

    • Clone the Semtech basic station git repository:
      Type: cd /opt/semtech
      Type: git clone https://github.com/lorabasics/basicstation.git

    • The SPI_SPEED in basicstation/deps/lgw/platform-rpi/libloragw/src/loragw_spi.native.c must be changed.
      File loragw_spi.native.c is an dependency, which does not exists yet, it will be downloaded when building basicstation.

      EXECUTE IN THIS SPECIFIC ORDER:
      Step a.
      Download and build the dependencies (deps) for the Semtech basic station:
      Type: cd /opt/semtech/basicstation
      Type: make platform=rpi variant=std deps

      Step b.
      Clean the builds. DO NOT USE TARGET: super-clean, this will remove the downloaded dependencies:
      Type: make platform=rpi variant=std clean

      Step c.
      Modify file: basicstation/deps/lgw/platform-rpi/libloragw/src/loragw_spi.native.c
      The SPI_SPEED value needs to be changed:

      From:
      #define SPI_SPEED    8000000
      To:
      #define SPI_SPEED    2000000

      Type:
      sed -i 's/SPI_SPEED[[:space:]]\+8000000/SPI_SPEED 2000000/g' deps/lgw/platform-rpi/libloragw/src/loragw_spi.native.c

      If it is NOT changed you will get this error when running basicstation:

      2020-02-06 06:38:22.475 [SYN:ERRO] Repeated excessive clock drifts between MCU/SX1301#0 (3 retries): 3.6ppm (threshold 2.5ppm)

      This solution originated from the RakWireless Forum

    • Now build the Semtech basic station. The dependencies will not be downloaded again (unless you used super-clean):
      Type: make platform=rpi variant=std

    • Copy ~/basicstation_setup/startup folder to /opt/semtech/basicstation.
      Type: cp -R ~/basicstation_setup/startup /opt/semtech/basicstation/startup

    • Copy /opt/semtech/basicstation/examples/live-s2.sm.tc/station.conf to /opt/semtech/basicstation/startup/config_files.
      Type: cp /opt/semtech/basicstation/examples/live-s2.sm.tc/station.conf /opt/semtech/basicstation/startup/config_files

    • Copy /opt/semtech/basicstation/examples/live-s2.sm.tc/version.txt to /opt/semtech/basicstation/startup/config_files.
      Type: cp /opt/semtech/basicstation/examples/live-s2.sm.tc/version.txt /opt/semtech/basicstation/startup/config_files

      Note:
      The config_files directory will finally contain the following 3 files:
      - version.txt
      - station.conf
      - tc.uri

      The tc.uri file contains only one line: WS://localhost:6090
      This means a local LNS is setup, so there is no need for a secure websocket.
      Do not use WSS use WS! This also means no need for tc*.key, tc*.crt and tc*.trust files.

    • Copy /opt/semtech/basicstation/examples/station2pkfwd folder to /opt/semtech/basicstation/station2pkfwd.
      Type: cp -R /opt/semtech/basicstation/examples/station2pkfwd /opt/semtech/basicstation/station2pkfwd

    • Install the virtualenv tool to create isolated Python environments (this will also install python3.7).
      Type: apt-get install python-virtualenv

  6. Start basic station, execute start.sh as root.
    Type: cd /opt/semtech/basicstation/startup
    Type: sudo ./start.sh

    This start.sh script, does the following. All commands should be executed as root:
    • Set basic station environment variables, type:

      export RADIODEV="/dev/spidev0.0"
      export STATION_RADIOINIT="/opt/semtech/basicstation/startup/reset.sh"
      export STATION_LOGLEVEL="1"

      The log levels are:
      0=XDEBUG, 1=DEBUG, 2=VERBOSE, 3=INFO, 4=NOTICE, 5=WARNING, 6=ERROR, 7=CRITICAL

      The above mentioned reset.sh script contains the following:

      #! /bin/bash

      # Reset SX1301_RESET_BCM_PIN
      SX1301_RESET_BCM_PIN=17
      echo "$SX1301_RESET_BCM_PIN" > /sys/class/gpio/export
      echo "out" > /sys/class/gpio/gpio$SX1301_RESET_BCM_PIN/direction
      echo "0" > /sys/class/gpio/gpio$SX1301_RESET_BCM_PIN/value
      sleep 0.1
      echo "1" > /sys/class/gpio/gpio$SX1301_RESET_BCM_PIN/value
      sleep 0.1
      echo "0" > /sys/class/gpio/gpio$SX1301_RESET_BCM_PIN/value
      sleep 0.1
      echo "$SX1301_RESET_BCM_PIN" > /sys/class/gpio/unexport


    • Start basic station:
      Type: cd /opt/semtech/basicstation/startup/config_files
      Type: cd /opt/semtech/basicstation/build-rpi-std/bin/station -p -f

      BasicStation log

      In the logging you can see that the station is running in NO CUPS mode and TC connect fails.
      LNS server (TC) is no setup yet. Will be done next.

      Write down the Station EUI, for example: b827:ebff:fec7:4b36

  7. Make station2pkfwd a virtual environment.
    Type: cd /opt/semtech/basicstation/
    Type: virtualenv -p python3.7 station2pkfwd

  8. Activate the station2pkfwd virtual environment.
    Type: cd /opt/semtech/basicstation/station2pkfwd
    Type: . bin/activate

  9. Install the packages found in the /opt/semtech/basicstation/station2pkfwd/requirements.txt
    Type: cd /opt/semtech/basicstation/station2pkfwd
    Type: pip install -r requirements.txt

  10. Start /opt/semtech/basicstation/station2pkfwd/main.py
    Type: cd /opt/semtech/basicstation/station2pkfwd
    Type: python ./main.py --infosuri ws://localhost:6090 --pkfwduri udp://router.eu.thethings.network:1700 b827:ebff:fec7:4b36

    This script starts:
    • A Service Discovery Server instance (aka INFOS) for incoming Station connections at ws://localhost:6090

    • A Gateway Server instance (aka MUXS) at ws://localhost:6092