Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By rooppoorali
#95903 Yes, there are examples of connecting to an ESP8266 server using a hostname instead of an IP address. One way to do this is by using the mDNS (multicast Domain Name System) protocol, which allows you to resolve hostnames to IP addresses on the local network.

You can use the ESP8266mDNS library to register the ESP8266's hostname on the local network and then connect to it using the hostname instead of the IP address. Here is an example of how to use the library:

Code: Select all#include <ESP8266mDNS.h>

void setup() {
  // Start the Wi-Fi connection
  WiFi.begin("your_SSID", "your_password");
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
  }

  // Start the mDNS responder
  if (MDNS.begin("esp8266")) {
    Serial.println("mDNS responder started");
  } else {
    Serial.println("Error setting up mDNS responder!");
  }
}

void loop() {
  // Your code here
}


Once the ESP8266 is connected to the network, you can use the hostname esp8266.local to connect to it, e.g. ws://esp8266.local:81.

Keep in mind that, the hostname might not be resolved in all Operating System and you need to check it first.

By the way, if you are interested in ESP32 WebSocket server, you can see this:

https://www.theengineeringprojects.com/ ... erver.html