correct deduplication issue with SRFB and improve OMG performance

by reducing the receivingMQTT call numbers
https://community.openmqttgateway.com/t/seeing-duplicated-messages/398/7
This commit is contained in:
Florian committed 2019-04-01 22:07:28 +02:00
1 parent 54d95158c7
commit 4dafcd3779
2 files changed
+20 -19

No files matched your search

+6 -8
View File
@@ -203,8 +203,8 @@ void callback(char* topic, byte* payload, unsigned int length) {
memcpy(p,payload,length); memcpy(p,payload,length);
// Conversion to a printable string // Conversion to a printable string
p[length] = '\0'; p[length] = '\0';
//launch the function to treat received data //launch the function to treat received data if this data concern OpenMQTTGateway
receivingMQTT(topic,(char *) p); if ((strstr(topic, subjectMultiGTWKey) != NULL) || (strstr(topic, subjectGTWSendKey) != NULL)) receivingMQTT(topic,(char *) p);
// Free the memory // Free the memory
free(p); free(p);
} }
@@ -802,14 +802,15 @@ return false;
} }
void receivingMQTT(char * topicOri, char * datacallback) { void receivingMQTT(char * topicOri, char * datacallback) {
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
JsonObject& jsondata = jsonBuffer.parseObject(datacallback);
if (strstr(topicOri, subjectMultiGTWKey) != NULL) // storing received value so as to avoid publishing this value if it has been already sent by this or another OpenMQTTGateway if (strstr(topicOri, subjectMultiGTWKey) != NULL) // storing received value so as to avoid publishing this value if it has been already sent by this or another OpenMQTTGateway
{ {
trc(F("Store signal")); trc(F("Store signal"));
unsigned long data = 0; unsigned long data = 0;
#ifdef jsonPublishing #ifdef jsonPublishing
trc(F("Json buf."));
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
JsonObject& jsondata = jsonBuffer.parseObject(datacallback);
if (jsondata.success()) data = jsondata["value"]; if (jsondata.success()) data = jsondata["value"];
#endif #endif
@@ -823,9 +824,6 @@ void receivingMQTT(char * topicOri, char * datacallback) {
} }
} }
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
JsonObject& jsondata = jsonBuffer.parseObject(datacallback);
if (jsondata.success()) { // json object ok -> json decoding if (jsondata.success()) { // json object ok -> json decoding
#ifdef ZgatewayPilight // ZgatewayPilight is only defined with json publishing #ifdef ZgatewayPilight // ZgatewayPilight is only defined with json publishing
MQTTtoPilight(topicOri, jsondata); MQTTtoPilight(topicOri, jsondata);
+14 -11
View File
@@ -109,21 +109,24 @@ void _rfbDecode() {
char val[8]= {0}; char val[8]= {0};
extract_char(buffer, val, 12 ,8, false,true); extract_char(buffer, val, 12 ,8, false,true);
SRFBdata.set("value", (char *)val); unsigned long MQTTvalue = (unsigned long)strtoul(val, NULL, 10);
SRFBdata.set("value", (unsigned long)MQTTvalue);
char val_Tsyn[4]= {0}; char Tsyn[4]= {0};
extract_char(buffer, val_Tsyn , 0 ,4, false, true); extract_char(buffer, Tsyn , 0 ,4, false, true);
SRFBdata.set("delay", (char *)val_Tsyn); int val_Tsyn = (int)strtol(Tsyn, NULL, 10);
SRFBdata.set("delay", (int)val_Tsyn);
char val_Thigh[4]= {0}; char Thigh[4]= {0};
extract_char(buffer, val_Thigh , 4 ,4, false, true); extract_char(buffer, Thigh , 4 ,4, false, true);
SRFBdata.set("val_Thigh", (char *)val_Thigh); int val_Thigh = (int)strtol(Thigh, NULL, 10);
SRFBdata.set("val_Thigh", (int)val_Thigh);
char val_Tlow[4]= {0}; char Tlow[4]= {0};
extract_char(buffer,val_Tlow , 8 ,4, false, true); extract_char(buffer,Tlow , 8 ,4, false, true);
SRFBdata.set("val_Tlow", (char *)val_Tlow); int val_Tlow = (int)strtol(Tlow, NULL, 10);
SRFBdata.set("val_Tlow", (int)val_Tlow);
unsigned long MQTTvalue = SRFBdata.get<unsigned long>("value");
if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of RF -->MQTT if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of RF -->MQTT
trc(F("Adv data SRFBtoMQTT")); trc(F("Adv data SRFBtoMQTT"));
pub(subjectSRFBtoMQTT,SRFBdata); pub(subjectSRFBtoMQTT,SRFBdata);