4

I'm building a wireless photoframe. The one thing I haven't been able to figure out is how to get my wifi connection back up using a recommended method.

Right now I edited /etc/network/interfaces so wlan0 is started at boot:

auto wlan0
iface wlan0 inet dhcp
        wireless-essid ourssid

This method works fine for booting. But I found that if I do not check the connection for a long time (could be a week) it might be down. So I should reconnect.

What I do now to verify the connection is working is downloading a file from the server that can't be cached (http://server.ext/ping.php?randomize=123456) If I fail to retrieve the file I assume that the connection is no longer working and I run a shell script like

#!/bin/bash
ifconfig wlan0 up
iwconfig wlan0 essid "ourssid"
dhclient wlan0

And the connection comes back. But I can't find anything if this is in any way a good method.

Can this be improved upon, or is this already right?

Ruud
  • 249

2 Answers2

4

I found the following script at http://sirlagz.net/2013/01/10/script-wifi-checker-script/

  • Just create a new file vi /root/checkwanup:

    #!/bin/bash
    
    wlan=`/sbin/ifconfig wlan0 | grep inet\ addr | wc -l`
    
    if [ $wlan -eq 0 ]; then
    /sbin/ifdown wlan0 && /sbin/ifup wlan0
    else
    echo interface is up
    fi
    
  • Then chmod 555 /root/checkwanup

  • Add it to your crontab

    crontab -e
    */15 * * * * /bin/bash /root/checkwanup
    
user.dz
  • 48,105
DougD
  • 71
  • 1
3

ifup wlan0 should do all that for you automatically.

It reads the interfaces file and does everything that startup would do. You may have to run ifdown wlan0 first if ifup believes the interface is already up.

You could make a small script to try getting the file and then run ifup if it fails and cron it for every hour or two.

Caesium
  • 15,807