#include #include #include #include // Timeout, wann die Verbindung als "zurückgesetzt" angesehen werden soll und wieder auf das erste Byte gewartet wird #define TIMEOUT 500 #define FW_NAME "esp-videoswitcher" #define FW_VERSION "1.0.0" SoftwareSerial swSer(D2, D1); int currentnumber = 0; int inputbytes[4]; String output = ""; String output2 = ""; HomieNode switchNode("switch", "switch"); bool switchHandler(const HomieRange& range, const String& value) { Homie.getLogger() << "switch " << ": " << value << endl; switchNode.setProperty("switch").send(value); return true; } void setup() { Serial.begin(115200); swSer.begin(9600); Serial.println("\nKramer VS-162AV"); Homie_setFirmware(FW_NAME, FW_VERSION); Homie_setBrand(FW_NAME); switchNode.advertise("switch").settable(switchHandler); Homie.setup(); ArduinoOTA.setHostname(Homie.getConfiguration().deviceId); ArduinoOTA.begin(); } void loop() { Homie.loop(); ArduinoOTA.handle(); while (swSer.available() > 0) { int r1 = swSer.read(); Serial.print(currentnumber); Serial.print(": "); Serial.print(r1); Serial.print(" "); inputbytes[currentnumber] = r1; output += String(r1, DEC); output += " "; if (currentnumber == 3) { switchNode.setProperty("data").send(output); output2 = ""; output2 += "OUTPUT "; output2 += String(inputbytes[2]-128, DEC); output2 += " INPUT "; output2 += String(inputbytes[1]-128, DEC); switchNode.setProperty("switchevent").send(output2); switchNode.setProperty("input").send(String(inputbytes[1]-128, DEC)); switchNode.setProperty("output").send(String(inputbytes[2]-128, DEC)); // Einfache Interpretation // Serial.print("Von "); // Serial.print(String(inputbytes[2]-128, DEC)); // Serial.print(" zu "); // Serial.println(String(inputbytes[1]-128, DEC)); currentnumber = 0; inputbytes[0] = 0; inputbytes[1] = 0; inputbytes[2] = 0; inputbytes[3] = 0; output = ""; } else { Serial.print(">"); Serial.print(currentnumber); Serial.print("<"); currentnumber++; } } // while (Serial.available() > 0) { // swSer.write(Serial.read()); // } }