Wifi connection test on Raspberry

wifiI don’t know if you have same issue with your raspberry after a network restart but sometimes raspberry do not reconnect itself to the Internet wifi. In that case the solution is to restart it by simply power shutdown. A little rough but it works well…

The problem is when you are not at home! If this happens your rasbeppy will remain disconnected from the network until you return … (no backup of NAS, no domoticz, no web server …)

So I made a realy simple script that will test the Internet connection and restart my rasberry in case of connection failure. Of course when your network is really out of order (internet outage, for example) it will restart every time the script is started ! That’s why shedule the script only every 20 minutes …

Here the script:

#! / usr / bin / ksh
######################################
#
# This script Will test the wireless connection
# Reboot the server in case of not connected
#
######################################
# Test connection with max 5s
https://www.google.com curl -s -m 5> / dev / null
CR = $?
if [$ CR! = 0]
Then
        echo "` ping date` Problem $ RC = CR "/tmp/test_wifi.log >>
        echo "Restarting Server" >> /tmp/test_wifi.log
        / sbin / reboot
else
        echo "` date` ping RAS code return $ CR "/tmp/test_wifi.log >>
fi

And the shedule using cron e
very 20 min :

# Check wifi
* / 20 * * * * /root/scripts/test_wifi.sh

Improvement:

  • find theroot cause and solve it …  But that’s for another day …

Leave a Reply

Your email address will not be published. Required fields are marked *