#include const char* ssid = "XXXX"; //don't forget to add your own ssid const char* password = "XXXXX"; //don't forget to add your own password const char* host = "XXX"; //don't forget to add the ESP slave IP const int buttonPin = XX; //don't forget to add your own button pin void setup() { Serial.begin(115200); pinMode(buttonPin, INPUT_PULLUP); connectToWiFi(); } void loop() { if (digitalRead(buttonPin) == LOW) { sendCommandToSlave("TOGGLE_LED"); delay(500); // Delay to avoid button "rebound" } } void connectToWiFi() { Serial.print("Connection to WiFi"); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("Connected to WiFi !"); } void sendCommandToSlave(String command) { WiFiClient client; if (!client.connect(host, 80)) { Serial.println("Fail to connect to the server"); return; } client.print(command); delay(10); client.stop(); }