Kontakt:

Fixing GPIO Error Elecrow LR1302 LoRaWAN Gateway on RPi Bookworm

For those who purchased the Elecrow LR1302 LoRaWAN Gateway Module together with the LR1302 LoRaWAN HAT for Raspberry Pi, might find that the software installation requires some experience and modification.
This BlogEntry aims at helping those in a need of better instructions.

The installation instructions for a Raspberry Pi needs some digging in the web... well, at least it was necessary for me.
So here's the link to the Elecrow WiKi page with the install instructions. I'm using the SPI version of the gateway module, so there was no need for me using the USB cable.

https://www.elecrow.com/wiki/lr1302-lorawan-gateway-module.html

I'm using the HAT on a Raspberry Pi4 with PiOS Bookworm

After the installation has been completed, you might notice that the startup script throws a number of errors related to the way it tries to access the GPIOs.
Reason is simple: the way it is done is no longer available in Bookworm and never was offcially supported. A good reason for an update.

First of all:
1. You MUST enable I2C and SPI interfaces in raspi-config!
2. You MUST free the UART from the console entry, but leave it enabled
3. You MUST set the serial port in your JSON config file to /dev/ttyS0 .... the "0" is missing in the file

After that please find a working reset_lgw.sh script below:
This is using the already availabe gpioset function from Bookworm which should be future proof.


#!/bin/bash

# reset_lgw.sh – compatible with Raspberry Pi Bookworm via gpioset
# Verwendung: ./reset_lgw.sh start | stop

# BCM-Pins
SX1302_RESET_PIN=17
SX1302_POWER_EN_PIN=18
SX1261_RESET_PIN=5
AD5338R_RESET_PIN=13

# GPIO-Chip (normally 0 on Raspberry Pi)
CHIP=0

wait_gpio() {
sleep 0.1
}

init() {
echo "Initialisiere GPIOs (kein Export nötig mit gpioset)..."
# keine Initialisierung nötig – gpioset setzt automatisch direction=out
}

reset() {
echo "==> SX1302 Power Enable (GPIO$SX1302_POWER_EN_PIN)"
gpioset $CHIP $SX1302_POWER_EN_PIN=1
wait_gpio

echo "==> SX1302 Reset (GPIO$SX1302_RESET_PIN)"
gpioset $CHIP $SX1302_RESET_PIN=1
wait_gpio
gpioset $CHIP $SX1302_RESET_PIN=0
wait_gpio

echo "==> SX1261 Reset (GPIO$SX1261_RESET_PIN)"
gpioset $CHIP $SX1261_RESET_PIN=0
wait_gpio
gpioset $CHIP $SX1261_RESET_PIN=1
wait_gpio

echo "==> AD5338R Reset (GPIO$AD5338R_RESET_PIN)"
gpioset $CHIP $AD5338R_RESET_PIN=0
wait_gpio
gpioset $CHIP $AD5338R_RESET_PIN=1
wait_gpio
}

term() {
echo "Reset GPIOs..."
gpioset $CHIP $SX1302_RESET_PIN=0
gpioset $CHIP $SX1261_RESET_PIN=0
gpioset $CHIP $SX1302_POWER_EN_PIN=0
gpioset $CHIP $AD5338R_RESET_PIN=0
wait_gpio
}

case "$1" in
start)
term # to be sure
init
reset
;;
stop)
reset
term
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac

exit 0

Don't forget to mark the new script as executable. The original one wasn't executable either ...
As this was working great, I found it nice having a systemd service taking care of an automatic start and re-start of the program.
Here's a simple systemd startup script.... please take care to modify the path in case you don't run it under the user "pi"

Create a new script:

sudo nano /etc/systemd/system/lora_pkt_fwd.service

...and copy/paste the content below:


[Unit]

Description=LoRa Packet Forwarder


After=network-online.target


Wants=network-online.target

[Service]
ExecStart=/home/pi/LR1302_loraWAN/LR1302_HAL/sx1302_hal/packet_forwarder/lora_pkt_fwd
WorkingDirectory=/home/pi/LR1302_loraWAN/LR1302_HAL/sx1302_hal/packet_forwarder
User=pi
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

Then just enable and start the service:



sudo systemctl daemon-reload


sudo systemctl enable lora_pkt_fwd.service


sudo systemctl start lora_pkt_fwd.service

Hope this helps someone saving some time....

More Coffee! – Or our view how to pimp a great Italian Lelit Espresso Machine. (Warning! Nerdy!)

Also we need coffee … A lot of it! Therfore we obtained a high quality Lelit Mara X V2 Espresso Machine for household use. It’s a great device, however in an Enineering Office, only rarely the things remain in its original design and need to be inspected, modified, improved or even disassembled.

See our Page about the Mara X V2 internal electronics and how to visualize what it is doing.