433 & 868 MHz – RAK5146L & RAK5146 – LoRa Basics Station

TTN version: TTNv3
Frequency: Europe 433 MHz (ITU region 1)
Europe 863-870 MHz (SF9 for RX2 – recommended)
Classes: Ready for LoRaWAN Classes A, B and C
Using Docker: Yes
Last updated: January 5, 2024

This article provides instructions for making LoRa Basics Station for two frequency plansEurope 433 MHz (ITU region 1) and Europe 863-870 MHz (SF9 for RX2 – recommended).433 & 868 MHz - RAK5146L & RAK5146 – LoRa Basics Station

Note: The RAK5146 with GPS and RAK5146L with GPS are required to support Class B end devices. This article shows the RAK5146L version without GPS and without Class B support, but the LoRa Basics Station setup and build is the same for the RAK5146L version with GPS and Class B support.

 

Prepare

 

Assembly

  1. First, from the 868 MHz RAK5146 SPI – LoRa Basics Station tutorial, do only the Assembly part and return to this tutorial.
  2. Then, from the 433MHz RAK5146L USB – LoRa Basics Station tutorial, do only the Assembly part and return to this tutorial.

 

Raspberry Pi OS setup

  1. From https://www.raspberrypi.com/software/ download Raspberry Pi Imager and install it.
  2. Insert the microSD card into the computer.
  3. Run Raspberry Pi Imager.
  4. Click on CHOOSE OS.
  5. Click on Raspberry Pi OS (other).
  6. Click on Raspberry Pi OS Lite (32-bit).
  7. Click on CHOOSE STORAGE.
  8. Select the inserted microSD card on which you want to install Raspberry Pi OS.
  9. Click on Next.
  10. Would you like to apply OS customisation settings? – EDIT SETTINGS.
  11. Set hostname.
  12. Set username and password. (we recommend a 17-digit password containing lower and upper case letters, numbers and symbols)
  13. If you will use WiFi – Configure wireless LAN. (optional)
  14. Set locale settings.
  15. Click on tab SERVICES.
  16. If you will be connecting remotely via SSH – Enable SSH – Use password authentication. (optional)
  17. Click on SAVE.
  18. Click on YES.
  19. Click on YES.
  20. Click on CONTINUE.
  21. Insert the microSD card into the Raspberry Pi.
  22. Turn on the Raspberry Pi.

 

Remote connection via SSH (optional)
  1. Connect to your router and find the IP address of your Raspberry Pi.
  2. From a Windows PC, you can connect using Command Prompt (CMD) or PuTTY.
  3. On Windows PC open Command Prompt (CMD).
  4. Type ssh -port username@IP_Address (for example: ssh -p 22 loravsb@192.168.1.120).
  5. Type your password.

 

Post-installation steps
  1. Update, upgrade and reboot Raspberry Pi. This will ensure that any security vulnerabilities are patched:
    $ sudo apt update
    $ sudo apt full-upgrade
    $ sudo reboot
  2. Connect again via SSH.
  3. Use a different port for SSH and disable root login. First, open the SSH configuration file with a text editor:
    $ sudo nano /etc/ssh/sshd_config
    
  4. Locate the line with Port 22 and change it to the desired port number (for example, change the port to 2222). Locate the line with PermitRootLogin and change its value to no (this will disable root login via SSH):
    Port 2222
    PermitRootLogin no
    
    
  5. Save the changes and exit the text editor.
  6. Restart the SSH service to apply the changes:
    $ sudo systemctl restart ssh
    
  7. Log out and connect again via SSH on the new port.
  8. Install and configure the built-in firewall, ufw, to limit incoming network connections. In the sudo ufw limit 2222/tcp rule, change port 2222 to port you have chose for SSH above.
    $ sudo apt install ufw
    $ sudo ufw default deny incoming
    $ sudo ufw limit 2222/tcp
    $ sudo ufw enable
    

    Note: Firewall rules will have no effect on ports opened by Docker.

  9. Reboot Raspberry Pi:
    $ sudo reboot

 

Docker
  1. Connect again via SSH.
  2. Install the latest Docker version using the convenience script provided by docker:
    $ curl -fsSL https://get.docker.com -o get-docker.sh
    $ sudo sh get-docker.sh
    $ sudo groupadd docker
    $ sudo usermod -aG docker $USER
    $ newgrp docker
    $ sudo systemctl enable docker.service
    $ sudo systemctl enable containerd.service

For more information on Docker installation, see https://docs.docker.com/engine/install/.

 

LoRa Basics Station setup

  1. First, get the Gateway EUI for the 433 MHz LoRa Basics Station by running the following command:
    $ docker run -it --network host --rm xoseperez/basicstation:latest bash -c "GATEWAY_EUI_NIC=wlan0 ./get_eui.sh"
  2. Then get the Gateway EUI for 868 MHz LoRa Basics Station by running the following command:
    $ docker run -it --network host --rm xoseperez/basicstation:latest bash -c "GATEWAY_EUI_NIC=eth0 ./get_eui.sh"
  3. If you receive two identical EUIs, change the last digit of one to make them different.

 

The Things Stack

  1. Create an account on The Things Network if you don’t have one.
  2. Login on The Things Network.
  3. Click on your username and choose Console.
  4. Select a network cluster.

 

