#include <WiFi.h>

#define WIFI_SSID    "Wokwi-GUEST"
#define WIFI_PASSWORD ""

#define LED 2
#define Tombol  13

int status = WL_IDLE_STATUS;

void connect_wifi()

{

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

WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 
while (WiFi.status() != WL_CONNECTED) { 
  Serial.print("."); 
  delay(500);

}

Serial.println("");
Serial.println("Connected to AP");

}
void reconnect() {

  status = WiFi.status();

  if (status = WL_CONNECTED) { 
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 
    while (WiFi.status() != WL_CONNECTED) { 
      Serial.print(".");
      delay(500);
      }
      Serial.println("");
      Serial.println("Connected to AP");

    }

  }

  void setup() {

  Serial.println();
  Serial.begin(115200); 
  pinMode(LED, OUTPUT);
  pinMode(Tombol, INPUT);

  }

void loop() {

  if (digitalRead(Tombol)== HIGH)

connect_wifi();

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

else {

   Serial.print("WiFi sudah terkoneksi dengan: "); 
   Serial.println(WIFI_SSID); 
   Serial.println(WiFi.localIP()); 
   digitalWrite(LED, HIGH);

  }
}