|
| 1 | +# Bootwifi |
| 2 | +It is common to want to start an ESP32 and have it connect to a WiFi environment but how |
| 3 | +does one bootstrap it? To connect to a WiFi environment, we typically need to know the |
| 4 | +SSID and password of the network to which we wish to connect. But without network connection |
| 5 | +to the ESP32, how do we set it? This component provides a potential solution. |
| 6 | + |
| 7 | +The module exposes a function called `bootwifi` which, when called, will own the connection |
| 8 | +of the device to the local WiFi environment. To do this, it looks in its flash storage to see |
| 9 | +if it has previously been given an SSID/password pair. If it has, it attempts to connect to that |
| 10 | +access point and join the network. |
| 11 | + |
| 12 | +However, let us assume that it has never been given that information. In this case it will become |
| 13 | +an access point in its own right. Now you can connect to the ESP32 using your phone or other WiFi |
| 14 | +device as it will appear as an access point against which we can connect. Once connected, we can |
| 15 | +open a browser to it. In the browser page, we will be prompted for the SSID and password we wish |
| 16 | +to subsequently use. This will be saved and used from then on. Now the device will connect to that |
| 17 | +network. |
| 18 | + |
| 19 | +What if we take our ESP32 to a new environment where the previously saved access point is no longer |
| 20 | +accessible or we simply just fail to connect? Again, we will fall back into being an access point |
| 21 | +and the user will be able to supply new information. |
| 22 | + |
| 23 | +What if we want to change the access point to which the ESP32 connects even if that access point has |
| 24 | +been previously saved and is still connectable? Simple, the ESP32 can check a GPIO pin at startup and, |
| 25 | +if that pin is high (default low) then that can be used as a manual indication that we should become |
| 26 | +an access point without even attempting to connect to the network. |
| 27 | + |
| 28 | +This code is supplied in the form of an ESP-IDF module. It depends on a partner module called `mongoose` |
| 29 | +that provides a Web Server in order to server up the web pages. A build of `mongoose` is available |
| 30 | +however, [Cesanta](https://www.cesanta.com/), the makers of Mongoose are still working on a formal |
| 31 | +port to the ESP32 which is anticipated to be available before 2017 so we should really wait for that |
| 32 | +to become available. |
| 33 | + |
| 34 | +##Future enhancements |
| 35 | +There is always room for enhancements: |
| 36 | + |
| 37 | +* Improve the web page shown to the user - Right now it is pretty basic and ideally could be |
| 38 | +dramatically improved. Features to be added include |
| 39 | + - listing of available access points for selection |
| 40 | + - Responsive visuals for better reading/styling on mobile devices |
| 41 | +* Integrate SSL security. |
| 42 | +* Configuration of GPIO pin to use (if any) for GPIO over-ride |
| 43 | +* NeoPixel support for visualization of connection status: |
| 44 | + - Green - connected |
| 45 | + - Blue - being an access point |
| 46 | + - Red - Connecting |
| 47 | + - Flashing red - failed |
| 48 | +* Ability to specify an IP address for static IP address connection to the access point. |
| 49 | +* mDNS support when available. |
| 50 | +* Component configuration options including: |
| 51 | + - Network SSID to use when being an access point. |
| 52 | + - Network password to use when being an access point (if any). |
0 commit comments