Page 1 of 1

[FIX] Wifi Disconnect

Posted: Tue Sep 24, 2019 3:46 pm
by vinanrra
  • Put the script into the home dir, like: /home/pi
  • Edit the parameter in the script

    # NetCard and PingTarget should be modified.
  • Add x priority to the script

    chmod +x
  • Add a task with crontab
    crontab -e

    Add this line which means run the script every 5 minutes between 8:00 and 22:00.

    */5 8-22 * * * ~/
Log file generated in home dir, like: /home/pi/NetReconnector.log

Code: Select all

# by nickwang

NetCard=wlan0	 		# the netcard connected to the internet	# the ping target, router ip or website, etc:,
LogFile=~/NetReconnector.log	# log file
LogAll=false			# log msg no matter whether the net is connected, used to be check whether the script is running.

test -e $LogFile || touch $LogFile

time=$(date "+%Y/%m/%d %H:%M:%S")

ret=$(ping -c 2 -W 1 -I $NetCard $PingTarget | grep 'received' | cut -d ',' -f 2 | cut -d ' ' -f 2)

if [ "$ret" == "0" ]; then
    sudo ifdown wlan0 && sudo ifup wlan0
    echo "Try Reconnect: $?, $time" | tee -a $LogFile
    if [ "$LogAll" == "true" ]; then
        echo "Network is ok, ret = $ret, $time" | tee -a $LogFile

exit 0
Source: Github

PD: Could be good if you add this script to DietPi because Wifi sometimes drop connection and with this seems to be working 24/7.
I only tested this 2 days and I had no drops, I will write later if my connection drops.

Re: [FIX] Wifi Disconnect

Posted: Fri Sep 27, 2019 11:34 am
by MichaIng
Many thanks for sharing.

Did you try/compare with the WiFi monitor that you can enable within dietpi-config WiFi adapter settings?

Re: [FIX] Wifi Disconnect

Posted: Fri Sep 27, 2019 10:07 pm
by vinanrra
Where it is?

It is the option to enable reconnect?

Re: [FIX] Wifi Disconnect

Posted: Fri Oct 11, 2019 6:06 pm
by MichaIng
Jep the "Auto Reconnect" option.