diff --git a/OpenMQTTGateway.ino b/OpenMQTTGateway.ino index 189bb64..9bd6143 100644 --- a/OpenMQTTGateway.ino +++ b/OpenMQTTGateway.ino @@ -35,7 +35,6 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT */ #include "User_config.h" #include -#include // array to store previous received RFs, IRs codes and their timestamps unsigned long ReceivedSignal[10][2] ={{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}; @@ -244,21 +243,13 @@ return false; void receivingMQTT(char * topicOri, char * datacallback) { - trc(F("Receiving data by MQTT")); - trc(String(topicOri)); - trc(F("Callback value")); - trc(String(datacallback)); - unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295 - trc(F("Converted value to unsigned long")); - trc(String(data)); - if (strstr(topicOri, subjectMultiGTWKey) != NULL) { trc(F("Storing signal")); + unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295 storeValue(data); trc(F("Data stored")); } - #ifdef ZgatewayRF MQTTtoRF(topicOri, datacallback); diff --git a/User_config.h b/User_config.h index ad49943..bdc7f4e 100644 --- a/User_config.h +++ b/User_config.h @@ -43,14 +43,14 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT #define wifi_ssid "wifi ssid" #define wifi_password "wifi password" #else // for arduino + W5100 - const byte mac[] PROGMEM = { 0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95 }; //W5100 ethernet shield mac adress + const byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95 }; //W5100 ethernet shield mac adress #endif -const byte ip[] PROGMEM = { 192, 168, 1, 99 }; //ip adress +const byte ip[] = { 192, 168, 1, 99 }; //ip adress // Advanced network config (optional) if you want to use these parameters uncomment line 158, 172 and comment line 171 of OpenMQTTGateway.ino -const byte gateway[] PROGMEM = { 192, 168, 1, 1 }; //ip adress -const byte Dns[] PROGMEM = { 192, 168, 1, 1 }; //ip adress -const byte subnet[] PROGMEM = { 255, 255, 255, 0 }; //ip adress +const byte gateway[] = { 192, 168, 1, 1 }; //ip adress +const byte Dns[] = { 192, 168, 1, 1 }; //ip adress +const byte subnet[] = { 255, 255, 255, 0 }; //ip adress //Addons and module management, comment the line if you don't use //#define ZsensorDHT @@ -73,7 +73,7 @@ const byte subnet[] PROGMEM = { 255, 255, 255, 0 }; //ip adress #define subjectMQTTtoRF "home/commands/MQTTto433" #define subjectRFtoMQTT "home/433toMQTT" #define subjectGTWRFtoMQTT "home/433toMQTT" -#define subjectRFtoMQTTport "home/433toMQTT/port" +#define subjectRFtoMQTTprotocol "home/433toMQTT/protocol" #define subjectRFtoMQTTbits "home/433toMQTT/bits" #define subjectRFtoMQTTlength "home/433toMQTT/length" #define RFprotocolKey "433_" // protocol will be defined if a subject contains RFprotocolKey followed by a value of 1 digit @@ -82,7 +82,7 @@ const byte subnet[] PROGMEM = { 255, 255, 255, 0 }; //ip adress #define subjectGTWIRtoMQTT "home/IRtoMQTT" #define subjectIRtoMQTT "home/IRtoMQTT" #define subjectMQTTtoIR "home/commands/MQTTtoIR" -#define subjectIRtoMQTTport "home/IRtoMQTT/port" +#define subjectIRtoMQTTprotocol "home/IRtoMQTT/protocol" #define subjectIRtoMQTTbits "home/IRtoMQTT/bits" /* RF supported protocols diff --git a/ZgatewayIR.ino b/ZgatewayIR.ino index 17159d4..8b14155 100644 --- a/ZgatewayIR.ino +++ b/ZgatewayIR.ino @@ -61,16 +61,16 @@ boolean IRtoMQTT(){ if (irrecv.decode(&results)){ trc(F("Receiving IR signal")); unsigned long MQTTvalue = 0; - int MQTTport = 0; - int MQTTbits = 0; + String MQTTprotocol; + String MQTTbits; MQTTvalue = results.value; - MQTTport = results.decode_type; - MQTTbits = results.bits; + MQTTprotocol = String(results.decode_type); + MQTTbits = String(results.bits); irrecv.resume(); // Receive the next value if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of RF -->MQTT trc(F("Sending advanced data to MQTT")); - client.publish(subjectIRtoMQTTport,(char *)MQTTport); - client.publish(subjectIRtoMQTTbits,(char *)MQTTbits); + client.publish(subjectIRtoMQTTprotocol,(char *)MQTTprotocol.c_str()); + client.publish(subjectIRtoMQTTbits,(char *)MQTTbits.c_str()); trc(F("Sending IR to MQTT")); String value = String(MQTTvalue); trc(value); @@ -83,12 +83,7 @@ boolean IRtoMQTT(){ void MQTTtoIR(char * topicOri, char * datacallback) { - trc(F("Receiving data by MQTT")); - trc(F("Callback value")); - trc(String(datacallback)); unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295 - trc(F("Converted value to unsigned long")); - trc(String(data)); // IR DATA ANALYSIS //send received MQTT value by IR signal (example of signal sent data = 1086296175) @@ -133,7 +128,10 @@ void MQTTtoIR(char * topicOri, char * datacallback) { } if (signalSent){ boolean result = client.publish(subjectGTWIRtoMQTT, datacallback); - if (result)trc(F("Acknowedgement of reception published")); + if (result){ + trc(F("Signal below sent by IR and acknowledgment published")); + trc(String(data)); + }; } irrecv.enableIRIn(); // ReStart the IR receiver (if not restarted it is not able to receive data) } diff --git a/ZgatewayRF.ino b/ZgatewayRF.ino index 18a5cdf..5c790db 100644 --- a/ZgatewayRF.ino +++ b/ZgatewayRF.ino @@ -54,19 +54,19 @@ boolean RFtoMQTT(){ if (mySwitch.available()){ trc(F("Receiving 433Mhz signal")); unsigned long MQTTvalue = 0; - int MQTTport = 0; - int MQTTbits = 0; - int MQTTlength = 0; + String MQTTprotocol; + String MQTTbits; + String MQTTlength; MQTTvalue = mySwitch.getReceivedValue(); - MQTTport = mySwitch.getReceivedProtocol(); - MQTTbits = mySwitch.getReceivedBitlength(); - MQTTlength = mySwitch.getReceivedDelay(); + MQTTprotocol = String(mySwitch.getReceivedProtocol()); + MQTTbits = String(mySwitch.getReceivedBitlength()); + MQTTlength = String(mySwitch.getReceivedDelay()); mySwitch.resetAvailable(); if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of RF -->MQTT trc(F("Sending advanced signal to MQTT")); - client.publish(subjectRFtoMQTTport,(char *)MQTTport); - client.publish(subjectRFtoMQTTbits,(char *)MQTTbits); - client.publish(subjectRFtoMQTTlength,(char *)MQTTlength); + client.publish(subjectRFtoMQTTprotocol,(char *)MQTTprotocol.c_str()); + client.publish(subjectRFtoMQTTbits,(char *)MQTTbits.c_str()); + client.publish(subjectRFtoMQTTlength,(char *)MQTTlength.c_str()); trc(F("Sending RF to MQTT")); String value = String(MQTTvalue); trc(value); @@ -78,26 +78,12 @@ boolean RFtoMQTT(){ } void MQTTtoRF(char * topicOri, char * datacallback) { - String topic = topicOri; - trc(F("Receiving data by MQTT")); - trc(topic); - trc(F("Callback value")); - trc(String(datacallback)); unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295 - trc(F("Converted value to unsigned long")); - trc(String(data)); - - // Storing data received - int pos0 = topic.lastIndexOf(subjectMultiGTWKey); - if (pos0 != -1){ - trc(F("Storing signal")); - storeValue(data); - trc(F("Data stored")); - } // RF DATA ANALYSIS //We look into the subject to see if a special RF protocol is defined + String topic = topicOri; int valuePRT = 0; int valuePLSL = 0; int pos = topic.lastIndexOf(RFprotocolKey); @@ -134,7 +120,10 @@ void MQTTtoRF(char * topicOri, char * datacallback) { 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("Signal below sent by RF and acknowledgment published")); + trc(String(data)); + }; } }