0

Is there any way in the ESP8266 code to ask the router for a specific IP? I mean, in the following example (which I copied from the web), it gets "192.168.1.3". The part "3" is automatically assigned, and may change next time. I want this number to be a specific number. I know I can modify the router setting to add a static IP, but at least for my router, adding a static IP is slow and inconvenient. And I may swap the ESP8266 board and run the same code. The router is mine, and used only by me, so if I need to change some settings of the router to grant this kind of request from the client, I can do that.

If there is no such feature, can I make the ESP8266 discoverable by a specific name (again, without creating a translation entry in the router settings, but within the ESP code)? For example, if the ESP8266 runs a web server, can I make the web server accessible by something like "http://myserver1" instead of "http://192.168.1.3"?

#include <ESP8266WiFi.h>        // Include the Wi-Fi library

const char* ssid     = "SSID";         // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "PASSWORD";     // The password of the Wi-Fi network

void setup() {
  Serial.begin(115200);         // Start the Serial communication to send messages to the computer
  delay(10);
  Serial.println('\n');
  
  WiFi.begin(ssid, password);             // Connect to the network
  Serial.print("Connecting to ");
  Serial.print(ssid); Serial.println(" ...");

  int i = 0;
  while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
    delay(1000);
    Serial.print(++i); Serial.print(' ');
  }

  Serial.println('\n');
  Serial.println("Connection established!");  
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());         // Send the IP address of the ESP8266 to the computer
}
5
  • Have you tried this: randomnerdtutorials.com/… ? Commented Sep 12, 2021 at 7:35
  • you can reserve the IP on the DHCP server in you router's configuration Commented Sep 12, 2021 at 8:31
  • While using a static IP address comes at the cost of flexibility it also speeds up the handshake process between your ESP8266 and the AP. If you use a static IP on the ESP8266 you have to make sure it's from a range that you reserved on the AP as NOT being available for DHCP. As for name resolution you may want to look into mDNS. There are examples at github.com/esp8266/Arduino/tree/master/libraries/ESP8266mDNS/… Commented Sep 13, 2021 at 6:32
  • @MarcelStör have you used this mDNS library? Do you know what exactly it can be use for? Commented Sep 13, 2021 at 13:36
  • Yes, I have. en.wikipedia.org/wiki/Multicast_DNS Commented Sep 14, 2021 at 6:07

1 Answer 1

0

Almost all routers have DHCP Server. What you can do is create a DHCP Reservation for your ESP8266s MAC Address.

For domain name what you can do is crate host entry in your local PC. Something like this,

192.168.1.3 myserver1

Update

I have found this tutorial which can answer to static IP configuration.

The resolution of the domain name is done by the DNS Server. Since you don't have a public IP or actual domain, your IP will not resolved by any DNS Servers out there. So what you can do is crate a DHCP host entry in your router (creating this host entry is also done in above tutorial) or create a host entry inside your local PC.

Note: I currently don't have a NodeMCU module. Otherwise I could have try this myself.

Sign up to request clarification or add additional context in comments.

3 Comments

this answer doesn't answer the question. it is a comment about alternative off topic solution
Well, if there is NO WAY to "request a specific address" on the ESP side, and it must be done in the router settings, then it is a valid answer, I think. I mean, if there is no answer to a problem, then "there is no answer" is the correct answer in mathematics. I think I will use the DNS server thing method.
@DamnVegetables yeah I agree!

Your Answer

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.