#include "WiFi.h"
#define WIFI_SSID           "Wokwi-GUEST"
#define WIFI_PASSWORD       ""
#define LED 13
#define SERIAL_DEBUG_BAUD   115200
int status = WL_IDLE_STATUS;

void InitWiFi()
{
  Serial.println("Tersambung ke Access Point ...");
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {

    delay(500);
    Serial.print(".");
  }
  Serial.println("Tersambung ke Access Point");
}

void reconnect() {
  status = WiFi.status();
  if ( status != WL_CONNECTED) {
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    Serial.println("Tersambung ke Access Point");
  }
}

void setup() {
  Serial.begin(SERIAL_DEBUG_BAUD);
  Serial.println("Initializing WiFi...");
  InitWiFi();
  pinMode(LED, OUTPUT);
}

void loop() {
delay(1000);

if (WiFi.status() != WL_CONNECTED) {
reconnect();
}

else {
    Serial.print("WiFi sudah terkoneksi dengan ");
    Serial.println(WIFI_SSID);
    Serial.print("IP: ");
    Serial.println(WiFi.localIP());
    digitalWrite(LED, HIGH);
    delay(200);
    digitalWrite(LED, LOW);
  }
}