Last active
November 21, 2022 07:02
-
-
Save jareddantis/362ea3c2d5b6208f6d9c385a98134f5f to your computer and use it in GitHub Desktop.
Custom scripts for LED functionality in TL-WA860RE repeaters running DD-WRT.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This version of the script is meant for repeaters running in client mode, | |
# i.e. rebroadcasting Wi-Fi on a different LAN from an existing wireless network. | |
# Run this on startup like so: | |
# sleep 10 | |
# sh /tmp/custom.sh & | |
# LED behavior: | |
# WLAN green - AP up, Good connection to base station | |
# amber - AP up, Poor connection to base station | |
# off - AP down | |
# Eth green - Ethernet connected | |
# Eth off - Ethernet disconnected | |
# Pwr green - AP up | |
# amber - AP down | |
# Updated as of build 50906. | |
WLAN_AMBER=0 | |
WLAN_GREEN=2 | |
PWR_AMBER=12 | |
PWR_GREEN=14 | |
ETH_GREEN=20 | |
hi(){ | |
gpio disable "$1" | |
} | |
lo(){ | |
gpio enable "$1" | |
} | |
# Don't run if already running | |
if ps | grep custom.sh | grep -v $$ | grep sh | grep -v grep; then | |
echo "Script already running as seen above. Exiting." | |
exit 1 | |
fi | |
# Main loop | |
while sleep 1; do | |
# Connection data | |
rssi=$(iw ath0 link | awk '/signal/ {print $2}') | |
wan_state=$(cat /sys/class/net/wlan0/operstate) | |
eth_state=$(cat /sys/class/net/eth0/carrier) | |
# Ethernet connected state | |
if [ "$eth_state" -eq 1 ]; then | |
hi $ETH_GREEN | |
else | |
lo $ETH_GREEN | |
fi | |
# WLAN connected & signal states | |
if [ "$wan_state" = "up" ]; then | |
hi $PWR_GREEN | |
lo $PWR_AMBER | |
if [ "$rssi" -lt -67 ]; then | |
hi $WLAN_AMBER | |
lo $WLAN_GREEN | |
else | |
hi $WLAN_GREEN | |
lo $WLAN_AMBER | |
fi | |
else | |
lo $WLAN_AMBER | |
lo $WLAN_GREEN | |
hi $PWR_AMBER | |
lo $PWR_GREEN | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This version of the script is meant for repeaters running in AP mode, | |
# i.e. broadcasting Wi-Fi from a LAN connection. | |
# Run this twice on startup with the "ping" option on the second run like so: | |
# sleep 10 | |
# sh /tmp/custom.sh & | |
# sh /tmp/custom.sh ping & | |
# LED behavior: | |
# WLAN green - AP up, Internet up | |
# amber - AP up, Internet down | |
# off - AP down | |
# Eth green - Ethernet connected | |
# Eth off - Ethernet disconnected | |
# Pwr green - AP up | |
# amber - AP down | |
# Updated as of build 50906. | |
WLAN_AMBER=0 | |
WLAN_GREEN=2 | |
PWR_AMBER=12 | |
PWR_GREEN=14 | |
ETH_GREEN=20 | |
hi(){ | |
gpio disable "$1" | |
} | |
lo(){ | |
gpio enable "$1" | |
} | |
# Check if we are running in connection watchdog mode | |
if [ "$1" = "ping" ]; then | |
if [ -f "/tmp/cwdog.lock" ]; then | |
echo "Already running, replacing instance." | |
kill -9 "$(cat /tmp/cwdog.lock)" | |
fi | |
echo $$ > /tmp/cwdog.lock | |
while sleep 10; do | |
ping -c 1 8.8.8.8 1>/dev/null | |
ping_result=$? | |
if [ "$ping_result" -eq 0 ]; then | |
echo "up" > /tmp/ping_result | |
else | |
echo "down" > /tmp/ping_result | |
fi | |
done | |
else | |
if [ -f "/tmp/ledd.lock" ]; then | |
echo "Already running, replacing instance." | |
kill -9 "$(cat /tmp/ledd.lock)" | |
fi | |
echo $$ > /tmp/ledd.lock | |
# Main loop | |
while sleep 1; do | |
# Connection data | |
conn_state=$(cat /tmp/ping_result) | |
wlan_state=$(cat /sys/class/net/wlan0/operstate) | |
eth_state=$(cat /sys/class/net/eth0/carrier) | |
# Ethernet connected state | |
if [ "$eth_state" -eq 1 ]; then | |
hi $ETH_GREEN | |
else | |
lo $ETH_GREEN | |
fi | |
# AP & connection states | |
if [ "$wlan_state" = "up" ]; then | |
hi $PWR_GREEN; lo $PWR_AMBER | |
if [ "$conn_state" = "up" ]; then | |
hi $WLAN_GREEN; lo $WLAN_AMBER | |
else | |
hi $WLAN_AMBER; lo $WLAN_GREEN | |
fi | |
else | |
lo $WLAN_AMBER; lo $WLAN_GREEN | |
hi $PWR_AMBER; lo $PWR_GREEN | |
fi | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment