I want to control relays using Arduino and ESP8266 with Android application.
My requirements are as follows:
1)No hard coding of WiFi Credentials(I tried this with WiFiManager library by Tzapu and APConnect and it worked well until connecting the esp to WiFi network after which I was unable to access the esp)
2)I want to access the ESP through the Android application in order to give the commands related to on/off status of relays. (Here I failed to fix a static IP to esp using WiFiManager. Also I don't want to go by the method of WiFi Router configuring or port forwarding or using any external broker as long as possible )
Please tell me how can I get the dynamic IP assigned to ESP in the Android application so that i can access the same.
Can you clarify if you want (case 1) a static IP address to be given to your ESP from an Android app, or if you want (case 2) your ESP to acquire a dynamic IP address (most likely from a DHCP service you have in your router at home when joining such network) ?
By definition in the first case if the arduino/esp does not have an address, then it’s not registered on your network and your Android app cannot talk to it
In the second case, your challenge is that you don’t know what is the dynamic IP address of your ESP and so your Android app does not know where to connect
If you are in case 1, then usually their would be a setup mode in your application where the ESP sets itself up in access point mode and create its own wireless network you can join. The process is to join that network from your android phone, connect to a web page hosted on the ESP, fill up some parameters that will be saved in a permanent space on the ESP (for example in SPIFFS) and then reboot the ESP in normal mode, were it will read the saved config and sets up a static IP as per your definition
In second case you need to read about broadcast messages for example or zero conf / bonjour type of approach to implement a discovery process in your Android app.
Remember that giving an IP address to a device in a network is usual you the role of the DHCP service of the router though, so the best place to define this would actually be within the router interface —> find the MAC address of your device and define the associated IP you want to reserve statically, and pick something outside the DHCP reallocation range.
Also if your Android app hand over a stupid IP address that is already being used by some other device on your network, then it’s a recipe for network troubles...
Last - if you have Bluetooth available as well on the arduino side, then you can use BT for configuration of the IP stack. BTLE offers service discovery capabilities.