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– MichaelT2019年05月03日 12:33:36 +00:00Commented 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/touroh.dae.su– oh.dae.su2019年05月03日 12:43:26 +00:00Commented May 3, 2019 at 12:43
-
2You could use mDNS.Gerben– Gerben2019年05月03日 12:58:50 +00:00Commented 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.sistemofsis– sistemofsis2019年05月03日 13:26:27 +00:00Commented 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.htmlMatsK– MatsK2019年05月08日 08:30:17 +00:00Commented May 8, 2019 at 8:30
2 Answers 2
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.
-
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– sistemofsis2019年05月04日 15:52:04 +00:00Commented 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.oh.dae.su– oh.dae.su2019年05月05日 09:29:43 +00:00Commented May 5, 2019 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– sistemofsis2019年05月04日 16:09:04 +00:00Commented 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.Majenko– Majenko2019年05月04日 16:12:56 +00:00Commented May 4, 2019 at 16:12
Explore related questions
See similar questions with these tags.