# \[FIX\] Wifi Disconnect

**URL:** https://dietpi.com/forum/t/fix-wifi-disconnect/3501
**Category:** Community Tutorials
**Created:** [24 September 2019 13:46 UTC](https://dietpi.com/forum/t/fix-wifi-disconnect/3501 "2019-09-24T13:46:54Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![vinanrra](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/v/f19dbf/32.png) [@vinanrra](https://dietpi.com/forum/u/vinanrra)
#### Post date: [24 September 2019 13:46 UTC](https://dietpi.com/forum/t/fix-wifi-disconnect/3501/1 "2019-09-24T13:46:54Z")

</div>

- Put the script into the home dir, like: /home/pi  
  
  
- Edit the parameter in the script

vim NetReconnector.sh

# NetCard and PingTarget should be modified.

- Add x priority to the script

chmod +x NetReconnector.sh

- 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 \* \* \* ~/NetReconnector.sh

> Log file generated in home dir, like: /home/pi/NetReconnector.log

```plaintext
#!/bin/bash
# by nickwang wxlcat@gmail.com

NetCard=wlan0 # the netcard connected to the internet
PingTarget=www.baidu.com	# the ping target, router ip or website, etc: 192.168.1.1, www.baidu.com
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
else
    if ["$LogAll" == "true"]; then
        echo "Network is ok, ret = $ret, $time" | tee -a $LogFile
    fi
fi

exit 0

```

Source: [Github](https://github.com/wxlcat/NetReconnector)  
  
  
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.

---

<div class="post-metadata">

### Author: ![MichaIng](https://dietpi.com/forum/user_avatar/dietpi.com/michaing/32/7_2.png) [@MichaIng](https://dietpi.com/forum/u/MichaIng)
#### Post date: [27 September 2019 09:34 UTC](https://dietpi.com/forum/t/fix-wifi-disconnect/3501/2 "2019-09-27T09:34:20Z")

</div>

vinanrra  
Many thanks for sharing.

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

---

<div class="post-metadata">

### Author: ![vinanrra](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/v/f19dbf/32.png) [@vinanrra](https://dietpi.com/forum/u/vinanrra)
#### Post date: [27 September 2019 20:07 UTC](https://dietpi.com/forum/t/fix-wifi-disconnect/3501/3 "2019-09-27T20:07:35Z")

</div>

Where it is?

It is the option to enable reconnect?

---

<div class="post-metadata">

### Author: ![MichaIng](https://dietpi.com/forum/user_avatar/dietpi.com/michaing/32/7_2.png) [@MichaIng](https://dietpi.com/forum/u/MichaIng)
#### Post date: [11 October 2019 16:06 UTC](https://dietpi.com/forum/t/fix-wifi-disconnect/3501/4 "2019-10-11T16:06:54Z")

</div>

vinanrra  
Jep the “Auto Reconnect” option.
