{"id":581,"date":"2017-02-17T20:55:08","date_gmt":"2017-02-17T19:55:08","guid":{"rendered":"http:\/\/hamsterhirn.de\/?p=581"},"modified":"2017-08-24T22:18:44","modified_gmt":"2017-08-24T21:18:44","slug":"raspberry-pi-reset-wireless-lan-to-solve-problems-with-no-connection","status":"publish","type":"post","link":"https:\/\/hamsterhirn.de\/index.php\/2017\/02\/raspberry-pi-reset-wireless-lan-to-solve-problems-with-no-connection\/","title":{"rendered":"Raspberry Pi reset wireless lan to solve problems with no connection"},"content":{"rendered":"<p>I found a script on <a href=\"http:\/\/askubuntu.com\/a\/593589\" target=\"_blank\">http:\/\/askubuntu.com\/a\/593589<\/a> which tried to reset the wlan interface in various ways. I modified that script a little with and installed in on cron and let it execute each minute (*\/1 * * * * \/root\/bin\/resetWifi.sh)<\/p>\n<p>resetWifi.sh:<br \/>\n<pre><code class=\"preserve-code-formatting\">\n#!\/bin\/bash\n# program to check wifi and reset if not running\nif [[ ! -z &quot;$(ps waux | grep $0)&quot; ]]; then exit 0; fi\nexec 2&gt;&amp;1 1&gt; &gt;(tee -a $HOME\/wificheck.log)\nGATEWAY=192.168.1.1\nIWCONFIG_BIN=$(which iwconfig)\nRFKILL_BIN=$(which rfkill)\nPING_BIN=$(which ping)\nDEVICE=$(iwconfig 2&gt;\/dev\/null | grep 802 | awk &#039;{print $1}&#039;)\nfunction isPingWorking {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ${PING_BIN} -c 1 ${GATEWAY} &gt;\/dev\/null 2&gt;&amp;1 ; then\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit 0\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;didn&#039;t work :(&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi\n}\nwhile true; do\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isPingWorking\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Failed, try to reset wifi - sometimes works ok\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;date\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ifdown ${DEVICE}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep 1\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ifup ${DEVICE}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep 10\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isPingWorking\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;turn wlan stick power off... &quot;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${IWCONFIG_BIN} ${DEVICE} txpower off\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep 3\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${IWCONFIG_BIN} ${DEVICE} txpower auto\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isPingWorking\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;use rfkill to reenable wlan stick... &quot;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${RFKILL_BIN} list\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${RFKILL_BIN} block wifi\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep 3\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${RFKILL_BIN} unblock wifi\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isPingWorking\ndone\nexit 0\n<\/code><\/pre><\/p>\n<p>Test if you have rfkill installed. The other bins should be available on most default installations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I found a script on http:\/\/askubuntu.com\/a\/593589 which tried to reset the wlan interface in various ways. I modified that script a little with and installed in on cron and let it execute each minute (*\/1 * * * * \/root\/bin\/resetWifi.sh) resetWifi.sh: #!\/bin\/bash # program to check wifi and reset if not running if [[ ! [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[146,280,283,279,281,276,278,182,147,277,282],"class_list":["post-581","post","type-post","status-publish","format-standard","hentry","category-it","tag-bash","tag-cronjob","tag-interface","tag-iwconfig","tag-raspberry-pi","tag-reset","tag-rfkill","tag-script","tag-shell","tag-wifi","tag-wlan"],"_links":{"self":[{"href":"https:\/\/hamsterhirn.de\/index.php\/wp-json\/wp\/v2\/posts\/581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hamsterhirn.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hamsterhirn.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hamsterhirn.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hamsterhirn.de\/index.php\/wp-json\/wp\/v2\/comments?post=581"}],"version-history":[{"count":5,"href":"https:\/\/hamsterhirn.de\/index.php\/wp-json\/wp\/v2\/posts\/581\/revisions"}],"predecessor-version":[{"id":629,"href":"https:\/\/hamsterhirn.de\/index.php\/wp-json\/wp\/v2\/posts\/581\/revisions\/629"}],"wp:attachment":[{"href":"https:\/\/hamsterhirn.de\/index.php\/wp-json\/wp\/v2\/media?parent=581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hamsterhirn.de\/index.php\/wp-json\/wp\/v2\/categories?post=581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hamsterhirn.de\/index.php\/wp-json\/wp\/v2\/tags?post=581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}