/* ESP32 HTTP IoT Server Example for Wokwi.com
https://wokwi.com/projects/320964045035274834
To test, you need the Wokwi IoT Gateway, as explained here:
https://docs.wokwi.com/guides/esp32-wifi#the-private-gateway
Then start the simulation, and open http://localhost:9080
in another browser tab.
Note that the IoT Gateway requires a Wokwi Club subscription.
To purchase a Wokwi Club subscription, go to https://wokwi.com/club
*/
#include <WiFi.h>
#include <WiFiClient.h>
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
// Defining the WiFi channel speeds up the connection:
#define WIFI_CHANNEL 6
const int LED1 = 26;
const int LED2 = 27;
const int BTN = 17;
bool led1State = false;
bool led2State = false;
void blinkYellow() {
digitalWrite(LED1, HIGH);
delay(1);
digitalWrite(LED1, LOW);
}
void setupWifi() {
WiFi.begin(WIFI_SSID, WIFI_PASSWORD, WIFI_CHANNEL);
Serial.print("Connecting to WiFi ");
Serial.print(WIFI_SSID);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(100);
blinkYellow();
}
Serial.println(" Connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
digitalWrite(LED1, HIGH);
}
void setup(void) {
Serial.begin(115200);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(BTN, INPUT_PULLUP);
setupWifi();
}
void getBtnValue() {
if (digitalRead(BTN) == LOW) {
Serial.println("Button press!!!");
}
}
void loop(void) {
getBtnValue();
delay(2);
}