-
-
Save GitHeld/1b00a8253490662882074779c6ff10d3 to your computer and use it in GitHub Desktop.
Revisions
-
carry0987 revised this gist
Feb 27, 2024 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,11 +28,10 @@ fi echo 'WiFi check finished' ``` Or you can also use the following command to download the script. ```bash sudo wget https://raw.github.com/carry0987/Raspberry-Pi-Repo/master/Auto-WiFi-Reconnect/wifi-reconnect.sh ``` #### Note: This script uses `/sbin/ip` command for disabling and enabling the wlan interface. This is a more modern approach compared to using `ifconfig` and is the preferred way in newer Linux distributions. -
carry0987 revised this gist
Feb 27, 2024 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Before you start, make sure `ip` command is available on your system. In modern ## Create script file Use ```touch /home/pi/wifi-reconnect.sh``` to create a shell script file, with the following content: ```bash #!/bin/bash SSID=$(/sbin/iwgetid --raw) @@ -29,7 +29,9 @@ echo 'WiFi check finished' ``` Or you can also use ```bash sudo wget https://raw.github.com/carry0987/Raspberry-Pi-Repo/master/Auto-WiFi-Reconnect/wifi-reconnect.sh ``` to download the script. #### Note: -
carry0987 revised this gist
Feb 27, 2024 . 1 changed file with 31 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,27 +1,39 @@ # Auto reconnect to wifi when lost connection Before you start, make sure `ip` command is available on your system. In modern Linux distributions, `ip` replaces older `ifconfig` command. If `net-tools` package (that includes `ifconfig`) is not installed and you prefer using it, you can install it via `sudo apt-get install net-tools`. ## Create script file Use ```touch /home/pi/wifi-reconnect.sh``` to create a shell script file, with the following content: ``` #!/bin/bash SSID=$(/sbin/iwgetid --raw) if [ -z "$SSID" ]; then echo "`date -Is` WiFi interface is down, trying to reconnect" >> /home/pi/wifi-log.txt if command -v /sbin/ip &> /dev/null; then /sbin/ip link set wlan0 down sleep 10 /sbin/ip link set wlan0 up elif command -v sudo ifconfig &> /dev/null; then sudo ifconfig wlan0 down sleep 10 sudo ifconfig wlan0 up else echo "`date -Is` Failed to reconnect: neither /sbin/ip nor ifconfig commands are available" >> /home/pi/wifi-log.txt fi fi echo 'WiFi check finished' ``` Or you can also use ```sudo wget https://raw.github.com/carry0987/Raspberry-Pi-Repo/master/Auto-WiFi-Reconnect/wifi-reconnect.sh``` to download the script. #### Note: This script uses `/sbin/ip` command for disabling and enabling the wlan interface. This is a more modern approach compared to using `ifconfig` and is the preferred way in newer Linux distributions. ## Make new file executable ```sudo chmod +x /home/pi/wifi-reconnect.sh``` @@ -32,17 +44,17 @@ to download the script ## Edit crontab Use ```sudo vim /etc/crontab``` to edit **crontab** By putting the following content at the end of the file: ```* * * * * root /home/pi/wifi-reconnect.sh``` Test it by disconnecting from WiFi: ```/sbin/ip link set wlan0 down``` The script should reestablish the connection within 1 minute. ## Check log file After the RPi reestablishes the connection, reconnect to the RPi and check the log file:<br> ```cat /home/pi/wifi-log.txt```  -
carry0987 revised this gist
Jul 30, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -45,4 +45,4 @@ Script should reestablish connection within 1 minute. ## Check log file After the RPi reestablish connection, reconnect RPi and check log file:<br> ```cat /home/pi/wifi-log.txt```  -
carry0987 revised this gist
Jul 24, 2018 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,6 +19,10 @@ fi echo "WiFi check finished" ``` Or you can also use ```sudo wget https://raw.github.com/carry0987/Raspberry-Pi-Repo/master/Auto-WiFi-Reconnect/wifi-reconnect.sh``` to download the script ## Make new file executable ```sudo chmod +x /home/pi/wifi-reconnect.sh``` -
carry0987 revised this gist
Jul 22, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ echo "WiFi check finished" ``` ## Make new file executable ```sudo chmod +x /home/pi/wifi-reconnect.sh``` ## Install cron ```sudo apt-get install cron``` -
carry0987 renamed this gist
Jul 22, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
carry0987 revised this gist
Jul 21, 2018 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,9 @@ SSID=$(/sbin/iwgetid --raw) if [ -z "$SSID" ] then echo "`date -Is` WiFi interface is down, trying to reconnect" >> /home/pi/wifi-log.txt sudo ifconfig wlan0 down sleep 30 sudo ifconfig wlan0 up fi echo "WiFi check finished" -
carry0987 revised this gist
Jul 21, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,6 +37,6 @@ Test it by disconnecting from WiFi: Script should reestablish connection within 1 minute. ## Check log file After the RPi reestablish connection, reconnect RPi and check log file:<br> ```cat /home/pi/wifi-log.txt```  -
carry0987 revised this gist
Jul 21, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,5 +38,5 @@ Script should reestablish connection within 1 minute. ## Check log file After the RPi reestablish connection, reconnect RPi and check log file: /r```cat /home/pi/wifi-log.txt```  -
carry0987 revised this gist
Jul 21, 2018 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,6 +38,5 @@ Script should reestablish connection within 1 minute. ## Check log file After the RPi reestablish connection, reconnect RPi and check log file: ```cat /home/pi/wifi-log.txt```  -
carry0987 revised this gist
Jul 21, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,5 +38,6 @@ Script should reestablish connection within 1 minute. ## Check log file After the RPi reestablish connection, reconnect RPi and check log file: ```cat /home/pi/wifi-log.txt```  -
carry0987 revised this gist
Jul 21, 2018 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,11 +24,16 @@ echo "WiFi check finished" ```sudo apt-get install cron``` ## Edit crontab Use ```sudo vim /etc/crontab``` to edit **crontab** By putting following content at end of file: ```* * * * * root /home/pi/wifi-reconnect.sh``` Test it by disconnecting from WiFi: ```sudo ifconfig wlan0 down``` Script should reestablish connection within 1 minute. ## Check log file -
carry0987 revised this gist
Jul 21, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Auto reconnect to wifi when lost connect ## Create script file Use ```touch /home/pi/wifi-reconnect.sh``` to create shell script file, with following content: ``` #!/bin/bash -
carry0987 revised this gist
Jul 21, 2018 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,7 @@ # Auto reconnect to wifi when lost connect ## Create script file Use```touch /home/pi/wifi-reconnect.sh```to create shell script file, with following content: ``` #!/bin/bash -
carry0987 revised this gist
Jul 21, 2018 . 1 changed file with 28 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,33 +1,38 @@ # Auto reconnect to wifi when lost connect ## Create script file Shell script: ```touch /home/pi/wifi-reconnect.sh``` with following content: ``` #!/bin/bash SSID=$(/sbin/iwgetid --raw) if [ -z "$SSID" ] then echo "`date -Is` WiFi interface is down, trying to reconnect" >> /home/pi/wifi-log.txt systemctl restart wireless fi echo "WiFi check finished" ``` ## Make new file executable ```chmod +x /home/pi/wifi-reconnect.sh``` ## Install cron ```sudo apt-get install cron``` ## Edit crontab ```sudo vim /etc/crontab``` by putting following content at end of file: ```* * * * * root /home/pi/wifi-reconnect.sh``` Test it by disconnecting from WiFi: ```sudo ifconfig wlan0 down``` Script should reestablish connection within 1 minute. ## Check log file After the RPi reestablish connection, reconnect RPi and check log file: ```cat /home/pi/wifi-log.txt```  -
carry0987 revised this gist
Jul 18, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,4 +30,4 @@ python /home/pi/autowifi.py & ```sudo update-rc.d autowifi.sh defaults``` ## 4. Demo Screenshot  -
carry0987 revised this gist
Jul 18, 2018 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,8 +22,11 @@ python /home/pi/autowifi.py & ## 3. Set Autorun ```sudo cp -f /home/pi/autowifi.sh /etc/init.d/``` ```sudo chmod +x /etc/init.d/autowifi.sh``` ```sudo chown root:root /etc/init.d/autowifi.sh``` ```sudo update-rc.d autowifi.sh defaults``` ## 4. Demo Screenshot -
carry0987 revised this gist
Jul 18, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,4 +27,4 @@ python /home/pi/autowifi.py & ```sudo update-rc.d autowifi.sh defaults``` ## 4. Demo Screenshot  -
carry0987 revised this gist
Jul 18, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,4 +27,4 @@ python /home/pi/autowifi.py & ```sudo update-rc.d autowifi.sh defaults``` ## 4. Demo Screenshot [](https://i.imgur.com/NoVaQcY.png) -
carry0987 created this gist
Jul 18, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ # Auto reconnect to wifi when lost connect ## 1. Python Script Named **autowifi.py** and then put it to **/home/pi** folder ``` #!/usr/bin/python import os, time while True: if '192' not in os.popen('sudo wpa_cli status').read(): print '\n****** wifi is down, restart... ******\n' os.system('sudo ifup wlan0') time.sleep(300) #5 minutes ``` ## 2. Shell Script Named **autowifi.sh** and then put it to **/home/pi** folder ``` #!/bin/sh python /home/pi/autowifi.py & ``` ## 3. Set Autorun ```sudo cp -f /home/pi/autowifi.sh /etc/init.d/``` ```sudo chmod +x /etc/init.d/autowifi.sh``` ```sudo chown root:root /etc/init.d/autowifi.sh``` ```sudo update-rc.d autowifi.sh defaults``` ## 4. Demo Screenshot [Imgur](https://i.imgur.com/NoVaQcY.png)