diff --git a/esp-videoswitcher.ino b/esp-videoswitcher.ino index fb55e05..427a778 100644 --- a/esp-videoswitcher.ino +++ b/esp-videoswitcher.ino @@ -20,8 +20,21 @@ HomieNode switchNode("switch", "switch"); bool switchHandler(const HomieRange& range, const String& value) { Homie.getLogger() << "switch " << ": " << value << endl; + int localByte = 0; + + int lastspace = 0; + int nextspace = 0; + while (nextspace < value.length()-1) + { + // Nur solange wir noch Platz für Inputbytes haben... :) + if (localByte <= 3) { + nextspace = value.indexOf(' ', lastspace); + commandbytes[localByte] = (value.substring(lastspace,nextspace-1)).toInt(); // TEST for sanity + localByte++; + } + } - if (sscanf(value, "%d %d %d %d", &commandbytes[0], &commandbytes[1], &commandbytes[2], &commandbytes[3]) == 4) + if (localByte ==4) { // Nur wenn wirklich 4 Werte übernommen wurden switchNode.setProperty("switch").send(value);