switchHandler: Kanal zur Maschine zurück aufgrund von 4 gegebenen Dezimal-Werten. (untested!)

This commit is contained in:
starcalc 2017-11-28 11:28:46 +01:00
parent 272a4fa43f
commit 8e487aa213
1 changed files with 21 additions and 12 deletions

View File

@ -12,6 +12,7 @@
SoftwareSerial swSer(D2, D1);
int currentnumber = 0;
int inputbytes[4];
int commandbytes[4];
String output = "";
String output2 = "";
@ -19,7 +20,25 @@ HomieNode switchNode("switch", "switch");
bool switchHandler(const HomieRange& range, const String& value) {
Homie.getLogger() << "switch " << ": " << value << endl;
if (sscanf(value, "%d %d %d %d", &commandbytes[0], &commandbytes[1], &commandbytes[2], &commandbytes[3]) == 4)
{
// Nur wenn wirklich 4 Werte übernommen wurden
switchNode.setProperty("switch").send(value);
// Sende an das Gerät
swSer.write(commandbytes[0]);
swSer.write(commandbytes[1]);
swSer.write(commandbytes[2]);
swSer.write(commandbytes[3]);
}
else
{
commandbytes[0] = 0;
commandbytes[1] = 0;
commandbytes[2] = 0;
commandbytes[3] = 0;
switchNode.setProperty("switch").send("ERROR");
}
return true;
}
@ -37,8 +56,6 @@ void setup() {
ArduinoOTA.setHostname(Homie.getConfiguration().deviceId);
ArduinoOTA.begin();
}
void loop() {
@ -65,11 +82,7 @@ void loop() {
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;
@ -84,8 +97,4 @@ void loop() {
currentnumber++;
}
}
// while (Serial.available() > 0) {
// swSer.write(Serial.read());
// }
}