Reputation: 177
I am developing a small-scale hobby project which involves an Android app and an ESP8266. The basic idea is, the ESP8266 will control an RGB led and the app will let me do this control remotely.
In my architecture, the ESP8266 will be connected to my home network and when my smartphone is connected to the same network, when I open the app the phone and the ESP8266 will pair and I will do the control over wifi. But the IP address of the ESP will change dynamically. My question is, how can I find out the IP address of the ESP8266 if it's not static?
Upvotes: 0
Views: 937
Reputation: 6462
This is what multicast was designed to do. Have your device listen on a particular multicast group, and your phone can send a message to the multicast group, then the device will respond via unicast to your phone. You phone will then have the unicast address of the device. In general, you want to use a multicast group in the Organization-Local Scope (239.0.0.0/8
) range.
Upvotes: 1
Reputation: 11224
Just try them all.
On the Android device you first determine the ip of the device itself.
Say its 192.168.1.5
.
You will then know that the ip of the esp is like that. Like 192.168.1.xx
.
So just make a loop where you start with 192.168.1.3 and try to connect to it using your port. Set timeout to one second. If it times out try the next ip. Skip your own ip.
You will be amazed how quick the esp is found.
Upvotes: 1