From a7adc11b22a05092869f7f9be668c59525b793e3 Mon Sep 17 00:00:00 2001 From: Jon Roeber Date: Mon, 29 Aug 2022 22:46:55 -0400 Subject: [PATCH] set static IP by default --- README.md | 2 +- src/main.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a53a86a..0f37379 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A basic program for getting pictures from the ESP32-CAM over the network. (Assumes basic knowledge of working with ESP32-CAM boards.) - Add your SSID/password to `src/main.cpp`. -- (Optional) [Set a static IP address](https://randomnerdtutorials.com/esp8266-nodemcu-static-fixed-ip-address-arduino/). +- (Optional) Set a static IP address below your SSID/password in `src/main.cpp`. - Flash to the ESP32-CAM with PlatformIO. - Get the IP address from the serial output if you did not set a static IP. - Run `curl -o test.jpg ` to take and save a picture to your local machine. diff --git a/src/main.cpp b/src/main.cpp index d85946e..98460e6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,12 @@ const char* ssid = "..."; const char* password = "..."; +// (Optional) Replace with desired static IP config +IPAddress localIp(192, 168, 0, 190); +IPAddress gateway(192, 168, 0, 1); +IPAddress dns(192, 168, 0, 1); +IPAddress subnet(255, 255, 255, 0); + // Create AsyncWebServer object on port 80 WebServer server(80); @@ -40,7 +46,11 @@ const int brightness = 255; // set the led PWM ( 0 - 255 ) void setup() { Serial.begin(115200); - // Connect to Wi-Fi + // Connect to WiFi + if (!WiFi.config(localIp, gateway, subnet, dns)) { // Remove this if you want a DHCP-assigned IP address instead + Serial.println("WiFi Failed to configure"); + } + WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000);