### Useful Wifi Code
Here’s an example of how to manually set up the **ESP32 in STA (Station) mode**, configure a static IP address, gateway, and DNS, and then print out all Wi-Fi related information (such as MAC address, IP address, gateway, DNS, etc.):
```cpp
#include
const char* ssid = "your_SSID"; // Your Wi-Fi SSID
const char* password = "your_PASSWORD"; // Your Wi-Fi password
// Static IP Configuration
IPAddress local_IP(192, 168, 1, 184); // Static IP address
IPAddress gateway(192, 168, 1, 1); // Gateway IP address
IPAddress subnet(255, 255, 255, 0); // Subnet mask
IPAddress dns(8, 8, 8, 8); // DNS (Google DNS)
void setup() {
Serial.begin(115200);
// Set static IP, gateway, subnet, and DNS
if (!WiFi.config(local_IP, gateway, subnet, dns)) {
Serial.println("Failed to configure Static IP");
}
// Connect to Wi-Fi network
WiFi.begin(ssid, password);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Once connected, print Wi-Fi details
Serial.println("\nConnected to Wi-Fi!");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
Serial.print("Subnet Mask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway: ");
Serial.println(WiFi.gatewayIP());
Serial.print("DNS: ");
Serial.println(WiFi.dnsIP());
Serial.print("MAC Address: ");
Serial.println(WiFi.macAddress());
}
void loop() {
// No need for anything in the loop
}
```
Useful Wifi Code
RELATED ARTICLES
Photoresistor Sensor
Project - Temperature Measurement
NTC Temperature Sensor
Project - IR Sender
Project - IR Receiver
Remote infrared Sensor
Project - Motion Detection Alarm
- Choosing a selection results in a full page refresh.