Martin's corner on the web

Auto reconnect WiFi on Raspberry Pi

For a number of reasons I have my DD-WRT-based router shut down WiFi at nights, that though causes some inconvenience to my Raspberry Pi.  I have it connected with a RTL8188CUS based WiFi dongle, the cheapest found on eBay. The problem is that it won’t re-connect by itself when WiFi drops and I find my Raspberry Pi without Internet connection at mornings. I have to physically unplug and then plug the dongle back to get it working. Luckily I am not the only one in this situation and found that a guy named Kevin Reed already created a script that would take care of the this. It didn’t work straight out for me, I had to do some modifications, my modified version is available on Github. So I created a cron job to run the script every minute and all works nicely now. Instructions on how to set it up are in the script itself.IMG_2079

6 thoughts on “Auto reconnect WiFi on Raspberry Pi

  1. Gazza

    I hadmy pi logging temp/humidity at my girlfriends place and had exactly the same problem! My girlfriennds router had a random reboot problem and it was a pita to have to go and reboot the pi (I don’t live with her) or ask her to do it. She went home for the hols so I sat outside in a car, hanging off the wifi on my blackbberry, and wrote a script to test&reconnect the wifi using the nm-cli and running every 5minutes via cron. This while eating a bucket of kfc with a mate haha.
    I was impressed when it worked!

  2. Paul

    Thanks a lot for that one. Had 3 Pi’s running solid as a rock for days in the house and then in the last week, overnight they would all die. Just solid red light on the Pi’s/ Only thing I could see was “Link Beat Lost” in syslog. Which brought me to your page.

    Then realised when I was in none-Pi mode, I had in the last few days put a restart on my access point each day at 4am – clearing out a VPN tunnel. Dummy!!!

    Hoping your script will kick in when the WiFi is out and keep the PI’s up and running.

    Still seems strange to me that the lack of WiFi causes the Pi to completely shutdown.

    Tomorrow will tell – Thanks a lot for your script.