-1

What I am trying to do is make an Android App for my NodeMCU so that I can send data via Websockets and not use the browser. I don't want the end user to be inputting any IP addresses to look for the NodeMCU in the network. I understand that you can set a hostname for NodeMCU.

Is there any way I can get the IP of the NodeMCU in the network using its hostname and then further communicate over it?

  • What kind of server is running on the NodeMCU? With a fixed port? – blackapps Dec 01 '21 at 05:24
  • The port will be fixed....so far ive been using port 81 for the websocket and port 80 for viewing the webserver. Yes the ESP will be running as a webserver – Rupava Baruah Dec 01 '21 at 06:31
  • Does this answer your question? [Discover devices (esp8266/arduino) on same LAN subnet](https://stackoverflow.com/questions/53016419/discover-devices-esp8266-arduino-on-same-lan-subnet) – gre_gor Dec 02 '21 at 05:11
  • this is not a question. – narcis dpr Dec 08 '21 at 05:57

1 Answers1

-1

You can find ip of server without using its hostname.

Both devices run in the same -wifi- network.

The Android client knows its ip. Say 192.168.2.12.

Now it knows that the ip of the server will be like 192.168.2.##.

Just make a loop where you use a Socket that tries to connect using ip's around the one of the client.

Set a socket time out of two seconds or less.

blackapps
  • 8,011
  • 2
  • 11
  • 25
  • That's a bad solution. The network could also be 192.168.##.##. And even just checking 256 IPs with 2 sec timeout, would be 8.5 min. – gre_gor Dec 02 '21 at 05:06
  • Maybe. But here we need only few seconds as the network is a i described and ip addresses are next to each other. @gre_gor. I use it too while travelleng and devices come in guest networks. Always worked. – blackapps Dec 02 '21 at 05:30
  • @gre_gor: you can open multiple connections to scan, at least 4, maybe 8, so it need not take as long as doing it one at a time. – dandavis Dec 06 '21 at 21:34