5

I am trying to use my esp8266 to discover several WiFi devices (sensor) in my home. I only know these devices MAC address, and I need to send TCP packets to their IP address. Using RPi, I can do that using ethernet and ARP protocol. But I cannot find similar command in ESP8266. Can you guys enlighten me, ideas about how to get list of devices IP address from router (similar like entering 'arp -a' in Windows )? Or can I directly find a device IP address from their MAC Address?

bonchenko
  • 244
  • 4
  • 8
  • Just to clarify - is it unacceptable for you to add DHCP reservations for your sensonrs in your router and simply access them by their (now known) IP address? – Mishony May 17 '16 at 13:45

3 Answers3

3

Use the inverse ARP protocol. See http://en.wikipedia.org/wiki/Address_Resolution_Protocol#Inverse_ARP_and_Reverse_ARP . I don't know if the module you are using can do this, or if you will have to do this yourself. The basic idea is to send an Ethernet packet to the MAC address in question with the 8 in the OPER field. The device at the other end should respond with the IP address filled in properly and 9 in the OPER field. Also see http://www.networksorcery.com/enp/rfc/rfc2390.txt . This does rely on the device at the other end supporting InARP. If it doesn't, I'm not sure if there is much of anything you can do about it. Another thing you could try is broadcasting ARP requests for each IP in the subnet and hope that you get the response you want.

alex.forencich
  • 40,694
  • 1
  • 68
  • 109
2

This is a general networking question, not limited to any microcontroller.

The reason you can see the arp cache (the mapping between IP and MAC addresses) on your RPi or any other computer is that they've presumably been on for a while, have heard ARP responses from other machines on the network, and have cached them.

Let me rephrase your question: absent any other IP traffic on the network, and knowing the MAC address of another device, how can you find its IP address?

The easy answer is "promiscuously listen to traffic and see what the source IP address is on packets that match the MAC address you are interested in (important safety tip: on 802.* frames, the destination MAC address is sent first, for reasons beyond the scope of this posting).

Otherwise, hand-craft an all-hosts-this-subnet (255.255.255.255) broadcast ICMP ECHO packet and send it to the unicast MAC address of the machine you are interested in. The response will come from the unicast IP address, and you'll now know it.

Of course, if the other machine is running IPv6, you can derive the link-local IP address from the mac address, but you already knew that :)

user301372
  • 61
  • 3
  • Hey, noob here :| what do you mean by "hand-craft an all-hosts-this-subnet (255.255.255.255) broadcast ICMP ECHO packet and send it to the unicast MAC address" ? I tried "ping 255.255.255.255" and "192.168.1.255" but no response (could not find host). Also, I learned that ARP cache is part of the link layer in internet protocol. Does this mean all network enabled devices, including ESP in this case, store ARP cache somewhere in it? – bonchenko May 13 '15 at 02:22
0

I don't know if this is what your looking for but have you tried looking at the AT commands for the ESP8266? I found a list of them here.

I used one of these modules with a Freescale K64F dev board and communicated with it over UART sending those AT commands to set it up as a server and served up a web page. If you go this route and the devices connect to it while it is in server mode, I think you can use the AT+CWLIF and you can get the connected devices information.

But it doesn't sound like your using it like this.

One other thing I can warn about is that if you monitor the UART line, if you see the "vendor" come up, the chip most likely reset. It draws a bit of current when transmitting.

Jesse
  • 143
  • 1
  • 1
  • 5
  • Isnt that used when ESP is in AP mode? To get list of devices connected to ESP? Currently my ESP is AP client, connected to a router. I need to discover the ip address of other devices that are connected to the router, based on their MAC address – bonchenko May 13 '15 at 01:54