In the ever-expanding world of the Internet of Things (IoT), Low-Power Wide-Area Networks (LPWAN) have emerged as a game-changer for long-range, low-power communication. Among these technologies, LoRaWAN stands out for its impressive range and energy efficiency. If you're looking to dive into this exciting field, setting up your own LoRa gateway is an excellent place to start.

Requirements

Software Setup

Step 1: Write the RPI OS to the SD Card

Using the Raspberry Pi Imager software, write the Raspberry Pi OS Lite image to the SD card disk. Make sure you configure a password/key and set the WiFi connection and key to enable the RPI W to connect.

Once imaging completes successfully, plug the SD into the RPI. Power on the device and make sure you have a decent power supply that can handle 3 amps.

Step 2: Update all the software

Assuming headless installation, use the hostname configured or your router to get the IP address of the device. SSH into the PI using the username/password or key configured during flashing.

sudo apt-get update && sudo apt-get upgrade

Step 3: Install the rak_common_for_gateway software application

Head over to GitHub and follow the instructions at RAKWireless/rak_common_for_gateway

the TDDR:
Use "sudo raspi-config" command, enable spi and i2c interface, disable login shell over serial and enable serial port hardware.

Clone the installer and start the installation

  $ sudo apt update; sudo apt install git -y
  $ git clone https://github.com/RAKWireless/rak_common_for_gateway.git
  $ cd ~/rak_common_for_gateway
  $ sudo ./install.sh

Next, you will see some messages as follows. Please select the corresponding hardware model.

  Please select your gateway model:
  *	 1.RAK2245
  *	 2.RAK7243/RAK7244 no LTE
  *	 3.RAK7243/RAK7244 with LTE
  *	 4.RAK2247(USB)
  *	 5.RAK2247(SPI)
  *	 6.RAK2246
  *	 7.RAK7248 no LTE (RAK2287 SPI + raspberry pi)
  *	 8.RAK7248 with LTE (RAK2287 SPI + LTE + raspberry pi)
  *	 9.RAK2287 USB
  *	 10.RAK5146 USB
  *	 11.RAK5146 SPI
  *	 12.RAK5146 SPI with LTE
  Please enter 1-12 to select the model:

Step 4: Configure the Gateway

In my case, it is option 1. as I have the RAK2245 RPI Hat Edition. Once installation completes reboot the RPI. Execute the following in a new SSH console:

sudo gateway-config

Go to 2 and Setup the Channel Plan. Once done go to 4 and edit the config. Note the Gateway Id above you will need that for the next step.

Log into TTN Console (you will need to register if you have not)
Navigate to Gatways

and click on the + (plus) button and "Add new gateway"

For the Gateway EUI use the Gateway Id from above

Once you have completed filling in the required info, you can go to your newly configured gateway. In the top right click the hamburger menu and select Download gloabl_conf.json

Go back to your SSH session which should be displaying the current configuration. Look at the downloaded config values. Make sure the
- gateway_ID
- server_address
Have been set correctly. Restart the concentrator.

Testing and verification:

Look at the gateway service logs

sudo journalctl -u ttn-gateway.service

If everything is working as expected you should see something like:

Trouble Shooting

Spoiler, mine did not "just work"

First Problem, GPS not detected

Make sure you have enabled the SPI, and I2C using raspi-config as per the GitHub instructions... Assuming you have done that and you still get the below error:

Oct 13 01:27:35 rak-gateway ttn-gateway[8005]: WARNING: [main] impossible to open /dev/ttyAMA0 for GPS sync (check permissions)
Oct 13 01:27:35 rak-gateway ttn-gateway[8005]: ERROR: [main] failed to start the concentrator

Check that the GPS is not detected under a different device. I did a

sudo journalctl | grep tty
Oct 13 13:07:43 rak-gateway ttn-gateway[5165]: INFO: GPS serial port path is configured to "/dev/ttyS0"
sudo cat /dev/ttyS0

results in:

N*30    �����$GPRMC,,,141024,,,N*7E
$GPGGA,10499.99,,,,1,,,,,,,,,,,,,9*30
0,,,,,0,00,99.99A,A,1,,,,,,,,,,,99.99,99.99*30,V,,,,,,,141TG,,,,,,,,,N*30
,1,01,02,,,09*73,,,,,104317.00,Vb ��s�

which confirms the GPS. You could go and modify the concentrator config to point to the correct device but I was not sure what else would be required to change so I just created a symlink from the actual GPS device to the expected one:

sudo ln -s /dev/ttyS0 /dev/ttyAMA0
sudo chmod 666 /dev/ttyS0
sudo chmod 666 /dev/ttyAMA0

Restart the gateway:

sudo systemctl restart ttn-gateway

Verify operation again:

journalctl -u ttn-gateway -f

At this point, the GPS issue went away but a serial issue popped up instead

Fixing GPIO error:

The next error I got was a GIO one. Apparently, the way the GPIO works in the later RPI image has changed resulting in the below error:

Oct 13 03:32:00 rak-gateway ttn-gateway[1143]: /opt/ttn-gateway/packet_forwarder/lora_pkt_fwd/start.sh: line 7: /sys/class/gpio/gpio17/direction: No such file or directory
Oct 13 03:32:00 rak-gateway ttn-gateway[1143]: /opt/ttn-gateway/packet_forwarder/lora_pkt_fwd/start.sh: line 8: /sys/class/gpio/gpio17/value: No such file or directory
Oct 13 03:32:00 rak-gateway ttn-gateway[1143]: /opt/ttn-gateway/packet_forwarder/lora_pkt_fwd/start.sh: line 10: /sys/class/gpio/gpio17/value: No such file or directory
Oct 13 03:32:00 rak-gateway ttn-gateway[1143]: /opt/ttn-gateway/packet_forwarder/lora_pkt_fwd/start.sh: line 12: /sys/class/gpio/gpio17/value: No such file or directory
Oct 13 03:32:00 rak-gateway ttn-gateway[1143]: /opt/ttn-gateway/packet_forwarder/lora_pkt_fwd/start.sh: line 14: echo: write error: Invalid argument

To fix this I found a support answer here by Nikola Semov.

The link points to a GitHub example here and the two files you need are linked below

The location of the files on my RPI was:

/opt/ttn-gateway/lora_gateway/reset_lgw.sh
/opt/ttn-gateway/packet_forwarder/lora_pkt_fwd/start.sh

make sure you replace the above files with the ones linked from the GitHub repo.

Restart the concentrator again... Now everything should be working.

You can confirm by looking at the TTN Gateways live data tab and viewing the last activity (downlink/uplink)

YAY! WE HAVE DATA!