title: How to configure WIFI connection of IoT device using an Android App
body: <p>Assume that you have an IoT device that only has WLAN connectivity. Now this device should operate using a given WLAN connection. Now the task is to configure the device and tell him which SSID and password to use. Now the question is how to achieve this given that WLAN is the only way of communication. I thought I would be smart to create an Android app that starts a hostspot with credentials know to the IoT device. Under this hotspot it would also serve a REST API where the device could read configuration from.</p>
  <p>Something like: SSID = &quot;MyIOTConfig&quot;, Password = &quot;NotSuperSecret&quot;</p>
  <p>The device would  look for such a WLAN, connect to it and read the real WLAN credentials. So as a user I would open the app, enter the WIFI credentials click a button and then the Android App would start the config HotSpot and spin up a local web server. The IoT would detect the Hotspot and send a request to the REST endpoint and thereby get the credentials of the WIFI.</p>
  <p>No this all sounded great to me until I realized that the methods to create a WIFI hotspot in Android are deprecated and supported for API level &gt;= 26.</p>
  <p>For API level &gt;= 26 I can start a hotspot using <code>startLocalOnlyHotspot</code> but the SSID is hardcoded to something random on the device. So for this purpose this seems completely useless (I generally don't get what purpose it has to start a WIFI with a SSID and password knowbody else knows).</p>
  <p>My question now is, what option do I have with Android to do something like this? What is the intention from Google in Android? What is generally the idea to configure the WLAN credentials on an IoT device that can only talk over WLAN?</p>
  <p>The only thing coming into my mind would be to start and stop this <em>LocalOnlyHotspot</em> in a pattern to communicate the credentials (e.g. send in Morse code by turing the WIFI on and off for short and long time framews). But that's like broadcasting it to everybody once somebody understands the pattern I use. And it sounds like &quot;<a href="https://www.ti.com/lit/wp/swry011a/swry011a.pdf?ts=1611597252258&amp;ref_url=https%253A%252F%252Fwww.google.com%252F" rel="nofollow noreferrer">SmartConfig</a>&quot; , where we share the credentials plain-text, in best case with a shared secret.</p>
  <p>Side question: What is the purpose of <em>LocalOnlyHotspot</em>?</p>