diff --git a/OpenMQTTGateway.ino b/OpenMQTTGateway.ino index fa73042..a12bae2 100644 --- a/OpenMQTTGateway.ino +++ b/OpenMQTTGateway.ino @@ -74,18 +74,15 @@ boolean reconnect() { trc(F("Attempting MQTT connection...")); //F function enable to decrease sram usage #ifdef mqtt_user if (client.connect(Gateway_Name, mqtt_user, mqtt_password, will_Topic, will_QoS, will_Retain, will_Message)) { // if an mqtt user is defined we connect to the broker with authentication - trc(F("connected with authentication")); #else if (client.connect(Gateway_Name, will_Topic, will_QoS, will_Retain, will_Message)) { - trc(F("connected without authentication")); #endif + trc(F("connected to MQTT broker")); // Once connected, publish an announcement... client.publish(will_Topic,Gateway_AnnouncementMsg); //Subscribing to topic - if (client.subscribe(subjectMQTTtoX) && client.subscribe(subject433toMQTT)) { - trc(F("subscription OK to")); - trc(subjectMQTTtoX); - trc(subject433toMQTT); + if (client.subscribe(subjectMQTTtoX) && client.subscribe(subjectMultiGTWRF)&& client.subscribe(subjectMultiGTWIR)) { + trc(F("subscription OK to the subjects defined")); } } else { trc(F("failed, rc=")); @@ -281,7 +278,7 @@ for (int i=0; i<10;i++){ if (ReceivedSignal[i][0] == value){ long now = millis(); if (now - ReceivedSignal[i][1] < time_avoid_duplicate){ // change - trc(F("don't send the received code")); + trc(F("--------------don't send the received code--------------")); return true; } } @@ -301,7 +298,8 @@ void receivingMQTT(char * topicOri, char * datacallback) { trc(String(data)); // Storing data received - if ((topic == subject433toMQTT)){ + int pos0 = topic.lastIndexOf(subjectMultiGTWKey); + if (pos0 != -1){ trc(F("Storing signal")); storeValue(data); trc(F("Data stored")); diff --git a/User_config.h b/User_config.h index 1886209..163075c 100644 --- a/User_config.h +++ b/User_config.h @@ -63,6 +63,10 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress //MQTT definitions // global MQTT subject listened by the gateway to execute commands (send RF, IR or others) #define subjectMQTTtoX "home/commands/#" +// subject monitored to listen traffic processed by other gateways to store data and avoid ntuple +#define subjectMultiGTWRF "+/433toMQTT" +#define subjectMultiGTWIR "+/IRtoMQTT" +#define subjectMultiGTWKey "toMQTT" //433Mhz MQTT Subjects and keys #define subjectMQTTto433 "home/commands/MQTTto433" @@ -72,8 +76,8 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress #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 //IR MQTT Subjects -#define subjectGTWIRtoMQTT "home/sensors/ir" -#define subjectIRtoMQTT "home/sensors/ir" +#define subjectGTWIRtoMQTT "home/IRtoMQTT" +#define subjectIRtoMQTT "home/IRtoMQTT" #define subjectMQTTtoIR "home/commands/MQTTtoIR" #define subjectIRtoMQTTAdvanced "home/IRtoMQTTAdvanced" /*