1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Custom script to light up LED light when WAN connection is up

Discussion in 'Tomato Firmware' started by borez, Aug 19, 2007.

  1. borez

    borez LI Guru Member

    Hi all,

    I remember DD-WRT has this nifty feature to light up the LED lights when a WAN connection is established.

    Was wondering if anyone has a script for this? Understand that this should be placed in the WAN Up section.

    Thanks a lot!
     
  2. yaqui

    yaqui LI Guru Member

    Place under wan up:
    Code:
    sleep 5
    I=`nvram get wl0_ifname`
    while sleep 1; do
    if [ "`wl assoclist`" != "" ]; then
    XFER=`ifconfig $I|grep bytes`
    if [ "$XFER" != "$PXFER" ]; then
    LED="amber on white on"
    PXFER=$XFER
    else
    LED="amber on white off"
    fi
    else
    LED="amber off white off"
    fi
    if [ "$LED" != "$PLED" ]; then
    led $LED
    PLED=$LED
    fi
    done
     
  3. srouquette

    srouquette Network Guru Member

    you can put it in "init" instead of "wan up"
     
  4. MiseryQ

    MiseryQ Network Guru Member

    That's where I have it.
     
  5. borez

    borez LI Guru Member

    Hi all,

    I've placed this in the WAN Up script section, rebooted - but still no go: there's no LED light.

    Is there any other option that I need to enable?
     
  6. srouquette

    srouquette Network Guru Member

    ah !
    the script above show a light when there's a WLAN (WiFi) connection, not WAN.
    sorry about that.
     
  7. borez

    borez LI Guru Member

    Ha, I realised it as well - no wonder it looks very similar to the earlier wireless script I've seen.

    Thanks anyway..
     
  8. Odin-60

    Odin-60 LI Guru Member

    Go to Administration - Scripts - WAN Up, enter

    led amber on

    into the text field, click on Save, and reboot.
    Well, the LED will not be turned off again, in case
    the WAN goes down. Unfortunately there is no
    "WAN down" script.
     
  9. MiseryQ

    MiseryQ Network Guru Member

    Doesn't the WAN LED come on when there's a connection?
     
  10. yaqui

    yaqui LI Guru Member

    I don't see a WAN led on my router.. there is a WLAN and an Internet one though.

    Maybe thats why they need this. I originally thought they wanted it for the wireless.
     
  11. yaqui

    yaqui LI Guru Member

    Maybe this would work to see if wan is active?
    I notice when I do 'service wan stop' ; ppp0 disappears from 'route' output.

    For pppoe connection it would be this:
    Code:
    while sleep 1; do
    if route | grep -q ppp0 ; then 
    led amber on
    else
    led amber off
    fi
    done
     
  12. roadkill

    roadkill Super Moderator Staff Member Member

    what about the same functionality for VPN?
     
  13. Odin-60

    Odin-60 LI Guru Member

    The WAN LED shows that a working device, for instance
    a DSL modem, is connected to the WAN ethernet port.
    It does, however, not indicate whether a logical connection
    (for instance PPPoE) has been established.
     
  14. Overflow-ar

    Overflow-ar LI Guru Member

    This is my script, just power led white on when internet connectivity is fine. and amb led when is down.

    Just place an ip address between the "" with your ISP DNS

    ## Light Internet
    ipaddress=""
    echo -e "if ping -c 1 \"$ipaddress\"; then \n led white on \n led amb off \n else \n led white off \n led amb on \n fi" > /tmp/light-online
    chmod 777 /tmp/light-online
    cru a light-online "*/1 * * * *" /tmp/light-online
     
  15. kufi

    kufi Network Guru Member

    nice idea, but ofcourse, it works only, when your ISP enable ping your dns server .)
     
  16. yaqui

    yaqui LI Guru Member

    You don't have to type in an ip address

    Code:
    ## Internet Connection Ping Light aka icplight ##
    ## Ping Version ##
    if [ ! -x /tmp/icplight ] ; then
    cat > /tmp/icplight <<EOF
    #!/bin/sh
    if ifconfig | grep UP ; then
    dns=$(nvram get wan_get_dns | cut -d" " -f1)
       if ping -q -c 1 $dns ; then 
          led amber on
          led white off
          else 
          led amber off
          led white off
       fi
    fi
    EOF
    fi
    chmod +x /tmp/icplight
    ## cru schedule for every minute
    cru a icplight "* * * * * /tmp/icplight"
    Plus does your ISP really want you pinging their server every minute or less? Not sure if that matters but....

    Maybe route method is better... just find out what name goes missing when you do 'service wan stop' and put it in the grep statement in place of ppp0.

    Code:
    ## Internet Connection Route Light aka icrlight ##
    ## Route Version ##
    if [ ! -x /tmp/icrlight ] ; then
    cat > /tmp/icrlight <<EOF
    #!/bin/sh
    I=$(nvram get wan_iface)
    if [ -n $I ] ; then
       if route | grep -q $I ; then
          led amber on white off
          else
          led amber off white off 
       fi
    fi
    EOF
    fi
    chmod +x /tmp/icrlight
    ## cru schedule for every minute
    cru a icrlight "* * * * * /tmp/icrlight"
     
  17. danix71

    danix71 LI Guru Member

    In init or wan-up script ?
     
  18. danix71

    danix71 LI Guru Member

    Could be done in the future ? :cool:
     
  19. yaqui

    yaqui LI Guru Member

    Huh? these scripts are checking if wan goes down. ;)
     
  20. madsul

    madsul LI Guru Member

    I am using DHCP to connect will this still work?
     
  21. yaqui

    yaqui LI Guru Member

    Yes the ping version will.

    But the route version you have to see what your ifname is: telnet in and type "route", view the output, then type "service wan stop" ; type route again and see what name dissappeared. Then when you done, type "service wan start".

    I'm not sure what it should be because I only have pppoe... post if you find out.
     
  22. Victek

    Victek Network Guru Member

    I use it to check if PPPoE works, then when WAN traffic occurs amber LED blinks ON.

    killall sesx_script.sh
    I=`ifconfig ppp0|grep -q 'UP'`
    while sleep 1; do
    if I=0; then
    XFER=`ifconfig ppp0|grep bytes`
    if [ "$XFER" != "$PXFER" ]; then
    led amb on
    PXFER=$XFER
    else
    led amb off
    fi
    else
    led amb off
    led white off
    fi
    done

    -Victek
     
  23. danix71

    danix71 LI Guru Member


    It worked great ! I put the script in Wan-Up section. Thanks a lot !
     
  24. yaqui

    yaqui LI Guru Member

    If you use route your doing it all in 1 step, plus I don't like the blinking. but whatever *shrugs*
     
  25. danix71

    danix71 LI Guru Member

    This:

    #!/bin/sh

    while :
    do
    ping -c 5 www.example.com >/dev/null # ping 5 packets
    sleep 300 # wait 5 minutes
    done

    will go in Wan-Up script for Tomato ? All I want is to ping an adress from time to time, to keep my ISP thinking that I'm doing some king of traffic..
     
  26. yaqui

    yaqui LI Guru Member

    Yes or just set up for 5 minute cron:
    Code:
    ## Internet Connection Ping aka icping ##
    if [ ! -x /tmp/icping ] ; then
    cat > /tmp/icping <<EOF
    #!/bin/sh
    ping -q -c 5 google.com 
    EOF
    chmod +x /tmp/icping
    ## cru schedule for every 5 minutes
    cru a icping "*/5 * * * *" /tmp/icping
    fi
    Or you could "hit" multiple sites like this using wget or you could use ping instead:
    Code:
    if [ ! -x /tmp/hitsites ] ; then
    cat > /tmp/hitsites <<EOF
    #!/bin/sh
    wget -O /dev/null http://www.site1.com
    wget -O /dev/null http://www.site2.com
    wget -O /dev/null http://www.site3.com
    wget -O /dev/null http://www.site4.com
    wget -O /dev/null http://www.site5.com
    wget -O /dev/null http://www.site6.com
    wget -O /dev/null http://www.site7.com
    EOF
    chmod +x /tmp/hitsites
    cru a hitsites "*/5 * * * * /tmp/hitsites"
    fi
     
  27. danix71

    danix71 LI Guru Member

    Brilliant !:clap: If I may, one more question, please: could be done ? to "host" a browser window on the router, one that will be somekind of chat between me accesing the router from WAN and the others accesing the router from within the LAN?
     
  28. yaqui

    yaqui LI Guru Member

    For chatting? How about just use a vpn with some type of instant messaging program?

    Or, just use instant messaging over the internet?
     
  29. danix71

    danix71 LI Guru Member

    Suppose that the Internet (as web pages) doesn't work, just connection to the router...
     
  30. yaqui

    yaqui LI Guru Member

    You both could log on via ssh/telnet then type notes in vi to files that you would save in /tmp

    Then just read the files :p Just use different ports for ssh per machine.
     
  31. danix71

    danix71 LI Guru Member

    :) Too complicated for a novice like me and my wife...So, couldn't be done like in old fashioned way, web pages...
     
  32. yaqui

    yaqui LI Guru Member

    You would have to have some type of messaging or http server built in to do that, seems more complicated than previous suggestion.

    Just yell across the house... :p Or if you have network printers; send printed pages.
     
  33. danix71

    danix71 LI Guru Member

    Hihi :) it's an ideea. :)
     
  34. danix71

    danix71 LI Guru Member

    Sorry to bother, again, but I want to know: not to blink, but a white led on when PPPoE connection, both led's (white&amber) off when no connection...

    LE: I've got it! Thanks.
     
  35. yaqui

    yaqui LI Guru Member

    This should work for DHCP and PPPoE:
    Code:
    ## Internet Connection Route Light aka icrlight ##
    ## Route Version ##
    if [ ! -x /tmp/icrlight ] ; then
    cat > /tmp/icrlight <<EOF
    #!/bin/sh
    I=$(nvram get wan_iface)
    if [ -n $I ] ; then
       if route | grep -q $I ; then
          led amber on white off
          else
          led amber off white off 
       fi
    fi
    EOF
    fi
    chmod +x /tmp/icrlight
    ## cru schedule for every minute
    cru a icrlight "* * * * * /tmp/icrlight"
     
  36. madsul

    madsul LI Guru Member

    Sorry I'm not sure where this should go I tried Wan Up and Init. Do I need to change something?
     
  37. danix71

    danix71 LI Guru Member

    Hi ! I put it (the script) in the Wan-UP section. It works great, I've change it just the led's color (white to light-up when pppoe connection is on/up and amber when is down).

    ## Internet Connection Route Light aka icrlight ##
    ## Route Version ##
    if [ ! -x /tmp/icrlight ] ; then
    cat > /tmp/icrlight <<EOF
    #!/bin/sh
    I=$(nvram get wan_iface)
    if [ -n $I ] ; then
    if route | grep -q $I ; then
    led amber off white on
    else
    led amber on white off
    fi
    fi
    EOF
    fi
    chmod +x /tmp/icrlight
    ## cru schedule for every minute
    cru a icrlight "* * * * *" /tmp/icrlight
     
  38. madsul

    madsul LI Guru Member

    I keep getting this message in Wallwatcher

    <77>crond[89]: user root pid 460 cmd /tmp/icrlight #icrlight#

    and a amber light
     
  39. danix71

    danix71 LI Guru Member

    You put the exact script ? Maybe you don't have a connection...or not pppoe anyway...
     
  40. yaqui

    yaqui LI Guru Member

    That is the cron, is your connection working when you see amber light?

    That is how it is supposed to work. Every minute it checks.

    If not, try this:
    Code:
    ## Internet Connection Route Light aka icrlight ##
    ## Route Version ##
    if [ ! -x /tmp/icrlight ] ; then
    cat > /tmp/icrlight <<EOF
    #!/bin/sh
    I=$(nvram get wan_iface)
    if [ -n "$I" ] ; then
       if route | grep -q $I ; then
          led amber on white off
          else
          led amber off white off 
       fi
    fi
    EOF
    fi
    chmod +x /tmp/icrlight
    ## cru schedule for every minute
    cru a icrlight "* * * * * /tmp/icrlight"
     
  41. madsul

    madsul LI Guru Member

    I have a DHCP connection
     
  42. danix71

    danix71 LI Guru Member

    Then the script won't work.
     
  43. madsul

    madsul LI Guru Member

    Thank You
     
  44. pfoomer

    pfoomer LI Guru Member

    Led Script. try this

    while sleep 2; do
    if [ -e /tmp/ppp/link ] ; then
    led amber on
    else
    led amber off
    fi
    done

    This works for me, in WAN UP.

    If you pull the ADSL cable or the ethernet cable to the modem the light changes (after a little while).

    Disconnect/connect via the web interface also works.
     
  45. dingmel

    dingmel LI Guru Member

    hi there. what if my connection to the net is via PPTP (VPN). which script would work? thanks
     
  46. Mihai Olimpiu-Cristian

    Mihai Olimpiu-Cristian Serious Server Member

    Wow, this is the only thread I found searching for a fix to my WAN light not working as the factory firmware did. I know this thread is now 6 years old but, I've tried the variants that used CRON jobs but probably there are some changes that affect how the scripts work.
    This is how the script has to be modified for it to work on Shibby v117 using a Belkin Play Max. The code has to go into Wan Up:
    Code:
    ## Internet Connection Route Light aka icrlight ##
    ## Route Version ##
    if [ ! -x /tmp/icrlight ] ; then
    cat > /tmp/icrlight <<EOF
    #!/bin/sh
    I=\$(nvram get wan_iface)
    if [ -n \$I ] ; then
       if route | grep -q \$I ; then
          led diag off
          else
          led diag on
       fi
    fi
    EOF
    fi
    chmod +x /tmp/icrlight
    ## cru schedule for every minute
    cru a icrlight "* * * * * /tmp/icrlight"
    Only difference is that $ has to pe preceded by \ otherwise the /tmp/icrlight script doesn't work properly and changed led command (it now uses only diag/aoss/dmz/usb) arguments.

    I used the same logic to modify a script so I use dmz/aoss leds as a cpu meter, this I pasted into Init:
    Code:
    ## CPU meter aka cpulight ##
    if [ ! -x /tmp/cpulight ] ; then
    cat > /tmp/cpulight <<EOF
    #!/bin/sh
    la=\$(cat /proc/loadavg | cut -d" " -f1 | tr -d .)
    [ \$la -gt 70 ] && led aoss on dmz off || ([ \$la -gt 30 ] && led aoss on dmz on || led aoss off dmz on)
    EOF
    fi
    chmod +x /tmp/cpulight
    ## cru schedule for every minute
    cru a cpulight "* * * * * /tmp/cpulight"
     

Share This Page