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:
1 parent
3e953e49e5
commit
0bbf882b30
2 files changed
+12
-10
No files matched your search
+6
-8
@@ -74,18 +74,15 @@ boolean reconnect() {
|
|||||||
trc(F("Attempting MQTT connection...")); //F function enable to decrease sram usage
|
trc(F("Attempting MQTT connection...")); //F function enable to decrease sram usage
|
||||||
#ifdef mqtt_user
|
#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
|
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
|
#else
|
||||||
if (client.connect(Gateway_Name, will_Topic, will_QoS, will_Retain, will_Message)) {
|
if (client.connect(Gateway_Name, will_Topic, will_QoS, will_Retain, will_Message)) {
|
||||||
trc(F("connected without authentication"));
|
|
||||||
#endif
|
#endif
|
||||||
|
trc(F("connected to MQTT broker"));
|
||||||
// Once connected, publish an announcement...
|
// Once connected, publish an announcement...
|
||||||
client.publish(will_Topic,Gateway_AnnouncementMsg);
|
client.publish(will_Topic,Gateway_AnnouncementMsg);
|
||||||
//Subscribing to topic
|
//Subscribing to topic
|
||||||
if (client.subscribe(subjectMQTTtoX) && client.subscribe(subject433toMQTT)) {
|
if (client.subscribe(subjectMQTTtoX) && client.subscribe(subjectMultiGTWRF)&& client.subscribe(subjectMultiGTWIR)) {
|
||||||
trc(F("subscription OK to"));
|
trc(F("subscription OK to the subjects defined"));
|
||||||
trc(subjectMQTTtoX);
|
|
||||||
trc(subject433toMQTT);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
trc(F("failed, rc="));
|
trc(F("failed, rc="));
|
||||||
@@ -281,7 +278,7 @@ for (int i=0; i<10;i++){
|
|||||||
if (ReceivedSignal[i][0] == value){
|
if (ReceivedSignal[i][0] == value){
|
||||||
long now = millis();
|
long now = millis();
|
||||||
if (now - ReceivedSignal[i][1] < time_avoid_duplicate){ // change
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -301,7 +298,8 @@ void receivingMQTT(char * topicOri, char * datacallback) {
|
|||||||
trc(String(data));
|
trc(String(data));
|
||||||
|
|
||||||
// Storing data received
|
// Storing data received
|
||||||
if ((topic == subject433toMQTT)){
|
int pos0 = topic.lastIndexOf(subjectMultiGTWKey);
|
||||||
|
if (pos0 != -1){
|
||||||
trc(F("Storing signal"));
|
trc(F("Storing signal"));
|
||||||
storeValue(data);
|
storeValue(data);
|
||||||
trc(F("Data stored"));
|
trc(F("Data stored"));
|
||||||
|
|||||||
+6
-2
@@ -63,6 +63,10 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
//MQTT definitions
|
//MQTT definitions
|
||||||
// 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/#"
|
||||||
|
// 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
|
//433Mhz MQTT Subjects and keys
|
||||||
#define subjectMQTTto433 "home/commands/MQTTto433"
|
#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 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 subjectGTWIRtoMQTT "home/sensors/ir"
|
#define subjectGTWIRtoMQTT "home/IRtoMQTT"
|
||||||
#define subjectIRtoMQTT "home/sensors/ir"
|
#define subjectIRtoMQTT "home/IRtoMQTT"
|
||||||
#define subjectMQTTtoIR "home/commands/MQTTtoIR"
|
#define subjectMQTTtoIR "home/commands/MQTTtoIR"
|
||||||
#define subjectIRtoMQTTAdvanced "home/IRtoMQTTAdvanced"
|
#define subjectIRtoMQTTAdvanced "home/IRtoMQTTAdvanced"
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in new issue
Block a user