I'm going to create an IoT system. I use a Raspberry Pi as a MQTT broker and as a webserver. Every day, the Pi gets a new IP address, so I need to find its new IP address via ESP8266 to use this information in my code. I know that I can use a fixed IP, but I don't want to, so it is better if I can find a solution.

  • What is the question you are asking? – MichaelT May 3 '19 at 12:33
  • Welcome to the Arduino stackexchange. Please be sure to take the tour, to know, how things are working here: arduino.stackexchange.com/tour – oh.dae.su May 3 '19 at 12:43
  • 2
    You could use mDNS. – Gerben May 3 '19 at 12:58
  • There was some problem in the libraries that i tried, i'm trying to solve it via Pinging now. – sistemofsis May 3 '19 at 13:26
  • As @Gerben say use multicast DNS aka AVAHI, it is even supported on ESP's ref.: tttapa.github.io/ESP8266/Chap08%20-%20mDNS.html – MatsK May 8 '19 at 8:30

First of all, if your Raspberry Pi acts as webserver and mqtt broker, in my opinion you should assign a fixed ip-address, either via configuration in the access point/router or via static ip.

However, if you insist on your approach you could do some hands-on method of pinging all addresses in your LAN-subnet and checking for the MAC-address of the respondents.
If the MAC-address matches to that of your Pi, you have found it.

I have not tested it myself, but this library seems to have what you need for this purpose.
After finding a responsive ip-address via ping, it tries to resolve the corresponding MAC-address using the etharp_find_addr function.

This struct field is the reference to a 6 byte character array that you can use for comparing with the Raspberry Pi's MAC address:


If you only want to find the IP address of the Raspberry Pi, using mDNS as suggested by @Majenko is the superior choice.
If you are looking for all devices in your LAN, as your title suggests, pinging makes more sense.

  • I had a Lib problem, now i fixed it and i really close to get the result. In the loop, i send all of the ip addresses that i want and the mac adresses are shown in pinger.OnEnd([](const PingerResponse& response) function. I wrote a function for convert response.DestMacAddress->addr to String. mac = mac2String(response.DestMacAddress->addr); I would like to have it on my setup function for create a list. But i can't. Could you please help me? – sistemofsis May 4 '19 at 15:52
  • I am sorry, but I cannot follow your explanation. I guess it would be best, if you ask a separate question on Stack Overflow for this programming issue. Then you can layout all your code, your results/error messages and what you expect from the program. Then feel free to link to this question. – oh.dae.su May 5 '19 at 9:29

You should use mDNS. Install (if it isn't already) avahi-daemon on your Raspberry.

Then check out the ESP8266mDNS library and the examples it has. Especially the mDNS-SD_Extended example, which performs a query for a service on the network.

  • I need also some other devices' ips. That's why mDNS does't work. – sistemofsis May 4 '19 at 16:09
  • Make those use mDNS as well, then. Either that or redefine your expectations and requirements and embrace the static IP address. – Majenko May 4 '19 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.