Hi all,
this is for users with Raspberry Pi and “bookworm” Raspian:
I had the known GPIO errors when restarting the packet forwarder using “sudo gateway-config”, for example. When it’s restarting, the reset-gpio-pins are not working since the sysfs-gpio commands are not supported anymore with raspbian bookworm.
Instead of sysfs-gpio, you now have to use gpiod as a method to access and set/reset the GPIOs.
To solve the issue (which otherwise always needs a powercycle to bring up the gateway again), we have to change the sys-fs commands to gpiod. Since there is nothing to “init”, I commented-out the init task at the bottom as well.
In the following code I just commented-out the original commands in case you want to roll-back.
/opt/ttn-gateway/packet_forwarder/lora_pkt_fwd/reset_lgw.sh
:
#!/bin/sh
# This script is intended to be used on SX1302 CoreCell platform, it performs
# the following actions:
# - export/unpexort GPIO23 and GPIO18 used to reset the SX1302 chip and to enable the LDOs
#
# Usage examples:
# ./reset_lgw.sh stop
# ./reset_lgw.sh start
# GPIO mapping has to be adapted with HW
#
SX1302_RESET_PIN=17
WAIT_GPIO() {
sleep 0.1
}
init() {
# setup GPIOs
# echo "$SX1302_RESET_PIN" > /sys/class/gpio/export; WAIT_GPIO
# echo "Init reset_lgw.sh done"
# set GPIOs as output
# echo "out" > /sys/class/gpio/gpio$SX1302_RESET_PIN/direction; WAIT_GPIO
}
reset() {
echo "CoreCell reset through GPIO$SX1302_RESET_PIN..."
# echo "1" > /sys/class/gpio/gpio$SX1302_RESET_PIN/value; WAIT_GPIO
gpioset gpiochip0 $SX1302_RESET_PIN=1
sleep 0.1
# echo "0" > /sys/class/gpio/gpio$SX1302_RESET_PIN/value; WAIT_GPIO
gpioset gpiochip0 $SX1302_RESET_PIN=0
sleep 0.1
}
term() {
# cleanup all GPIOs
# if [ -d /sys/class/gpio/gpio$SX1302_RESET_PIN ]
# then
# echo "$SX1302_RESET_PIN" > /sys/class/gpio/unexport; WAIT_GPIO
# fi
gpioget gpiochip0 $SX1302_RESET_PIN
}
case "$1" in
start)
term # just in case
# init
reset
;;
stop)
reset
term
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
exit 0
In the file start.sh in the same directory as reset_lgw.sh, you need to do the same.
/opt/ttn-gateway/packet_forwarder/lora_pkt_fwd/start.sh
:
#! /bin/bash
# Reset iC880a 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
gpioset gpiochip0 $SX1301_RESET_BCM_PIN=0
sleep 0.1
#echo "1" > /sys/class/gpio/gpio$SX1301_RESET_BCM_PIN/value
gpioset gpiochip0 $SX1301_RESET_BCM_PIN=1
sleep 0.1
#echo "0" > /sys/class/gpio/gpio$SX1301_RESET_BCM_PIN/value
gpioset gpiochip0 $SX1301_RESET_BCM_PIN=0
sleep 0.1
#echo "$SX1301_RESET_BCM_PIN" > /sys/class/gpio/unexport
gpioget gpiochip0 $SX1301_RESET_BCM_PIN
./set_eui.sh
sleep 0.2
#./update_gwid.sh ./local_conf.json
sleep 0.5
./lora_pkt_fwd
Without this modification, a restart of the packet forwarder did not work for me and instead it required a powercycle of the whole gateway, to bring back the lgw to its initial state.
Of course, a cleaner look can be achieved by deleting all old commands and unsued methods like “WAIT_GPIO()” and such. I’ll post a cleaned up version below.