Posts: 118
Joined: Sun Jul 05, 2015 10:01 pm

Wifi reconnect

Sun Oct 04, 2015 2:42 pm

Hello, my raspberry pi can works a few days without me, i buy offical wi-fi usb module then choose my network and wrote password - the internet is working, but raspberry can lose network and if i want connect to wifi again i must restart raspberry or remove and insert wifi module, how to make it automatically (if raspberry lose network it must to try to reconnect)?

User avatar
Posts: 37073
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Wifi reconnect

Sun Oct 04, 2015 3:04 pm

Try running this every ten minutes from crontab.

Code: Select all


router=`ip route | awk '/default/ {print $3}'`
/bin/ping -q -c1 $router > /dev/null

if [ $? -eq  0 ]
  : #  echo "Network active"

  echo "Network down, fixing..."
#  ifdown --force wlan0
  /bin/kill -9 `pidof wpa_supplicant`
  /sbin/ifup --force wlan0
  /sbin/ip route add default via $router dev wlan0
  /bin/mount -a
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Beginners”