Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By sambosykes
#74058 Hi - my first post to this fab forum.

This is a question about ARP with the esp8266. I realise this might be a fairly low-level question (i.e. not that normal), 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 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 known, I get the index of the result and the associated MAC address.

Code: Select all// 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: Select all// 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);

......

Exception (28):
epc1=0x4000df2f epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000033 depc=0x00000000

ctx: cont
sp: 3fff1ff0 end: 3fff2230 offset: 01a0

>>>stack>>>
3fff2190:  3f202020 00000000 00000000 00000000
3fff21a0:  4024545b 00000033 3fff1148 40245439
3fff21b0:  00000004 3fff21e0 00000000 00000001
3fff21c0:  6101a8c0 00ffffff fe01a8c0 3fff1208
3fff21d0:  3fffdad0 00000000 3fff1148 4020fa6b
3fff21e0:  6f00a8c0 6101a8c0 3fff1148 40206bb4
3fff21f0:  3fffdad0 3fff0e4c 3fff1148 40211717
3fff2200:  3fffdad0 00000000 3fff1200 4021252d
3fff2210:  3fffdad0 00000000 3fff1200 40208770
3fff2220:  feefeffe feefeffe 3fff1210 4020994c
<<<stack<<<

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.