Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- const char* ssid = "YOUR SSID";
- const char* password = "Your Password";
- WiFiServer server(1234);
- struct ButtonAction {
- const char* name;
- int pin;
- };
- ButtonAction buttonMap[] = {
- { "BTN_SOUTH", 19 }, # replace pin no. accdg to your esp32. In this case I use, 19,18,23 and 22
- { "BTN_EAST", 18 },
- { "BTN_NORTH", 23 },
- { "BTN_WEST", 22 },
- };
- const int flashDuration = 200;
- void setup() {
- Serial.begin(115200);
- Serial.println(WiFi.localIP()); // ← this prints the IP address to Serial Monitor
- for (auto& btn : buttonMap) {
- pinMode(btn.pin, OUTPUT);
- digitalWrite(btn.pin, LOW);
- }
- WiFi.begin(ssid, password);
- Serial.print("Connecting to Wi-Fi");
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("\n✅ Wi-Fi connected");
- Serial.println(WiFi.localIP());
- server.begin();
- }
- void flashLED(int pin) {
- digitalWrite(pin, HIGH);
- delay(flashDuration);
- digitalWrite(pin, LOW);
- }
- void loop() {
- WiFiClient client = server.available();
- if (client) {
- while (client.connected()) {
- if (client.available()) {
- String input = client.readStringUntil('\n');
- input.trim();
- for (auto& btn : buttonMap) {
- if (input == "BTN:" + String(btn.name)) {
- flashLED(btn.pin);
- Serial.println("Triggered: " + input);
- }
- }
- }
- }
- client.stop(); // Close client cleanly after disconnect
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement