1

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.

The Guy with The Hat
5,2927 gold badges30 silver badges51 bronze badges
asked May 3, 2019 at 11:55
5
  • What is the question you are asking? Commented May 3, 2019 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 Commented May 3, 2019 at 12:43
  • 2
    You could use mDNS. Commented May 3, 2019 at 12:58
  • There was some problem in the libraries that i tried, i'm trying to solve it via Pinging now. Commented May 3, 2019 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 Commented May 8, 2019 at 8:30

2 Answers 2

-1

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:

response.DestMacAddress->addr

Update:
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.

answered May 3, 2019 at 12:19
2
  • 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? Commented May 4, 2019 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. Commented May 5, 2019 at 9:29
1

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.

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.