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:
1 parent
ee3a76d348
commit
6c795aa802
2 files changed
+94
-76
No files matched your search
+92
-75
@@ -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(topic);
|
|
||||||
|
|
||||||
// Acknowledgement inside a subtopic to avoid loop
|
trc(F("Receiving data by MQTT"));
|
||||||
char AckSubject[strlen(topicOri)+5];
|
trc(topic);
|
||||||
AckSubject[strlen(topicOri)+4] ='\0';
|
trc(F("Callback value"));
|
||||||
strcpy(AckSubject, topicOri);
|
trc(String(datacallback));
|
||||||
strcat(AckSubject, subjectAck);
|
unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295
|
||||||
boolean result = client.publish(AckSubject, "OK");
|
trc(F("Converted value to unsigned long"));
|
||||||
|
trc(String(data));
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
mySwitch.setProtocol(valuePRT,valuePLSL);
|
||||||
|
mySwitch.send(data, 24);
|
||||||
|
// Acknowledgement to the GTWRF topic
|
||||||
|
boolean result = client.publish(subjectGTWRFtoMQTT, datacallback);
|
||||||
|
if (result)trc(F("Acknowedgement of reception published"));
|
||||||
|
}
|
||||||
|
|
||||||
// RF DATA ANALYSIS
|
// IR DATA ANALYSIS
|
||||||
//We look into the subject to see if a special RF protocol is defined
|
//send received MQTT value by IR signal (example of signal sent data = 1086296175)
|
||||||
int valuePRT = 0;
|
boolean signalSent = false;
|
||||||
int valuePLSL = 0;
|
#ifdef ESP8266 // send coolix not available for arduino IRRemote library
|
||||||
int pos = topic.lastIndexOf(RFprotocolKey);
|
if (topic.lastIndexOf("IR_COOLIX") != -1 ){
|
||||||
if (pos != -1){
|
irsend.sendCOOLIX(data, 24);
|
||||||
pos = pos + +strlen(RFprotocolKey);
|
signalSent = true;
|
||||||
valuePRT = (topic.substring(pos,pos + 1)).toInt();
|
}
|
||||||
trc(F("RF Protocol number:"));
|
#endif
|
||||||
trc(String(valuePRT));
|
if (topic.lastIndexOf("IR_NEC")!= -1 || topic == subjectMQTTtoIR){
|
||||||
}
|
irsend.sendNEC(data, 32);
|
||||||
//We look into the subject to see if a special RF pulselength is defined
|
signalSent = true;
|
||||||
int pos2 = topic.lastIndexOf(RFpulselengthKey);
|
}
|
||||||
if (pos2 != -1) {
|
if (topic.lastIndexOf("IR_Whynter")!=-1){
|
||||||
pos2 = pos2 + strlen(RFpulselengthKey);
|
irsend.sendWhynter(data, 32);
|
||||||
valuePLSL = (topic.substring(pos2,pos2 + 3)).toInt();
|
signalSent = true;
|
||||||
trc(F("RF Pulse Length:"));
|
}
|
||||||
trc(String(valuePLSL));
|
if (topic.lastIndexOf("IR_LG")!=-1){
|
||||||
}
|
irsend.sendLG(data, 28);
|
||||||
|
signalSent = true;
|
||||||
if ((topic == subjectMQTTto433) && (valuePRT == 0) && (valuePLSL == 0)){
|
}
|
||||||
trc(F("Sending data by RF, default parameters"));
|
if (topic.lastIndexOf("IR_Sony")!=-1){
|
||||||
mySwitch.setProtocol(1,350);
|
irsend.sendSony(data, 12);
|
||||||
mySwitch.send(data, 24);
|
signalSent = true;
|
||||||
} else if ((valuePRT != 0) || (valuePLSL != 0)){
|
}
|
||||||
trc(F("Sending data by RF, user defined parameters"));
|
if (topic.lastIndexOf("IR_DISH")!=-1){
|
||||||
if (valuePRT == 0) valuePRT = 1;
|
irsend.sendDISH(data, 16);
|
||||||
if (valuePLSL == 0) valuePLSL = 350;
|
signalSent = true;
|
||||||
trc(String(valuePRT));
|
}
|
||||||
trc(String(valuePLSL));
|
if (topic.lastIndexOf("IR_RC5")!=-1){
|
||||||
mySwitch.setProtocol(valuePRT,valuePLSL);
|
irsend.sendRC5(data, 12);
|
||||||
mySwitch.send(data, 24);
|
signalSent = true;
|
||||||
}
|
}
|
||||||
|
if (topic.lastIndexOf("IR_Sharp")!=-1){
|
||||||
// IR DATA ANALYSIS
|
irsend.sendSharpRaw(data, 15);
|
||||||
//send received MQTT value by IR signal (example of signal sent data = 1086296175)
|
signalSent = true;
|
||||||
#ifdef ESP8266 // send coolix not available for arduino IRRemote library
|
}
|
||||||
if (topic.lastIndexOf("IR_COOLIX") != -1 ){
|
if (topic.lastIndexOf("IR_SAMSUNG")!=-1){
|
||||||
irsend.sendCOOLIX(data, 24);
|
irsend.sendSAMSUNG(data, 32);
|
||||||
}
|
signalSent = true;
|
||||||
#endif
|
}
|
||||||
if (topic.lastIndexOf("IR_NEC")!= -1 || topic == subjectMQTTtoIR)
|
if (signalSent){
|
||||||
irsend.sendNEC(data, 32);
|
boolean result = client.publish(subjectGTWIRtoMQTT, datacallback);
|
||||||
if (topic.lastIndexOf("IR_Whynter")!=-1)
|
if (result)trc(F("Acknowedgement of reception published"));
|
||||||
irsend.sendWhynter(data, 32);
|
}
|
||||||
if (topic.lastIndexOf("IR_LG")!=-1)
|
irrecv.enableIRIn(); // ReStart the IR receiver (if not restarted it is not able to receive data)
|
||||||
irsend.sendLG(data, 28);
|
|
||||||
if (topic.lastIndexOf("IR_Sony")!=-1)
|
|
||||||
irsend.sendSony(data, 12);
|
|
||||||
if (topic.lastIndexOf("IR_DISH")!=-1)
|
|
||||||
irsend.sendDISH(data, 16);
|
|
||||||
if (topic.lastIndexOf("IR_RC5")!=-1)
|
|
||||||
irsend.sendRC5(data, 12);
|
|
||||||
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
@@ -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
|
||||||
|
|||||||
Reference in new issue
Block a user