Chat here about code rewrites, mods, etc... with respect to the github project https://github.com/esp8266/Arduino

Moderator: igrr

User avatar
By Rodrigo Miranda
#47162 Hi, how are you?
I am trying to develop a chat between 2 nodeMCU's.
So far I've been able to communicate between them in my home network because I know both of the ip address.
The thing is that I need to do the following sequence:
First: The client nodeMCU connects to the server nodeMCU via the server's AP (server is working in dual mode, AP_STA). At this point since the client connected to the AP the server can have a fixed ip address previously set. So no problem until here.
Second: The client (which can be connected to the pc to upload the following info) sends the home network information to the server (SSID and pass). Once this is done the server can stay connected to the home network
Third: Now the client disconnects from the server's AP and connects to the home network. but there is a problem, it does not know the ip address of the server in the home network, since the router may change it dynamically.

Setting a static ip is not an option.
Can I search for all the devices connected in the network and maybe check if any of them has the same MAC as the server nodemcu and then connect to that ip? Or maybe something like that. I am kind of stuck here, I will appreciate any help!
User avatar
By Rodrigo Miranda
#47212
martinayotte wrote:Simply use mDNS library, it will advertise the module itself on your network as "MyESP123" for example.

Thanks you a lot for the help, I will look into it asap!
By the way, is that the way it is usually done? For example in those commercial electronic products such as wifi led spotlights... I mean, not the library itself but the way the library works (I am a newbie in networking so I am not aware of these procedures).
Regards
User avatar
By lethe
#47259
Rodrigo Miranda wrote:By the way, is that the way it is usually done? For example in those commercial electronic products such as wifi led spotlights...

There's no standard method, there are several, each with their own advantages & drawbacks...
mDNS is a popular & standardized method, but has probably more overhead than others (needs additional UDP socket).
An alternative would be to implement custom UDP broadcast/multicast messages. If you are using UDP anyway, you can get away with only using a single socket for everything.
Some manufacturers only communicate through a cloud server (with the obvious disadvantage of your device being as useful as a paperweight without internet access, but with internet it works world-wide).