set default protocol with to IR NEC when no protocol is set on json

This commit is contained in:
Florian committed 2019-01-25 00:05:19 +01:00
1 parent 448a20a2cf
commit e89bce406d
1 file changed
+22 -26
+22 -26
View File
@@ -489,8 +489,14 @@ void IRtoMQTT(){
if (data != 0||raw) { if (data != 0||raw) {
trc(F("MQTTtoIR data || raw ok")); trc(F("MQTTtoIR data || raw ok"));
boolean signalSent = false; boolean signalSent = false;
trc("value");
trc(data); trc(data);
trc("raw");
trc(raw);
const char * protocol_name = IRdata["protocol_name"]; const char * protocol_name = IRdata["protocol_name"];
unsigned int valueBITS = IRdata["bits"];
uint16_t valueRPT = IRdata["repeat"]|repeatIRwNumber;
if(raw){ if(raw){
unsigned int s = strlen(raw); unsigned int s = strlen(raw);
//number of "," value count //number of "," value count
@@ -529,10 +535,10 @@ void IRtoMQTT(){
trc("IR_Raw"); trc("IR_Raw");
//buffer allocation from char datacallback //buffer allocation from char datacallback
#ifdef ESP8266 #ifdef ESP8266
uint16_t Raw[count+1]; uint16_t Raw[count+1];
#else #else
unsigned int Raw[count+1]; unsigned int Raw[count+1];
#endif #endif
String value = ""; String value = "";
int j = 0; int j = 0;
for(int i = 0; i < s; i++) for(int i = 0; i < s; i++)
@@ -551,15 +557,7 @@ void IRtoMQTT(){
signalSent = true; signalSent = true;
} }
#endif #endif
}else if(protocol_name){ }else if(protocol_name && (strstr(protocol_name, "IR_NEC") == NULL)){
unsigned int valueBITS = IRdata["bits"];
trc(F("Bits nb:"));
trc(valueBITS);
uint16_t valueRPT = IRdata["repeat"]|repeatIRwNumber;
trc(F("IR repeat:"));
trc(valueRPT);
#ifdef ESP8266 // send coolix not available for arduino IRRemote library #ifdef ESP8266 // send coolix not available for arduino IRRemote library
#ifdef IR_COOLIX #ifdef IR_COOLIX
if (strstr(protocol_name, "IR_COOLIX") != NULL){ if (strstr(protocol_name, "IR_COOLIX") != NULL){
@@ -569,15 +567,6 @@ void IRtoMQTT(){
} }
#endif #endif
#endif #endif
if (strstr(protocol_name, "IR_NEC") != NULL || !protocol_name ){
if (valueBITS == 0) valueBITS = NEC_BITS;
#ifdef ESP8266
irsend.sendNEC(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendNEC(data, valueBITS);
#endif
signalSent = true;
}
#ifdef IR_Whynter #ifdef IR_Whynter
if (strstr(protocol_name, "IR_Whynter") != NULL){ if (strstr(protocol_name, "IR_Whynter") != NULL){
if (valueBITS == 0) valueBITS = WHYNTER_BITS; if (valueBITS == 0) valueBITS = WHYNTER_BITS;
@@ -781,13 +770,20 @@ void IRtoMQTT(){
#endif #endif
#endif #endif
}else{
trc(F("Using NEC protocol"));
if (valueBITS == 0) valueBITS = NEC_BITS;
#ifdef ESP8266
irsend.sendNEC(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendNEC(data, valueBITS);
#endif
signalSent = true;
}
if (signalSent){ // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also if (signalSent){ // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
pub(subjectGTWIRtoMQTT, IRdata); pub(subjectGTWIRtoMQTT, IRdata);
} }
irrecv.enableIRIn(); // ReStart the IR receiver (if not restarted it is not able to receive data) irrecv.enableIRIn(); // ReStart the IR receiver (if not restarted it is not able to receive data)
}else{
trc(F("MQTTtoIR Fail reading protocol name from json"));
}
}else{ }else{
trc(F("MQTTtoIR Fail reading from json")); trc(F("MQTTtoIR Fail reading from json"));
} }