#include #include #include const char* ssid = "paradicsom"; const char* password = "19700318"; String url = "http://192.168.50.69"; WebServer server(80); const char webpage[] PROGMEM = R"rawliteral( Arduino Remote Web
Power
Exit
Guide
Mute
Source
Volume up
Volume down
Channel up
Channel down
1
2
3
4
5
6
7
8
9
0
#define DELAY_AFTER_SEND 1000 #define DELAY_AFTER_LOOP 5000 bool switching = false; void SendNecSignal(int buttonCode) { digitalWrite(LED, HIGH); Serial.print(F("Send NEC with 8 bit address code: ")); Serial.println(buttonCode); Serial.flush(); IrSender.sendNEC(0x7F00, buttonCode, 1); delay(DELAY_AFTER_SEND); //delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal digitalWrite(LED, LOW); } void setup() { Serial.begin(115200); pinMode(LED, OUTPUT); digitalWrite(LED, HIGH); WiFi.begin(ssid, password); Serial.println("connecting to wifi"); while (WiFi.status() != WL_CONNECTED) { delay(250); Serial.println("."); } Serial.println(); Serial.print("Connected to wifi. IP: "); Serial.println(WiFi.localIP()); ///////////////////////////////////////////////////////// IrSender.begin(IR_TRANSMIT_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); Serial.print(F("Ready to receive IR signals of protocols: ")); printActiveIRProtocols(&Serial); // Define route for root server.on("/", HTTP_GET, []() { server.send(200, "text/html", webpage); }); // Define route for LED toggle server.on("/sendSignal", HTTP_POST, []() { String json = server.arg("plain"); // Get JSON payload as a string Serial.print("Received JSON: "); Serial.println(json); // Parse JSON StaticJsonDocument<200> doc; DeserializationError error = deserializeJson(doc, json); if (error) { Serial.print("Failed to parse JSON: "); Serial.println(error.c_str()); server.send(400, "text/plain", "Invalid JSON"); return; } int code = doc["code"]; Serial.print("code: "); Serial.println(code); SendNecSignal(code); Serial.println(); server.send(200, "text/plain", "SentSignal: " + code); }); // Start the server server.begin(); digitalWrite(LED, LOW); } void loop() { server.handleClient(); // Handle incoming client requests }