Editing
esp
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===mDNS=== DNS works great for normal sites on the Internet, but most local networks don't have their own DNS server. This means that you can't reach local devices using a domain name, and you're stuck using IP addresses.<br> <br> Fortunately, there's another way: multicast DNS, or mDNS.<br> '''mDNS''' uses domain names with the .local suffix, for example ''http://esp8266.local''. If your computer needs to send a request to a domain name that ends in .local, it will send a multicast query to all other devices on the LAN that support mDNS, asking the device with that specific domain name to identify itself. The device with the right name will then respond with another multicast and send its IP address. Now that your computer knows the IP address of the device, it can send normal requests.<br> <br> Luckily for us, the ESP8266 Arduino Core supports mDNS:<br> <nowiki>#include <ESP8266WiFi.h> // Include the Wi-Fi library #include <ESP8266WiFiMulti.h> // Include the Wi-Fi-Multi library #include <ESP8266mDNS.h> // Include the mDNS library ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti' void setup() { Serial.begin(115200); // Start the Serial communication to send messages to the computer delay(10); Serial.println('\n'); wifiMulti.addAP("ssid_from_AP_1", "your_password_for_AP_1"); // add Wi-Fi networks you want to connect to wifiMulti.addAP("ssid_from_AP_2", "your_password_for_AP_2"); wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3"); Serial.println("Connecting ..."); int i = 0; while (wifiMulti.run() != WL_CONNECTED) { // Wait for the Wi-Fi to connect: scan for Wi-Fi networks, and connect to the strongest of the networks above delay(1000); Serial.print(++i); Serial.print(' '); } Serial.println('\n'); Serial.print("Connected to "); Serial.println(WiFi.SSID()); // Tell us what network we're connected to Serial.print("IP address:\t"); Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer if (!MDNS.begin("esp8266")) { // Start the mDNS responder for esp8266.local Serial.println("Error setting up MDNS responder!"); } Serial.println("mDNS responder started"); } void loop() { }</nowiki> <br> Upload it and ping to esp8266.local<br> {{template:top}}
Summary:
Please note that all contributions to Notebook may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Notebook:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Home Page
C++ Reference
ESP Hardware
ESPHome
Home Assistant
Network Stuff
Tools
What links here
Related changes
Special pages
Page information