Skip to content

Instantly share code, notes, and snippets.

@joleuger
Last active August 29, 2015 14:21
Show Gist options
  • Save joleuger/1a6bcb69295f6b05707b to your computer and use it in GitHub Desktop.
Save joleuger/1a6bcb69295f6b05707b to your computer and use it in GitHub Desktop.
WLAN debian autoreconnect (ping method)

I had problems with my raspberry pi disconnecting and never reconnecting to a WiFi-network. There are already several different solutions

  • http://raspberrypi.stackexchange.com/questions/4120/how-to-automatically-reconnect-wifi
  • http://www.forum-raspberrypi.de/Thread-wlan-reconnect-nach-verbindungsabbruch?page=2

This is mine:

  1. vim /usr/local/sbin/wlan-reconnect
  2. chmod +x /usr/local/sbin/wlan-reconnect.sh
  3. vim /etc/systemd/system/wlan-reconnect.timer
  4. vim /etc/systemd/system/wlan-reconnect.service
  5. systemctl daemon-reload
  6. systemctl enable wlan-reconnect.timer
  7. systemctl start wlan-reconnect.timer
[Unit]
Description=Restart WLAN if down
[Service]
Type=simple
ExecStart=/usr/local/sbin/wlan-reconnect.sh
#!/bin/bash
ROUTERIP=192.168.50.253
ping -c4 ${ROUTERIP} > /dev/null
if [ $? != 0 ]
then
echo "WiFi seems down, restarting."
#shutdown -r 0
ifdown --force wlan0
/etc/init.d/networking stop
killall wpa_supplicant
/etc/init.d/networking start
ifup wlan0
echo "WiFi should be up again."
sleep 40
ping -c4 ${ROUTERIP} > /dev/null
if [ $? != 0 ]
then
shutdown -r 0
else
echo "WiFi up again."i
exit 0
fi
else
echo "WiFi ok"
exit 0
fi
[Unit]
Description=Restart WLAN if down
[Timer]
OnCalendar=*-*-* *:*:00
Persistent=false
[Install]
WantedBy=timers.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment