Change the acknowledgment to be Home assistant compatible

#29 Instead of returning acknowledgement as a string to a subtopic
return the pauload to a defined topic in user_config.h
This commit is contained in:
1technophile committed 2017-03-24 22:16:28 +01:00
1 parent ee3a76d348
commit 6c795aa802
2 files changed
+96 -78

No files matched your search

+94 -77
View File
@@ -273,85 +273,102 @@ return false;
void receivingMQTT(char * topicOri, char * datacallback) { void receivingMQTT(char * topicOri, char * datacallback) {
String topic = topicOri; String topic = topicOri;
if(topic.lastIndexOf(subjectAck) == -1){ //avoid loop when publishing an acknowledgement
trc(F("Receiving data by MQTT")); trc(F("Receiving data by MQTT"));
trc(topic); trc(topic);
trc(F("Callback value"));
// Acknowledgement inside a subtopic to avoid loop trc(String(datacallback));
char AckSubject[strlen(topicOri)+5]; unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295
AckSubject[strlen(topicOri)+4] ='\0'; trc(F("Converted value to unsigned long"));
strcpy(AckSubject, topicOri); trc(String(data));
strcat(AckSubject, subjectAck);
boolean result = client.publish(AckSubject, "OK"); // RF DATA ANALYSIS
//We look into the subject to see if a special RF protocol is defined
int valuePRT = 0;
int valuePLSL = 0;
int pos = topic.lastIndexOf(RFprotocolKey);
if (pos != -1){
pos = pos + +strlen(RFprotocolKey);
valuePRT = (topic.substring(pos,pos + 1)).toInt();
trc(F("RF Protocol number:"));
trc(String(valuePRT));
}
//We look into the subject to see if a special RF pulselength is defined
int pos2 = topic.lastIndexOf(RFpulselengthKey);
if (pos2 != -1) {
pos2 = pos2 + strlen(RFpulselengthKey);
valuePLSL = (topic.substring(pos2,pos2 + 3)).toInt();
trc(F("RF Pulse Length:"));
trc(String(valuePLSL));
}
if ((topic == subjectMQTTto433) && (valuePRT == 0) && (valuePLSL == 0)){
trc(F("Sending data by RF, default parameters"));
mySwitch.setProtocol(1,350);
mySwitch.send(data, 24);
// Acknowledgement to the GTWRF topic
boolean result = client.publish(subjectGTWRFtoMQTT, datacallback);
if (result)trc(F("Acknowedgement of reception published")); if (result)trc(F("Acknowedgement of reception published"));
trc(F("Callback value")); } else if ((valuePRT != 0) || (valuePLSL != 0)){
trc(String(datacallback)); trc(F("Sending data by RF, user defined parameters"));
unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295 if (valuePRT == 0) valuePRT = 1;
trc(F("Converted value to unsigned long")); if (valuePLSL == 0) valuePLSL = 350;
trc(String(data)); trc(String(valuePRT));
trc(String(valuePLSL));
// RF DATA ANALYSIS mySwitch.setProtocol(valuePRT,valuePLSL);
//We look into the subject to see if a special RF protocol is defined mySwitch.send(data, 24);
int valuePRT = 0; // Acknowledgement to the GTWRF topic
int valuePLSL = 0; boolean result = client.publish(subjectGTWRFtoMQTT, datacallback);
int pos = topic.lastIndexOf(RFprotocolKey); if (result)trc(F("Acknowedgement of reception published"));
if (pos != -1){ }
pos = pos + +strlen(RFprotocolKey);
valuePRT = (topic.substring(pos,pos + 1)).toInt(); // IR DATA ANALYSIS
trc(F("RF Protocol number:")); //send received MQTT value by IR signal (example of signal sent data = 1086296175)
trc(String(valuePRT)); boolean signalSent = false;
} #ifdef ESP8266 // send coolix not available for arduino IRRemote library
//We look into the subject to see if a special RF pulselength is defined if (topic.lastIndexOf("IR_COOLIX") != -1 ){
int pos2 = topic.lastIndexOf(RFpulselengthKey); irsend.sendCOOLIX(data, 24);
if (pos2 != -1) { signalSent = true;
pos2 = pos2 + strlen(RFpulselengthKey); }
valuePLSL = (topic.substring(pos2,pos2 + 3)).toInt(); #endif
trc(F("RF Pulse Length:")); if (topic.lastIndexOf("IR_NEC")!= -1 || topic == subjectMQTTtoIR){
trc(String(valuePLSL)); irsend.sendNEC(data, 32);
} signalSent = true;
}
if ((topic == subjectMQTTto433) && (valuePRT == 0) && (valuePLSL == 0)){ if (topic.lastIndexOf("IR_Whynter")!=-1){
trc(F("Sending data by RF, default parameters")); irsend.sendWhynter(data, 32);
mySwitch.setProtocol(1,350); signalSent = true;
mySwitch.send(data, 24); }
} else if ((valuePRT != 0) || (valuePLSL != 0)){ if (topic.lastIndexOf("IR_LG")!=-1){
trc(F("Sending data by RF, user defined parameters")); irsend.sendLG(data, 28);
if (valuePRT == 0) valuePRT = 1; signalSent = true;
if (valuePLSL == 0) valuePLSL = 350; }
trc(String(valuePRT)); if (topic.lastIndexOf("IR_Sony")!=-1){
trc(String(valuePLSL)); irsend.sendSony(data, 12);
mySwitch.setProtocol(valuePRT,valuePLSL); signalSent = true;
mySwitch.send(data, 24); }
} if (topic.lastIndexOf("IR_DISH")!=-1){
irsend.sendDISH(data, 16);
// IR DATA ANALYSIS signalSent = true;
//send received MQTT value by IR signal (example of signal sent data = 1086296175) }
#ifdef ESP8266 // send coolix not available for arduino IRRemote library if (topic.lastIndexOf("IR_RC5")!=-1){
if (topic.lastIndexOf("IR_COOLIX") != -1 ){ irsend.sendRC5(data, 12);
irsend.sendCOOLIX(data, 24); signalSent = true;
} }
#endif if (topic.lastIndexOf("IR_Sharp")!=-1){
if (topic.lastIndexOf("IR_NEC")!= -1 || topic == subjectMQTTtoIR) irsend.sendSharpRaw(data, 15);
irsend.sendNEC(data, 32); signalSent = true;
if (topic.lastIndexOf("IR_Whynter")!=-1) }
irsend.sendWhynter(data, 32); if (topic.lastIndexOf("IR_SAMSUNG")!=-1){
if (topic.lastIndexOf("IR_LG")!=-1) irsend.sendSAMSUNG(data, 32);
irsend.sendLG(data, 28); signalSent = true;
if (topic.lastIndexOf("IR_Sony")!=-1) }
irsend.sendSony(data, 12); if (signalSent){
if (topic.lastIndexOf("IR_DISH")!=-1) boolean result = client.publish(subjectGTWIRtoMQTT, datacallback);
irsend.sendDISH(data, 16); if (result)trc(F("Acknowedgement of reception published"));
if (topic.lastIndexOf("IR_RC5")!=-1) }
irsend.sendRC5(data, 12); irrecv.enableIRIn(); // ReStart the IR receiver (if not restarted it is not able to receive data)
if (topic.lastIndexOf("IR_Sharp")!=-1)
irsend.sendSharpRaw(data, 15);
if (topic.lastIndexOf("IR_SAMSUNG")!=-1)
irsend.sendSAMSUNG(data, 32);
irrecv.enableIRIn(); // ReStart the IR receiver (if not restarted it is not able to receive data)
} else
trc(F("Not processing this callback contains $subjectAck"));
} }
//trace //trace
+2 -1
View File
@@ -60,16 +60,17 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT
#define GatewayAnnouncementMsg "hello broker!" #define GatewayAnnouncementMsg "hello broker!"
// global MQTT subject listened by the gateway to execute commands (send RF, IR or others) // global MQTT subject listened by the gateway to execute commands (send RF, IR or others)
#define subjectMQTTtoX "home/commands/#" #define subjectMQTTtoX "home/commands/#"
#define subjectAck "/ack"
//433Mhz MQTT Subjects and keys //433Mhz MQTT Subjects and keys
#define subjectMQTTto433 "home/commands/MQTTto433" #define subjectMQTTto433 "home/commands/MQTTto433"
#define subject433toMQTT "home/433toMQTT" #define subject433toMQTT "home/433toMQTT"
#define subjectGTWRFtoMQTT "home/433toMQTT"
#define subject433toMQTTAdvanced "home/433toMQTTAdvanced" #define subject433toMQTTAdvanced "home/433toMQTTAdvanced"
#define RFprotocolKey "433_" // protocol will be defined if a subject contains RFprotocolKey followed by a value of 1 digit #define RFprotocolKey "433_" // protocol will be defined if a subject contains RFprotocolKey followed by a value of 1 digit
#define RFpulselengthKey "PLSL_" // pulselength will be defined if a subject contains RFprotocolKey followed by a value of 3 digits #define RFpulselengthKey "PLSL_" // pulselength will be defined if a subject contains RFprotocolKey followed by a value of 3 digits
//IR MQTT Subjects //IR MQTT Subjects
#define subjectIRtoMQTT "home/sensors/ir" #define subjectIRtoMQTT "home/sensors/ir"
#define subjectGTWIRtoMQTT "home/sensors/ir"
#define subjectMQTTtoIR "home/commands/MQTTtoIR" #define subjectMQTTtoIR "home/commands/MQTTtoIR"
/* /*
RF supported protocols RF supported protocols