ESP8266 Developer Zone The Official ESP8266 Forum 2018-02-20T16:56:40+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=9236 2018-02-20T16:56:40+08:00 2018-02-20T16:56:40+08:00 https://bbs.espressif.com:443/viewtopic.php?t=9236&p=19423#p19423 <![CDATA[ARP request using etharp_request() - exception]]>
This is a question about ARP with the esp8266. I realise this might be a fairly low-level SDK question, so I will explain a little about what I am trying to achieve.

If we assume that I have a known MAC address or IP address, I would like to know if the device in question is connected to the network. The ESP8266 is in STATION mode, so the device might be on WiFi or might be on Ethernet, but that should not matter. I am using an ESP07 and Arduino SDK / platform.

My understanding is that the ARP table in the ESP needs to have sent/received a packet from a device for the MAC and IP pair to be stored. If I do an ARP lookup for a known IP address using etharp_find_addr(STATION_IF, &_ip, &_arp_mac, &_arp_ip), then assuming the device is know, I get the index of the result and the associated MAC address.

Code:

// search ARP records for IP
int8_t result = etharp_find_addr(STATION_IF, &_ip, &_arp_mac, &_arp_ip)


One way I get traffic to be 'seen' is to do a ping to the device (using the in-built ping.h) - it seems to help considerably in the accuracy of the result. In fact, if I do not do a ping, then I get no results most of the time. I think this follows the theory that the ARP table is only populated when traffic to the IP/MAC is seen. All good so far.

However, not all devices respond to a ping (if they are dormant, etc.), so this is not always reliable. Pretty reliable, but not bullet-proof.

Other tools for desktop systems can use ARP to force a request to the network / device to get a reply. Using such tools gives a much more reliable answer to the question "is device with IP address active?". There appears to be some functionality within etharp.h, but if I even think about using them, such as etharp_request(STATION_IF, &_ip), then I get an exception and the ESP reboots.

Code:

// test IP address
ip_addr_t test_ip;
IP4_ADDR(&test_ip, 192,168,0,111);

// do a search
int8_t result = etharp_request(STATION_IF, &test_ip);


I have searched long and hard on this forum and also on Google for answers to this, but have failed dismally. Does anyone have a clue (or even better, some working sample code) that can help me do what I am after?

Many thanks.

Statistics: Posted by branchespark — Tue Feb 20, 2018 4:56 pm


]]>