Search code examples
androidarduinoesp8266mac-addressnodemcu

How to get MAC addresses of all nearby devices in Android


Can anyone tell me how to find the MAC address of all devices nearby in Android, programmatically?

I am trying to design an Android app that is able to communicate data using broadcast messages via MAC address, to an Arduino microcontroller (ESP8266). I would like the data communication between the two devices not to be tied to the connection (WiFi or Bluetooth). Therefore, I add to my initial question, if there are further ways of communication between Android and Arduino without connection.


Solution

  • This looks like an example of what you're trying to achieve (not mine): https://github.com/rorist/android-network-discovery/blob/master/src/info/lamatricexiste/network/DnsDiscovery.java

    Your second question is kinda badly worded I think.

    1. Broadcast: "broadcasting is a method of transferring a message to all recipients simultaneously". Are you trying to send a message to all the ESP8266 (note that an ESP is not an Arduino) ? If so, use the dedicated broadcast address: which is all 1 on the host part of your IP address. So on a local network it would be 192.168.x.255.

    2. You could communicate via MAC address but this seems very inefficient. If you absolutely want to do it you have to dig into the lower layers of the TCP/IP stack (or other stack that uses the MAC address).

    3. There is no way to communicate without a medium. You either need a wired or a wireless connection. Maybe you are referring to a the 'connectionless' way of sending packets like UDP. With UDP you can send a packet to your ESP without previous handshake (but you still need a medium: wifi or ethernet).