I have an app which consists of an Android device that processes real time data sent in large packets to it by an esp8266 over wifi. The app also send a few simple commands to the esp from time to time. This all works very well. It has been easy to get the wifi working in various forms using the assistance of this forum, but I am locked in to hard coded parameters.
So now my problem is how to set it all up for real users. Most people using this app will not know the difference between a mac address and a mac feast. I can hardly ask them to enter ssid, password and ip address.
After a lot (lots) of searching and reading I still do not have a definitive idea of the "recipe" to use. Almost all samples use hard coded ssid and other parameters, which is of course useless in production. What is the method typically used?
If I assume the user has a wifi then the esp is a station, and so is the android. This works and I use async streams, but how do I setup the esp in the first instance, ie. when the user first purchases the gizmo with the esp embedded in it. And even then, when the esp is setup, how does the android find it since it is likely to be on a dynamic address. I have tried using host name and that works but every device has a different name since it is composed of part of the mac address.
Or do I run the esp in ap mode and connect the android directly to its private network. Then I seem to be stuck with just a single default gateway.
I just need some direction here. How is this "usually" done?
If someone can point me in the right direction I expect no problems with the coding.
One solution is to use the AP mode on the ESP8266 directly as you suggested but when you do that you will not have internet access on your phone or tablet. I use this in my apps but not with ESP8266 modules, I use other modules. I use this for things like remote control where you want very low latency and you do not need internet access on the phone or tablet while you use your app.
Another is to use the AP mode of the ESP8266 to configure it with your network parameters (the user has to know these) and once the ESP8266 has rebooted and connected to your network, open an unusual port >32768 on the ESP8266 with a function that provides a unique response and in your app, create a search function in your app where you quickly scan all the IP addresses within the range of the router (typically a Class C network) for something that answers on that port with that unique response. When you get the response, you know you found your device.
The problem with that is that your device may not always get the same IP address so it may be irritating to your user if the app does not connect every time and they have to use the search function periodically.
Another solution I have used is to connect the ESP8266 to your router with a fixed IP address, typically an address outside the range used by the router for dynamic addressing, or use an address way up in the range, like 192.168.1.200. But you have to know that this address will not be used by another device. This may work in your home but not be practical in a business setting.
I have also used a registry service with a server on the LAN, like a Raspberry Pi, or even an outside server on the Internet that you own or rent. This is useful if you have many devices connected on one LAN. The Raspberry Pi needs to be at a known address (the outside server could be accessed via DNS), the ESP8266 uses dynamic IP and once connected to your router it sends a message to the Raspberry Pi with its MAC address which allows the Raspberry Pi to create a table connecting the MAC address of the device with its IP address. Your app connects to the Raspberry Pi, downloads the table and the user knows which IP address corresponds to which MAC address. I use that method with data loggers. I have half a dozen devices collecting data throughout my property and they send their data to the Raspberry Pi which runs a web server creating on the fly plots of the data, kinda like ThingSpeak. It has been working well for several years. It is the best method for things like data logging or home automation (the Raspberry Pi can send commands back to the ESP8266 in response to the ESP8266 uploading data), but it is a little more complicated to setup. Once it works, it is pretty foolproof and extremely convenient.
The best way may be to use Wireless Protected Setup but I have not looked if this is supported in the ESP8266 and I am not familiar with it.
I have used all these methods aside from WPS. Bottom line, there is no simple, obvious solution which is why I also uses Bluetooth. It is quite a bit simpler for the end user.
Late addition: following a post from another member, he has a simple way to be able to communicate with an IoT device that uses DHCP and has no way to display its IP address. The device (an ESP8266) is configured to listen to UDP packets on a certain port. The app sends a UDP broadcast message to that port number, the device responds to the UDP broadcast. Very simple to setup, works even if the device uses DHCP and gets a different IP address each time. The only issue is that UDP broadcast only work on the local subnet. For most home applications, it's not a problem but you won't be able to control the lights via the Internet. If you have multiple devices, assign each one a serial number that the app embeds in the UDP broadcast message so that only that device responds. Very simple and requires little setup as long as the device connects to the access point.