implemented IR transmission via MQTT

This commit is contained in:
Ronald Schaten 2016-04-21 11:33:48 +02:00
parent 1301947c7a
commit 2970dad868

View File

@ -26,7 +26,68 @@ void DeviceIrTx::deviceSetup() {
} }
bool DeviceIrTx::irTxHandler(String message) { bool DeviceIrTx::irTxHandler(String message) {
irsend.sendSony(0xa90, 12); DynamicJsonBuffer json_inBuffer;
JsonObject& json_in = json_inBuffer.parseObject(message);
if (json_in.success()) {
unsigned long data = 0;
int nbits = 0;
if (json_in.containsKey("data")) {
data = json_in["data"];
}
if (json_in.containsKey("nbits")) {
nbits = json_in["nbits"];
}
if (json_in.containsKey("protocol")) {
String protocol = json_in["protocol"];
protocol.toUpperCase();
Serial.print("IR-Tx: sending ");
Serial.print(data);
Serial.print(" (");
Serial.print(nbits);
Serial.print(") via ");
Serial.print(protocol);
Serial.println(" Protocol");
for (int i = 0; i < 5; i++) {
if (protocol == "NEC") {
irsend.sendNEC(data, nbits);
} else if (protocol == "SONY") {
irsend.sendSony(data, nbits);
} else if (protocol == "RC5") {
irsend.sendRC5(data, nbits);
} else if (protocol == "RC6") {
irsend.sendRC6(data, nbits);
} else if (protocol == "DISH") {
irsend.sendDISH(data, nbits);
} else if (protocol == "SHARP") {
irsend.sendSharp(data, nbits);
} else if (protocol == "PANASONIC") {
irsend.sendPanasonic(data, nbits);
/* JVC needs a repeat parameter, will be implemented if necessary
} else if (protocol == "JVC") {
int repeat = 0;
irsend.sendJVC(data, nbits, repeat);
*/
/* Sanyo and Mitsubishi aren't implemented in the library
} else if (protocol == "SANYO") {
irsend.sendSanyo(data, nbits);
} else if (protocol == "MITSUBISHI") {
irsend.sendMitsubishi(data, nbits);
*/
} else if (protocol == "SAMSUNG") {
irsend.sendSAMSUNG(data, nbits);
} else if (protocol == "LG") {
irsend.sendLG(data, nbits);
} else if (protocol == "WHYNTER") {
irsend.sendLG(data, nbits);
} else {
Serial.println("IR protocol not implemented");
}
delay(40);
}
}
} else {
Serial.println("parsing of JSON failed");
}
return true; return true;
} }