{"id":41,"date":"2014-10-24T03:55:23","date_gmt":"2014-10-24T03:55:23","guid":{"rendered":"http:\/\/www.beer.org\/beerblog\/?p=41"},"modified":"2015-12-30T03:55:54","modified_gmt":"2015-12-30T03:55:54","slug":"how-to-auto-start-wifi-hotspot-on-android-4-4-4","status":"publish","type":"post","link":"https:\/\/www.beer.org\/blog\/index.php\/2014\/10\/24\/how-to-auto-start-wifi-hotspot-on-android-4-4-4\/","title":{"rendered":"How to auto start Wifi hotspot on Android 4.4.4"},"content":{"rendered":"<header>\n<h1 class=\"entry-title\"><a title=\"Permalink to How to auto start Wifi hotspot on Android 4.4.4\" href=\"https:\/\/www.beer.org\/blog\/how-to-auto-start-wifi-hotspot-on-android-444.html\" rel=\"bookmark\">How to auto start Wifi hotspot on Android 4.4.4<\/a><\/h1>\n<\/header>\n<div class=\"entry-content\">\n<footer class=\"post-info\"><abbr class=\"published\" title=\"2014-10-24T06:12:38\"> Published: Fri 24 October 2014 <\/abbr><\/p>\n<address class=\"vcard author\">By <a class=\"url fn\" href=\"https:\/\/www.beer.org\/blog\/author\/herb-peyerl.html\">Herb Peyerl<\/a><\/address>\n<p>In <a href=\"https:\/\/www.beer.org\/blog\/category\/tech-stuff.html\">Tech Stuff<\/a>.<\/p>\n<\/footer>\n<p>I got a broken Nexus-7 and wanted to use it as a router up at DebtRidge. I wanted it to come up as a wifi hotspot automatically when booted. This means the &#8216;hostapd&#8217; daemon needs to be started automatically. So here&#8217;s what I did.<\/p>\n<ul>\n<li>Unlock the bootloader<\/li>\n<li>Root the tablet and install SuperSU<\/li>\n<li>install busybox<\/li>\n<li>install <a href=\"http:\/\/www.theandroidhow.com\/2014\/06\/how-to-enable-initd-support-on-android.html\">init.d<\/a><\/li>\n<\/ul>\n<p>The above is outside the scope of this article. There&#8217;s already lots of fine articles that tell you how to do all that.<\/p>\n<p>Once you can get a terminal prompt or adb shell and su, you can proceed.<\/p>\n<ul>\n<li>setup the Wifi hotspot in Settings. This will generate a file called \/data\/misc\/wifi\/hostapd.conf. It looks something like this:<\/li>\n<\/ul>\n<pre>interface=wlan0\r\ndriver=nl80211\r\nctrl_interface=\/data\/misc\/wifi\/hostapd\r\nssid=drgate\r\nchannel=6\r\nieee80211n=1\r\nhw_mode=g\r\nignore_broadcast_ssid=0\r\nwpa=2\r\nrsn_pairwise=CCMP\r\nwpa_psk=115dfdf3a3c63c3692b5cfaf0ad73234e89a1e7b70037fd5cfcdcd2d608a6bc9\r\n<\/pre>\n<p>Since init.d is run in \/data\/install-recovery-2.sh, it runs too early in the boot process for hostapd to start. Another issue is that hostapd won&#8217;t run if Wifi is enabled. However, if Wifi hasn&#8217;t been enabled, the wlan driver isn&#8217;t loaded and hostapd isn&#8217;t able to bind to wlan0 because it doesn&#8217;t exist. So I had to find a way to load the wifi drivers so that hostapd would come up.<\/p>\n<p>I discovered that I can run &#8220;svc wifi enable&#8221; to install the drivers and bring up the wlan0 interface. Then &#8220;svc wifi disable&#8221; would bring down the wlan0 interface but leave the drivers installed. At this point, hostapd was perfectly happy.<\/p>\n<p>So to bring this all together, I needed a script that could be launched at boot time that would delay the starting to hostapd until later in the boot process. Here&#8217;s what I did.<\/p>\n<pre>su\r\nmount -o rw,remount \/system\r\ncd \/system\/etc\/init.d\r\ncat &gt; 50hostapd\r\n#!\/system\/bin\/sh\r\n\/data\/start_hostapd.sh &amp;\r\n^D\r\nchmod 755 50hostapd\r\n<\/pre>\n<p>Now install the following script as \/data\/start_hostapd.sh:<\/p>\n<pre>#!\/system\/bin\/sh\r\nwhile true; do\r\n    su -c svc wifi enable\r\n    sleep 1\r\n    netcfg | grep wlan0 &amp;&amp; break\r\n    sleep 10\r\ndone\r\nsu -c svc wifi disable\r\nsleep 2\r\n\/system\/bin\/hostapd -e \/data\/misc\/wifi\/entropy.bin \/data\/misc\/wifi\/hostapd.conf &amp;\r\n<\/pre>\n<p>Then:<\/p>\n<pre>chmod 755 \/data\/start_hostapd.sh\r\n<\/pre>\n<p>and you should be good to go.<\/p>\n<pre>root@deb:\/ # ps | grep hostapd\r\nwifi      1282  1     2416   1000  c0138fe4 b6ee46d8 S \/system\/bin\/hostapd\r\n<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>How to auto start Wifi hotspot on Android 4.4.4 Published: Fri 24 October 2014 By Herb Peyerl In Tech Stuff. I got a broken Nexus-7 and wanted to use it as a router up at DebtRidge. I wanted it to come up as a wifi hotspot automatically when booted. This means the &#8216;hostapd&#8217; daemon needs&#8230; <a class=\"moretag\" href=\"https:\/\/www.beer.org\/blog\/index.php\/2014\/10\/24\/how-to-auto-start-wifi-hotspot-on-android-4-4-4\/\">Continue reading &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-41","post","type-post","status-publish","format-standard","hentry","category-tech-stuff"],"_links":{"self":[{"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/41","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":2,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":43,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/41\/revisions\/43"}],"wp:attachment":[{"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}