From 2970dad868c7dd333f10ef9e84a8931280c6ecfb Mon Sep 17 00:00:00 2001 From: Ronald Schaten Date: Thu, 21 Apr 2016 11:33:48 +0200 Subject: [PATCH] implemented IR transmission via MQTT --- things/DeviceIrTx.h | 63 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/things/DeviceIrTx.h b/things/DeviceIrTx.h index ae5a6d4..9a7b346 100644 --- a/things/DeviceIrTx.h +++ b/things/DeviceIrTx.h @@ -26,7 +26,68 @@ void DeviceIrTx::deviceSetup() { } 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; }