My openwrt router runs on a raspberry pi 4 which got gpio pins.
Like we do on traditional raspberry pi, can we control the GPIO pins voltage?
My idea is to setup a system service that check for internet connectivity, and when no connectivity, toggle gpio pin voltage to turn the led connected to it off.
Thanks.
I came up with below to achieve this,
#!/bin/sh
CHIP="gpiochip0"
GPIO=14
STATE_FILE="/tmp/gpio14.state"
# Turn off LED initially
gpioset -c $CHIP -z $GPIO=0
echo 0 > $STATE_FILE
while true; do
if ping -c 1 -W 2 192.168.0.243 > /dev/null 2>&1; then
if [ "$(cat $STATE_FILE)" != "1" ]; then
killall gpioset 2>/dev/null
gpioset -c $CHIP -z $GPIO=1
echo 1 > $STATE_FILE
killall gpioset 2>/dev/null
fi
else
if [ "$(cat $STATE_FILE)" != "0" ]; then
killall gpioset 2>/dev/null
gpioset -c $CHIP -z $GPIO=0
echo 0 > $STATE_FILE
killall gpioset 2>/dev/null
fi
fi
sleep 10
done
is there a better approach for this?