{"id":99104,"date":"2020-09-08T13:34:58","date_gmt":"2020-09-08T13:34:58","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=99104"},"modified":"2020-09-08T13:35:01","modified_gmt":"2020-09-08T13:35:01","slug":"esp32-cam-static-fixed-ip-address-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-cam-static-fixed-ip-address-arduino\/","title":{"rendered":"ESP32-CAM: Set Static\/Fixed IP Address (Arduino IDE)"},"content":{"rendered":"\n<p>This tutorial shows how to set a static\/fixed IP address for your ESP32-CAM board. If you\u2019re 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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/ESP32-CAM-Static-Fixed-IP-Address.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Set Static Fixed IP Address Arduino IDE\" class=\"wp-image-99105\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/ESP32-CAM-Static-Fixed-IP-Address.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/ESP32-CAM-Static-Fixed-IP-Address.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/ESP32-CAM-Static-Fixed-IP-Address.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/ESP32-CAM-Static-Fixed-IP-Address.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Static\/Fixed IP Address Sketch<\/h2>\n\n\n\n<p>To show you how to fix your ESP32-CAM IP address, we\u2019ll use the <a href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-video-streaming-face-recognition-arduino-ide\/\" target=\"_blank\" rel=\"noreferrer noopener\">CameraWebServer Example<\/a> that comes with the Arduino IDE. <\/p>\n\n\n\n<p>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\u2019re building.<\/p>\n\n\n\n<p>In your Arduino IDE, go to <strong>File <\/strong>&gt; <strong>Examples <\/strong>&gt; <strong>ESP32 <\/strong>&gt; <strong>Camera <\/strong>&gt; <strong>CameraWebServer<\/strong>.<br>Then, modify the code to fix the IP address as we\u2019ll explain.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting ESP8266 Static IP Address<\/h2>\n\n\n\n<p>Before the <span class=\"rnthl rntliteral\">setup()<\/span> and <span class=\"rnthl rntliteral\">loop()<\/span> functions, define the following variables with your own static IP address and corresponding gateway IP address. <\/p>\n\n\n\n<p>By default, the next snippet assigns the IP address 192.168.1.184 that works in the gateway 192.168.1.1.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Set your Static IP address\nIPAddress local_IP(192, 168, 1, 184);\n\/\/ Set your Gateway IP address\nIPAddress gateway(192, 168, 1, 1);\nIPAddress subnet(255, 255, 0, 0);\nIPAddress primaryDNS(8, 8, 8, 8); \/\/optional\nIPAddress secondaryDNS(8, 8, 4, 4); \/\/optional<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, you need to call the <span class=\"rnthl rntliteral\">WiFi.config()<\/span> method to assign the configurations to your ESP32-CAM (before starting Wi-Fi).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if(!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {\n  Serial.println(\"STA Failed to configure\");\n}\nWiFi.begin(ssid, password);<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">primaryDNS<\/span> and <span class=\"rnthl rntliteral\">secondaryDNS<\/span> parameters are optional and you can remove them.<\/p>\n\n\n\n<p>You can <a href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-CAM-eBook\/blob\/master\/Code\/Extra\/CameraWebServer_Static_IP.zip?raw=true\" target=\"_blank\" rel=\"noreferrer noopener\">download the complete code for this project here<\/a>. 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"669\" height=\"269\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/Static-IP-Address-ESP32-CAM-Serial-Monitor.png?resize=669%2C269&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Set a Static IP Address Demonstration Serial Monitor\" class=\"wp-image-99106\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/Static-IP-Address-ESP32-CAM-Serial-Monitor.png?w=669&amp;quality=100&amp;strip=all&amp;ssl=1 669w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/Static-IP-Address-ESP32-CAM-Serial-Monitor.png?resize=300%2C121&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 669px) 100vw, 669px\" \/><\/figure><\/div>\n\n\n\n<p>As you can see, it prints the IP address 192.168.1.184.<\/p>\n\n\n\n<p>Now, you can access that IP address on your local network to watch the <a href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-video-streaming-face-recognition-arduino-ide\/\">video streaming web server<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you\u2019ve learned how to set up a static IP address for your ESP32-CAM. You can use what you\u2019ve learned here in any of your ESP32-CAM sketches.<\/p>\n\n\n\n<p>If you like the ESP32-CAM, take a look at our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-projects-ebook\/\">Build ESP32-CAM Projects using Arduino IDE eBook<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32-cam\/\">More ESP32-CAM Projects and Tutorials&#8230;<\/a><\/li><\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to set a static\/fixed IP address for your ESP32-CAM board. If you\u2019re running a web server or Wi-Fi client with your ESP32-CAM and every time you &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32-CAM: Set Static\/Fixed IP Address (Arduino IDE)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-static-fixed-ip-address-arduino\/#more-99104\" aria-label=\"Read more about ESP32-CAM: Set Static\/Fixed IP Address (Arduino IDE)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":99105,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[281,319,264],"tags":[],"class_list":["post-99104","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32-project","category-esp32-cam","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/ESP32-CAM-Static-Fixed-IP-Address.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/99104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=99104"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/99104\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/99105"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=99104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=99104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=99104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}