From 8e033c093a59e1d647e712fc9612f00bc20115ad Mon Sep 17 00:00:00 2001 From: 1technophile Date: Thu, 4 May 2017 23:43:21 +0200 Subject: [PATCH] add sending availability of IR code raw from GC #9 --- User_config.h | 2 ++ ZgatewayIR.ino | 43 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/User_config.h b/User_config.h index 60b2566..687bd60 100644 --- a/User_config.h +++ b/User_config.h @@ -105,6 +105,7 @@ RF supported protocols #define pubIRunknownPrtcl false // key to avoid mqtt publication of unknown IR protocol (set to true if you want to publish unknown protocol) #ifdef ESP8266 //IR supported protocols on ESP8266, all supported per default + #define IR_Raw #define IR_COOLIX #define IR_Whynter #define IR_LG @@ -114,6 +115,7 @@ RF supported protocols #define IR_Sharp #define IR_SAMSUNG #else //IR supported protocols on arduino uncomment if you want to send with this protocol, NEC protocol is available per default + //#define IR_Raw //#define IR_COOLIX //#define IR_Whynter //#define IR_LG diff --git a/ZgatewayIR.ino b/ZgatewayIR.ino index 5f80a37..21f3bff 100644 --- a/ZgatewayIR.ino +++ b/ZgatewayIR.ino @@ -74,12 +74,49 @@ boolean IRtoMQTT(){ } void MQTTtoIR(char * topicOri, char * datacallback) { - - unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295 // IR DATA ANALYSIS - //send received MQTT value by IR signal (example of signal sent data = 1086296175) + //send received MQTT value by IR signal boolean signalSent = false; + unsigned long data = 0; + String strcallback = String(datacallback); + trc(String(datacallback)); + int s = strcallback.length(); + //number of "," value count + int count = 0; + for(int i = 0; i < s; i++) + { + if (datacallback[i] == ',') { + count++; + } + } + if(count == 0){ + data = strtoul(datacallback, NULL, 10); // standard sending with unsigned long, we will not be able to pass values > 4294967295 + } + else if(strstr(topicOri, "IR_Raw") != NULL){ // sending raw data from https://irdb.globalcache.com + trc("IR_Raw"); + //buffer allocation from char datacallback + unsigned int GC[count+1]; + String value = ""; + int j = 0; + for(int i = 0; i < s; i++) + { + if (datacallback[i] != ',') { + value = value + String(datacallback[i]); + } + if ((datacallback[i] == ',') || (i == s - 1)) + { + GC[j]= value.toInt(); + value = ""; + j++; + } + } + #ifdef IR_Raw + irsend.sendGC(GC, j); + signalSent = true; + #endif + } + #ifdef ESP8266 // send coolix not available for arduino IRRemote library #ifdef IR_COOLIX if (strstr(topicOri, "IR_COOLIX") != NULL){