/**
 ******************************************************************************
 * @file     WiFi_Connection.ino
 * @brief    ESP32 connect to specified Wi-Fi network and print assigned IP address
 * @version  V1.1
 * @date     2025-10-14
 * @author   liangjingheng
 * @company  Waveshare
 * @license  MIT
 ******************************************************************************
 * Features:
 * 1. Connect ESP32 to target Wi-Fi network using provided SSID and password
 * 2. Print connection progress and status via serial monitor
 * 3. Display assigned IP address after successful connection
 * 4. Maintain Wi-Fi connection in loop function
 ******************************************************************************
 */
#include <WiFi.h>  // Include Wi-Fi library

// Replace with your Wi-Fi network credentials
const char *ssid = "waveshare";                // Your WiFi SSID
const char *password = "12345678";            // Your WiFi password

void setup() {
  // Start serial communication
  Serial.begin(115200);
  while (!Serial) {
    ; // Wait for the serial port to be ready
  }



  Serial.println();
  Serial.println("Connecting to WiFi...");

  // Begin Wi-Fi connection
  WiFi.begin(ssid, password);

  // Wait until connected
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  // Connection successful
  Serial.println();
  Serial.println("Connected to WiFi");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP()); // Print assigned IP address
}

void loop() {
  // Keep connection alive (optional: can be used to add functionality)
  delay(1000);
}
