#include <WiFi.h>
// Replace with your own network credentials
const char* ssid = "Wokwi-GUEST";
const char* password = "";
IPAddress local_IP(192, 168, 1, 108); // Desired Static IP Address
IPAddress subnet(255, 255, 255, 0);
IPAddress gateway(192, 168, 1, 1);
IPAddress primaryDNS(192, 168, 1, 1); // Not Mandatory
IPAddress secondaryDNS(0, 0, 0, 0); // Not Mandatory
void setup(){
Serial.begin(115200);
WiFi.mode(WIFI_STA);
// Configures Static IP Address
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS))
{
Serial.println("Configuration Failed!");
}
WiFi.begin(ssid, password);
Serial.println("\nConnecting to WiFi Network ..");
// Wait until connection is established
while(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(100);
}
Serial.println("\nConnected to the WiFi network");
// Print The IP And It Should Match The Desired Static IP That We've Defined
Serial.print("Local ESP32 IP: ");
Serial.println(WiFi.localIP());
}
void loop(){
// Do Nothing
}