Open the EXAMPLES menu on your Arduino IDE and get the ESP32 WiFi/SimpleWiFiServer.ino sketch:
About this program:
WiFi Web Server LED Blink
Created for arduino 25 Nov 2012 by Tom Igoe
Ported for sparkfun esp32 31.01.2017 by Jan Hendrik Berlin
A simple web server that lets you blink an LED via the web. This sketch will print the IP address of your ESP32 WiFi network to the Serial monitor. From there, you can open that address in a web browser to turn on and off the LED on pin 5.
If the IP address of your board is for example 10.0.1.40:
http://10.0.1.40/Hturns the LED on
http://10.0.1.40/L
turns the LED off
This example is written for a network using WPA encryption. For WEP or WPA, change the Wifi.begin() call accordingly.
Circuit: LED attached to pin 5
So, let's use the program without significant modifications. Change the External LED Pin to GPIO5
Off course, if you prefer change the code for GPIO2 w/o changing the HW.
First, enter your network credentials:
const char* ssid = "yourssid"; const char* password = "yourpasswd";
And upload it on your ESP32.
The first thing that you will see at your serial Monitor will be the information that your ESP32 is connected and what is its Ip Address:
WiFi connected. IP address: 10.0.1.40
Open your favorite browser, typing this IP address. You will get a WebPage like the one above. There you can Turn on or off the LED remotely.