OpenWrt Forum Archive

Topic: How to blink your IP address using an LED

The content of this topic has been archived on 1 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I wrote this so I could find out my DHCP-assigned IP address without having to poke around with nmap or other tools.  It was written for a TP-LINK TL-WR703N but you can adjust to suit your hardware.  Just change the LEDFILE variable to the LED that you want to blink.  This script assumes you are using DHCP on the LAN interface, in a bridged configuration (br-lan).

EDIT:  Zeros are represented by a longer blink, or "dash", and the periods between octets by a 3 second pause.

#!/bin/sh
# Script for controlling the LED on a TP-LINK TL-WR703N
# Use at bootup to find your LAN IP address
LEDFILE=/sys/devices/platform/leds-gpio/leds/tp-link\:blue\:system/brightness
IPADDR=$(ifconfig br-lan | grep inet | sed 's/^.*addr://' | sed 's/  Bcast.*//')

turnoff ()
{
  echo "0" > $LEDFILE
}

turnon ()
{
  echo "1" > $LEDFILE
}

dot ()
{
  turnon
  sleep 1
  turnoff
  sleep 1
}

dash ()
{
  turnon
  sleep 2
  turnoff
  sleep 1
}


turnoff
echo $IPADDR | while IFS= read -r -n1 char
do
  echo $char
  if [[ "$char" != "." && "$char" != "0" && "$char" != "" ]]; then
    for n in `seq 1 $char`; do
      dot
    done
    sleep 1
  elif [[ "$char" == "0" ]]; then
    dash
  else
    sleep 3
  fi
done

(Last edited by greenleaf on 4 Feb 2012, 21:00)

I don't have any use for it but I thought it was cool that you posted it for others to use so thanks smile

Interesting idea, but it takes way too long to blink out an IP address. It'd be probably enough to blink out the last octet, maybe even in binary (short for 0, long for 1)?

The discussion might have continued from here.