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.
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.
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.
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).
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!
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!
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.