• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

IP address of server keeps changing.

Q&A Forum › IP address of server keeps changing.
1 Vote Up Vote Down
ancienttron asked 7 years ago

I load a server sketch to esp32 using the Arduino IDE and it says the server is 192.168.1.106.

Then I load three different client sketches to three different ESP32’s with each sending data to

the server at 192.168.1.106. Everything works great, all data received as long as  clients are powered.

Now the problem:   If I unplug the server and leave it unplugged for a length of time, when I plug it back in

nothing works because the server IP address has jumped to 192.168.1.105 or 107 or 101. If I change all the

clients to send to what the new server IP address is everything works fine again.

I don’t have a clue of how to fix this.

 

9 Answers
1 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

Are you familiar with MAC Addresses? Basically a MAC address is a unique identifier assigned to your ESP32 (or any network device). You can use this function to retrieve your ESP32 MAC address while using a WiFi or web server example:

String mac = WiFi.macAddress();
Serial.println(mac);

Then, you login into your router dashboard (the router ip and login/pass are usually printed in the router label). You can assign a fixed IP address to your ESP MAC address, so it always has the same IP address.
The steps to assign a fixed IP to a MAC address is very similar to all the routers.

0 Vote Up Vote Down
ancienttron answered 7 years ago

Thanks Rui, problem solved. I didn’t have a clue that I could assign a fixed IP address to my ESP Mac address.
Your ESP32 course has been well worth the $29.

0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

You’re welcome! I’m glad you made it work and I’m happy that you found the course useful.
I plan to add more content to the course (like assigning fixed IP address and much more, but right now I’m working on adding the ESP32 Projects Modules).

0 Vote Up Vote Down
Russell Lear answered 7 years ago

I’m actually having that same problem (I’m a little surprised it hasn’t happened before).  I’m wondering what you think about modifying the dhcpcd.conf file of my server to specify a static address? Is that generally considered safe? Or something to avoid?  I don’t have easy access to the router configuration.
Thanks!  And the two courses I’ve purchased have both been worth the money!

0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

To be honest I’ve never had the need to modify the dhcpcd.conf file, but if you make the right changes it should work. However, I would leave that option as a last resource.
You could also try to assign the IP directly with WiFi.config() function: https://www.arduino.cc/en/Reference/WiFiConfig
Note that I’m not sure if WiFi.config() works well with the ESP32, because I’ve found a bunch of people having problems when I search for “ESP32 static IP address arduino”…
But the best method to assign the IP address to an ESP32 or a device is using the router configurations pointing to a MAC Address..
I’m glad you found the courses helpful! Thanks for your feedback!

0 Vote Up Vote Down
Lars Ljungberg answered 7 years ago

Assigning an IP address to the ESP MAC address was a great help.

0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

I’m glad it helped!

0 Vote Up Vote Down
Andy Kotowski answered 7 years ago

I can confirm that the esp32  WiFi.config(ip)  does not work as described in the Arduino documents.  No matter how ip is declared a the compiler throws a type error.

You need to specify at least 3 parameters: local_IP, gateway & subnet.  primaryDNS and seconday DNS are optional such as:

IPAddress local_IP(192, 168, 0, 201);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional

 

WiFi.config(local_IP, gateway, subnet);

 

The example “WiFiClientStaticIP” in the esp32 examples works.

0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

Thanks for letting me know Andy! In two or three weeks, I’ll be publishing an article in the RNT blog on how to assign a fix IP address to the ESP32.

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.