Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finding ESP when connected to any network. #7

Open
ajinkyaw opened this issue Jun 21, 2018 · 6 comments
Open

Finding ESP when connected to any network. #7

ajinkyaw opened this issue Jun 21, 2018 · 6 comments

Comments

@ajinkyaw
Copy link

Hi Guys i have developed a program for esp8266 to connect to any wifi station by providing SSID and password. I am using mDNS to find the device when its in AP Mode. but when in STA mode i cannot find it with the mDNS.
I am using websocket to communicate with the device , but here i need to know the IP address of the esp and then i can communicate with it.
What i want to achieve here is , I want to access the esp without knowing its IP address when it is connected to the network i am in. Also i cannot set a static ip address to the esp in my case.

What are the techniques to do so , please guide.

@reivaxy
Copy link

reivaxy commented Jun 21, 2018

Hi,
Would printing the IP to the serial port do ?

Here is what you could do:

wifiSTAGotIpHandler = WiFi.onStationModeGotIP(onSTAGotIP);

void onSTAGotIP (WiFiEventStationModeGotIP ipInfo) {
ipOnHomeSsid = ipInfo.ip.toString();
Serial.printf("Got IP on %s: %s\n", config->getHomeSsid(), ipOnHomeSsid.c_str());
}

Otherwise if the ESP is both STA and AP, you could have the AP provide a small webpage on its IP (since you said you know it) and serve it to display the STA ip.

You could also attach a screen and display the IP address on it :)

@ajinkyaw
Copy link
Author

ajinkyaw commented Jun 21, 2018 via email

@reivaxy
Copy link

reivaxy commented Jun 21, 2018

Well, you could do an ip scan :(

Do you know its Mac address ?

@ajinkyaw
Copy link
Author

ajinkyaw commented Jun 21, 2018

@reivaxy : Every time scanning the IP will be the option i can consider, but still looking for more suitable way to make it work.
is the mac address of the esp fix ? does it change ever? so that i will try to find the solution to get the ipaddress from mac address.
Can we find it in a desktop app developed in c# ?

@gilmaimon
Copy link

gilmaimon commented Oct 6, 2018

You could have a third endpoint (like an AWS server) with a fixed ip. So that when the esp wakes up it will "register" it's local ip on that server (with some unique id you will hardcode, in case that you have multiple devices).
EDIT: also, for me mDNS works fine on STA mode.. Maybe you are accessing it the wrong way? maybe from a client that does not support it?

@reivaxy
Copy link

reivaxy commented Oct 6, 2018

Absolutely @gilmaimon, I have done a similar thing on https://github.com/reivaxy/iotinator.

After the master ESP8266 connects to my home SSID using DHCP, it POSTs its IP address to www.iotinator.com where I have set up a mySql database and some php scripts (from the same repo) to record it.

Then, querying HTTP GET my.iotinator.com will return the IP of all the modules connected to the same network as the gateway used by the querying client. If there is only one, the response is a redirect to that IP.
So I no longer need to know the IP of my ESP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants