RHF0M301 Raspberry Pi with Basics Station

Hi,
Some notes on getting Basics Station running on a Rasperry PI B3+ with the RHF0M301 from the Seeed Studio LoraWAN Gateway Kit.

I followed the iC880A tutorial from @bigjohnson posted in the forum here. It works really well, but there were some things to sort out for the RHF0M301, or more specifically the adapter board for the Pi, and I made some mistakes along the way.

I started with a new micro SD card and a clean installation of Raspbian Buster with all the updates done. The old card had been in use for three years, it was time to update the OS, and swapping back to the old card is the easy way to switch back to the old gateway config.

This gateway is indoors at home. I don’t need remote configuration, so I chose the LNS config.

When it came to creating the tc.trust file I downloaded the minimal certificate list using the download link from the TTN Documentation pages here.

I also used the code fragment from this TTN Documentation page, slightly modified, to create the tc.key file expected by the build from from the LNS API key.

$ export LNS_KEY="your-lns-api-key"
$ echo "Authorization: Bearer $LNS_KEY" | perl -p -e 's/\r\n|\n|\r/\r\n/g'  > tc.key

At this point I made a mistake and also created a tc.crt file. It is not not part of the instructions and is not needed for LNS. The .crt file seems to cause Basics Station to choose a different authentication method and fail to connect. It took me a few hours to figure out what was causing the problem and it was solved by deleting the tc.crt file.

My RHF0M301 needs to be reset before the gateway starts. The adapter board that I have for the RHF0M301 connects the SX1301 reset pin to GPIO7 on the Raspberry Pi. When SPI is enabled in raspi-config the SPI configuration allocates GPIO7 as a chip select pin SPI CS1. Fortunately there is a dtoverlay file that will make GPIO7 available. I added dtoverlay=spi0-1cs in the [all] section of /boot/config.txt.

To reset the RHF0M301 I used this script for my reset_gw.sh file.

#! /bin/bash

SX1301_RESET_BCM_PIN=7
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

I added the --radio-init=reset_gw.sh parameter to the ExecStart line in the basicstation.service file.

ExecStart=/opt/basicstation/bin/station -h /etc/basicstation --radio-init=/etc/basicstation/reset_gw.sh

I also extended the default 200ms start up time by adding “RADIO_INIT_WAIT”: “2s”, to the station.conf file.

    "station_conf": {
         "RADIO_INIT_WAIT": "2s",
          .....

Thanks to @bigjohnson for his tutorial, and I hope this helps some other RFH0M301 owners.

2 Likes

Hi AndyG,

For the gateway EUI, can i generate it and use the EUI that given by the The Things Stack?

Hi NorHairil,

The Gateway EUI must be unique and based on something that you own. As far as I know the TTN console does not generate the EUI for gateways.

I create mine from the MAC address of the ethernet port on my Raspberry Pi. Ethernet MAC addresses are already unique. .

The MAC address is six pairs of hexadecimal characters. The GatewayEUI needs to be eight pairs. The convention is to insert FF FE in the middle of the MAC address.

Use the ifconfig command to get the MAC address for eth0:
IE. ether 01:23:45:67:89:ab would make a GatewayEUI 012345fffe6789ab

Ouh okay I got it.

BTW, I have problem with this error.

root@raspberrypi:~# cp build-rpi-std/bin/station /opt/basicstation/bin cp: cannot stat 'build-rpi-std/bin/station': No such file or directory

Do you know what cause this error? Do i need to get into root from the first step?

Sorry I’m really a newbie in LoRa world :pray: Hope you can help me go through this.

Hi,

I’m not sure how much Raspberry Pi and Linux experience you have, so apologies if this seems very basic. Also I’m not an expert either.

Something may have gone wrong in the “make” command, or you are not in the basicstation directory.
Try a pwd command and see if you are somewhere like /home/pi/basicstation directory. When you did the sudo su - command it might have changed the current directory to /root instead.

Don’t worry about being a newbie. We all had to start in the same place :slight_smile:

Hi AndyG,

Please help me a little bit more.
image
I got live data like this. Why it keeps disconnect and connect and repeat?

I have followed all your steps except for the /boot/config.txt part.

Hi,

Check the basicstation log files on the Raspberry Pi. They should be in /var/log. The log file will let you see what is happening. If you want more detail in the log file, you can change the log_level to verbose in the station.conf file.

It is possible that the SX130X chip needs a reset before Basics Station starts. Check that you have chosen the correct reset pin. If your adapter board connects the SX130X reset pin to pin 7 on the Raspberry Pi, then the option in config.txt will be needed to make pin 7 available.

Thanks AndyG, finally I can connect the gateway to the TTN.
But I have another problem. When I reboot my Raspberry Pi, I got the Kernel Panic error like the picture below shows.
image
Do you know how to deal with this type of problem?

Hi NorHairil,
I’m definitely not any kind of Raspberry Pi or Linux expert. The error indicates that the Pi cannot find the root file system on the SD card.

The first thing I would try is removing and reinserting the SD card, but I suspect that the file system on the SD card has probably been corrupted somehow.

Have you been getting low power warning messages on the Pi? With the gateway connected you need to make sure that you have a good power supply.

Search the Internet for ways to repair the file system and keep the files. If the SD card has already been used for few years, it is sometimes quicker and safer to redo the build again on a new SD card.

Hi guys , i try to start my gw , but i found this issue root@raspberrypi:/etc/basicstation# systemctl status basicstation.service
â—Ź basicstation.service - Basic Sation TTN V3 service
Loaded: loaded (/lib/systemd/system/basicstation.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Tue 2022-01-11 22:19:43 GMT; 3s ago
Process: 1706 ExecStart=/opt/basicstation/bin/station -h /etc/basicstation --radio-init=/etc/basicstation/reset_gw.sh (code=exited, status=1/FAILURE)
Main PID: 1706 (code=exited, status=1/FAILURE)
CPU: 17ms
root@raspberrypi:/etc/basicstation#
Could you please help me with this issue?

Hi Andre.

I think the starting point to investigate your problem is to double check all connections between the Pi and the gateway card. Pay particular attention to which pin the gateway’s reset pin is connected to on the Raspberry Pi. Make sure that you use the correct pin in the reset.sh script.

Make sure that the SPI interface is enabled on the Raspberry Pi.

Also you need a good quality power supply to run the Pi and the gateway card together. I use an official Raspberry Pi power supply. I have tried some phone chargers, but even those rated for 2.2A do not work reliably.

Hi AndyG,
I used a Raspberry Pi 4B and when I want to reset the sx1301(start the reset_gw.sh),I got the error below:
./reset_gw.sh: line 4: echo: write error: Device or resource busy
./reset_gw.sh: line 5: /sys/class/gpio/gpio7/direction: No such file or directory
./reset_gw.sh: line 6: /sys/class/gpio/gpio7/value: No such file or directory
./reset_gw.sh: line 8: /sys/class/gpio/gpio7/value: No such file or directory
./reset_gw.sh: line 10: /sys/class/gpio/gpio7/value: No such file or directory
./reset_gw.sh: line 12: echo: write error: Invalid argument

And the reset_gw.sh is:
#! /bin/bash

SX1301_RESET_BCM_PIN=7
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

First off, is GPIO 7 the signal connected to the concentrator reset on your particular hardware, or did you just copy that from someone else rather than verify it for our specific concentrator to pi adapter board?

And are you actually using basicstation, or did you just post in this topic because of a similar mention?

Not sure if it is the issue, but something I’ve noticed is that on some Linux systems, trying to again export a GPIO that is already exported has the odd effect of unexporting it, causing the /sys/class/gpio/gpio7/ or whatever directory to disappear. If this is such a system and you’re running the script multiple times it’s possible you’ve gotten such a mixed up state.

I’d try the commands manually one at a time checking what’s showing up in sysfs as you do so.

Actually,my concentrator is RHF0M301 and I am setting it through the method.Then I met this error.
My imager is “2022-01-28-raspios-bullseye-armhf.img”,the latest imager download in Operating system images – Raspberry Pi

As cslorabox says, you need to know which RPi GPIO pin is connected to your concentrator’s reset pin.

My notes describe how to make Pin 7 available to use as a reset pin. The script provided works for the adapter board supplied with my rhf0m301 from Seeed Studios which connects Pin 7 to reset. This is a problem with modern Rasbian builds which assume that Pin 7 is available as a chip select pin for SPI.

If your reset pin is connected to Pin 7 you will need to make it available by adding

overlay=spi0-1cs

in the [all] section of /boot/config.txt. This will tell Rasbian not to reserve Pin 7 as a Chip Select pin for SPI.

I think that more recent concentrator cards and adapter boards avoid using Pin 7, so check the documentation to see which pin is being used.

dtoverlay or overlay?
I have already added the dtoverlay = spi0-1cs like you said

Sorry, yes that was a cut and paste error.

The errors you are seeing are pretty much the same as I saw without the dtoverlay = spi0-1cs.

Is there anything else you are doing that might be setting/ resetting the modern RPi defaults for SPI after the boot phase? do you have any other SPI devices attached to the Pi besides the concentrator card?

There is nothing besides the concentrator.
And my situation is just like the NorHairil——it keeps disconnect and connect and repeat