Allow multiple gateways installation to remove duplicate with different topics "hom"

and remove duplicate for IR and when there is multiple gateways
This commit is contained in:
1technophile committed 2017-04-13 21:14:16 +02:00
1 parent 3e953e49e5
commit 0bbf882b30
2 files changed
+12 -10

No files matched your search

+6 -8
View File
@@ -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"));
+6 -2
View File
@@ -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"
/*