{"id":34,"date":"2013-03-22T19:21:00","date_gmt":"2013-03-22T19:21:00","guid":{"rendered":"https:\/\/www.root42.de\/blog\/?p=34"},"modified":"2013-03-22T19:21:00","modified_gmt":"2013-03-22T19:21:00","slug":"how-to-make-the-raspberry-pi-automatically-restart-the-wifi-interface","status":"publish","type":"post","link":"https:\/\/www.root42.de\/blog\/?p=34","title":{"rendered":"How to make the Raspberry Pi automatically restart the WiFi interface"},"content":{"rendered":"<p>My WiFi router sometimes goes haywire and the Pi won&#8217;t notice when the WiFi connection is up again. So I wrote this little script:<\/p>\n<pre>#!\/bin\/bash                                   <br \/>                                              <br \/>TESTIP=192.168.1.1                            <br \/>                                              <br \/>ping -c4 ${TESTIP} > \/dev\/null                <br \/>                                              <br \/>if [ $? != 0 ]                                <br \/>then                                          <br \/>    logger -t $0 \"WiFi seems down, restarting\"<br \/>    ifdown --force wlan0                      <br \/>    ifup wlan0                                <br \/>else                                         <br \/>    logger -t $0 \"WiFi seems up.\"            <br \/>fi                                                                    <br \/><\/pre>\n<p>You can put this script under <tt>\/usr\/local\/bin<\/tt> and add the following line to the system wide <tt>\/etc\/crontab<\/tt>: <\/p>\n<pre>*\/5 * * * * root \/usr\/local\/bin\/testwifi.sh<br \/><\/pre>\n<p>This will check every five minutes if the connection is still up, and restart it, if the router cannot be pinged. If you dislike all the syslog messages, you can comment them out in the script.<br \/>My corresponding <tt>\/etc\/network\/interfaces<\/tt> looks like this (I uninstalled all the network managers): <\/p>\n<pre><br \/>auto lo                                                                                  <br \/>                                                                                         <br \/>iface lo inet loopback                                                                   <br \/>iface eth0 inet static                                                                   <br \/>        address 192.168.3.42                                                             <br \/>        netmask 255.255.255.0                                                            <br \/>                                                                                         <br \/>auto wlan0                                                                               <br \/>iface wlan0 inet dhcp                                                                    <br \/>      pre-up wpa_supplicant -Dwext -i wlan0 -c \/etc\/wpa_supplicant\/wpa_supplicant.conf -B<br \/>      post-down killall wpa_supplicant ; rmmod 8192cu ; modprobe 8192cu                  <br \/>                                                                                         <br \/>iface default inet dhcp                                                                  <br \/><\/pre>\n<p>The <tt>wpa_supplicant.conf<\/tt> should be easy to generate, there are lots of guides on the web for this.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My WiFi router sometimes goes haywire and the Pi won&#8217;t notice when the WiFi connection is up again. So I wrote this little script: #!\/bin\/bash TESTIP=192.168.1.1 ping -c4 ${TESTIP} > \/dev\/null if [ $? != 0 ] then logger -t $0 &#8220;WiFi seems down, restarting&#8221; ifdown &#8211;force wlan0 ifup wlan0 else logger -t $0 &#8220;WiFi &hellip; <a href=\"https:\/\/www.root42.de\/blog\/?p=34\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to make the Raspberry Pi automatically restart the WiFi interface&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/34"}],"collection":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=34"}],"version-history":[{"count":0,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/34\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}