const int NUM_BUTTONS = sizeof(buttons) / sizeof(buttons[0]); String soapEnvelope(const String& key) { return "" "" "" "" "" + key + "" "" "" ""; } void sendKey(const char* key) { HTTPClient http; WiFiClient client; String url = String("http://") + TV_IP + ":" + TV_PORT + "/nrc/control_0"; http.begin(client, url); http.addHeader("Content-Type", "text/xml; charset=\"utf-8\""); http.addHeader( "SOAPAction", "\"urn:panasonic-com:service:p00NetworkControl:1#X_SendKey\"" ); http.POST(soapEnvelope(key)); http.end(); Serial.print("Sent: "); Serial.println(key); } void setup() { Serial.begin(115200); for (int i = 0; i < NUM_BUTTONS; i++) { pinMode(buttons[i].pin, INPUT_PULLUP); } WiFi.begin(WIFI_SSID, WIFI_PASS); while (WiFi.status() != WL_CONNECTED) { delay(300); } Serial.println("WiFi connected"); } void loop() { static uint32_t lastPress[NUM_BUTTONS] = {0}; const uint32_t debounceMs = 250; for (int i = 0; i < NUM_BUTTONS; i++) { if (digitalRead(buttons[i].pin) == LOW) { uint32_t now = millis(); if (now - lastPress[i] > debounceMs) { sendKey(buttons[i].command); lastPress[i] = now; } } } }