Search code examples
cordovatcplanmac-address

Cordova - how to TCP connect to MAC address on LAN


I am developing an application using Cordova that will control an ESP32 device from a mobile phone. I have initial contact with the device using the Cordova BLE plugin, when I set the WiFi parameters and retrieve the MAC address of the WiFi device. Later, I would like to no longer use BT communication and communicate directly with the device via LAN. The problem is that I don't know the future IP address of the device. Is there any way in Cordova to create a TCP connection to a known MAC address in the LAN or to perform a LAN scan for all IP / MAC addresses? I could not find any such plugin / function. Of course, there are other solutions - to try to contact all IPs from the range of the connected LAN or to pass the IP address through some web server, but neither of these seem effective to me.


Solution

  • The ESP32 device can set up an mDNS instance so it becomes visible on the LAN. It can include its MAC address in the data. Then your central can find it by service browsing.