433 MHz LoRa Basics Station
  1. Go to gateways.RAK5146_KIT_LBS_1
  2. Click on button + Register gateway.
  3. Write the previously detected Gateway EUI for 433 MHz LoRa Basics Station in the Gateway EUI field.RAK5146_KIT_LBS_3
  4. Click on button Confirm.
  5. Write something into Gateway ID.
  6. Write something into Gateway name.
  7. Frequency plan – Europe 433 MHz (ITU region 1).
  8. Click on button Register gateway.RAK5146L LBS 4
  9. In API keys click on button +Add API key.RAK5146_KIT_LBS_5
  10. Write something into Name.
  11. Click on Grant individual rights.
  12. Select Link as Gateway to a Gateway Server for traffic exchange, i.e. write uplink and read downlink.
  13. Click on button Create API key.RAK5146_KIT_LBS_6
  14. Click the Copy to clipboard button and paste the key into some text document for future use.
  15. Click on button I have copied the key.RAK5146_KIT_LBS_7

 

868 MHz LoRa Basics Station
  1. Go to gateways.RAK5146_KIT_LBS_1
  2. Click on button + Register gateway.
  3. Write the previously detected Gateway EUI for 868 MHz LoRa Basics Station in the Gateway EUI field.RAK5146_KIT_LBS_3
  4. Click on button Confirm.
  5. Write something into Gateway ID.
  6. Write something into Gateway name.
  7. Frequency plan – Europe 863-870 MHz (SF9 for RX2 – recommended)
  8. Click on button Register gateway.RAK5146_KIT_LBS_4
  9. In API keys click on button +Add API key.RAK5146_KIT_LBS_5
  10. Write something into Name.
  11. Click on Grant individual rights.
  12. Select Link as Gateway to a Gateway Server for traffic exchange, i.e. write uplink and read downlink.
  13. Click on button Create API key.RAK5146_KIT_LBS_6
  14. Click the Copy to clipboard button and paste the key into some text document for future use.
  15. Click on button I have copied the key.RAK5146_KIT_LBS_7

 

Raspberry Pi’s Interfaces

  1. Run the following command to configure the Raspberry Pi’s Interfaces:
    $ sudo raspi-config

    RAK5146_KIT_LBS_8

  2. In 3 Interface Options -> I4 SPI.RAK5146_KIT_LBS_9
  3. Would you like the SPI interface to be enabled? -> Yes.RAK5146_KIT_LBS_10
  4. Ok.
  5. In 3 Interface Options -> I5 I2C.RAK5146_KIT_LBS_11
  6. Would you like the ARM I2C interface to be enabled? -> Yes.RAK5146_KIT_LBS_12
  7. Ok.
  8. In 3 Interface Options -> I6 Serial Port.RAK5146_KIT_LBS_13
  9. Would you like a login shell to be accessible over serial? -> No.RAK5146_KIT_LBS_14
  10. Would you like the serial port hardware to be enabled? -> Yes.RAK5146_KIT_LBS_15
  11. Ok.RAK5146_KIT_LBS_16
  12. Finish.RAK5146_KIT_LBS_17
  13. Would you like to reboot now? -> Yes.RAK5146_KIT_LBS_18

LoRa Basics Station

  1. Connect again via SSH.
  2. Run this command to create and edit the docker-compose.yml file:
  3. $ sudo nano docker-compose.yml
  4. Copy and paste the configuration below into your docker-compose.yml file. Copy and paste the API keys you got previously saved to the TC_KEY variables. Copy and paste the EUIs you got previously generated to the GATEWAY_EUI variables.
    version: '2.0'
    services:
      basicstation-433:
          image: xoseperez/basicstation:latest
          container_name: basicstation-433
          restart: unless-stopped
          privileged: true
          network_mode: host
          environment:
            INTERFACE: "USB"
            MODEL: "SX1303"
            GATEWAY_EUI: "0000000000000000"             # Copy here your EUI for 433 MHz LoRa Basics Station
            TC_KEY: "NNSXS...."                         # Copy here your API key from the TTS for 433 MHz LoRa Basics Station
    
      basicstation-868:
          image: xoseperez/basicstation:latest
          container_name: basicstation-868
          restart: unless-stopped
          privileged: true
          network_mode: host
          environment:
            INTERFACE: "SPI"
            MODEL: "RAK5146"
            GATEWAY_EUI: "0000000000000000"             # Copy here your EUI for 868 MHz LoRa Basics Station
            TC_KEY: "NNSXS...."                         # Copy here your API key from the TTS for 868 MHz LoRa Basics Station
  5. Next, create a script that automatically on system startup (or power on) will recreate the containers (because there were errors when starting the original container for 433 MHz).
  6. Create the script reset-docker-compose.sh:
    $ sudo nano reset-docker-compose.sh
  7. Copy and paste the content below into your reset-docker-compose.sh file. In the path, replace yourUsername with your username:
    #!/bin/bash
    cd /home/yourUsername/
    sleep 30
    sudo docker compose down
    sudo docker compose up -d --force-recreate
  8. Make the script executable:
    $ sudo chmod +x reset-docker-compose.sh
  9. Create a systemd service:
    $ sudo nano /etc/systemd/system/docker-reset.service
  10. Copy and paste the content below into your docker-reset.service file. In the path, replace yourUsername with your username:
    [Unit]
    Description=Reset Docker Compose on Startup
    
    [Service]
    Type=oneshot
    ExecStart=/home/yourUsername/reset-docker-compose.sh
    
    [Install]
    WantedBy=multi-user.target
  11. Enable and start the service. The second command will take 30 seconds to execute:
    $ sudo systemctl enable docker-reset
    $ sudo systemctl start docker-reset
  12. Finaly, check that the gateway status is Connected in the TTS console.

 

For more information on LoRa Basics™ Station for Docker, see: