This tutorial shows how to set a static/fixed IP address for your ESP32-CAM board. If you’re running a web server or Wi-Fi client with your ESP32-CAM and every time you restart your board, it has a new IP address, you can follow this tutorial to assign a static/fixed IP address.
Static/Fixed IP Address Sketch
To show you how to fix your ESP32-CAM IP address, we’ll use the CameraWebServer Example that comes with the Arduino IDE.
By the end of our explanation you should be able to fix your IP address regardless of the web server or Wi-Fi project you’re building.
In your Arduino IDE, go to File > Examples > ESP32 > Camera > CameraWebServer.
Then, modify the code to fix the IP address as we’ll explain.
Setting ESP8266 Static IP Address
Before the setup() and loop() functions, define the following variables with your own static IP address and corresponding gateway IP address.
By default, the next snippet assigns the IP address 192.168.1.184 that works in the gateway 192.168.1.1.
// Set your Static IP address
IPAddress local_IP(192, 168, 1, 184);
// Set your Gateway IP address
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
In the setup(), you need to call the WiFi.config() method to assign the configurations to your ESP32-CAM (before starting Wi-Fi).
if(!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");
}
WiFi.begin(ssid, password);
The primaryDNS and secondaryDNS parameters are optional and you can remove them.
You can download the complete code for this project here. It assigns the static IP address 192.168.1.184. You just need to insert your network credentials and the code will work straight away.
Testing
After uploading the code to your board, open the Arduino IDE Serial Monitor at the baud rate 115200. Restart your ESP32-CAM board and the IP address defined earlier should be assigned to your board.
As you can see, it prints the IP address 192.168.1.184.
Now, you can access that IP address on your local network to watch the video streaming web server.
Wrapping Up
In this tutorial, you’ve learned how to set up a static IP address for your ESP32-CAM. You can use what you’ve learned here in any of your ESP32-CAM sketches.
If you like the ESP32-CAM, take a look at our resources:
Thanks for reading.
hi,
thank you very much for this Tutorial, long time I was searching in that case, now every thing are clearly
great work!
all the best
kind regards form Likya
Max
You’re welcome! I’m glad it worked 🙂
I heard that using static IP address will cut power usage quite a lot. Important feature in wireless applications.
Hi I m Ramesh. Currently I am working with esp32cam but I cannot connect to network it shows “Connecting………….” so on. SSID, password, speed wifi, good Usb everything is fine from my side but yet unable to connect. Please help me
Hi.
Take a look at our troubleshooting guide and see if that helps: https://randomnerdtutorials.com/esp32-cam-troubleshooting-guide/
Regards,
Sara
tried this. My CAM is working with the dynamic address (the default code) but not working with the static IP address
When I tried this with the suggested 192.168.1.184 address and the 192.168.1.1 gateway it did not work. I change to 192.168.0.184 and 192.168.0.1 and it worked because all the other devices use 192.168.0.nn. Not sure why. Can you explain?
I would also like to know what the optional primary and secondary DNS line are for. Are they used if something else is already using 184? Please explain.
Hi !! I would like to display ip adress of esp32 cam on mini oled . My project is portable so static ip won’t help . Can you help me ? Thanks in advance !!