some corrections
value assignments for advanced data progmem not available for esp8266 avoid unecessary storevalue
This commit is contained in:
1 parent
8c174255c4
commit
575eb9063e
4 files changed
+32
-54
No files matched your search
+1
-10
@@ -35,7 +35,6 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT
|
|||||||
*/
|
*/
|
||||||
#include "User_config.h"
|
#include "User_config.h"
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#include <avr/pgmspace.h>
|
|
||||||
|
|
||||||
// array to store previous received RFs, IRs codes and their timestamps
|
// 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}};
|
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,22 +243,14 @@ return false;
|
|||||||
|
|
||||||
void receivingMQTT(char * topicOri, char * datacallback) {
|
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)
|
if (strstr(topicOri, subjectMultiGTWKey) != NULL)
|
||||||
{
|
{
|
||||||
trc(F("Storing signal"));
|
trc(F("Storing signal"));
|
||||||
|
unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295
|
||||||
storeValue(data);
|
storeValue(data);
|
||||||
trc(F("Data stored"));
|
trc(F("Data stored"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef ZgatewayRF
|
#ifdef ZgatewayRF
|
||||||
MQTTtoRF(topicOri, datacallback);
|
MQTTtoRF(topicOri, datacallback);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+7
-7
@@ -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_ssid "wifi ssid"
|
||||||
#define wifi_password "wifi password"
|
#define wifi_password "wifi password"
|
||||||
#else // for arduino + W5100
|
#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
|
#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
|
// 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 gateway[] = { 192, 168, 1, 1 }; //ip adress
|
||||||
const byte Dns[] PROGMEM = { 192, 168, 1, 1 }; //ip adress
|
const byte Dns[] = { 192, 168, 1, 1 }; //ip adress
|
||||||
const byte subnet[] PROGMEM = { 255, 255, 255, 0 }; //ip adress
|
const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
||||||
|
|
||||||
//Addons and module management, comment the line if you don't use
|
//Addons and module management, comment the line if you don't use
|
||||||
//#define ZsensorDHT
|
//#define ZsensorDHT
|
||||||
@@ -73,7 +73,7 @@ const byte subnet[] PROGMEM = { 255, 255, 255, 0 }; //ip adress
|
|||||||
#define subjectMQTTtoRF "home/commands/MQTTto433"
|
#define subjectMQTTtoRF "home/commands/MQTTto433"
|
||||||
#define subjectRFtoMQTT "home/433toMQTT"
|
#define subjectRFtoMQTT "home/433toMQTT"
|
||||||
#define subjectGTWRFtoMQTT "home/433toMQTT"
|
#define subjectGTWRFtoMQTT "home/433toMQTT"
|
||||||
#define subjectRFtoMQTTport "home/433toMQTT/port"
|
#define subjectRFtoMQTTprotocol "home/433toMQTT/protocol"
|
||||||
#define subjectRFtoMQTTbits "home/433toMQTT/bits"
|
#define subjectRFtoMQTTbits "home/433toMQTT/bits"
|
||||||
#define subjectRFtoMQTTlength "home/433toMQTT/length"
|
#define subjectRFtoMQTTlength "home/433toMQTT/length"
|
||||||
#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
|
||||||
@@ -82,7 +82,7 @@ const byte subnet[] PROGMEM = { 255, 255, 255, 0 }; //ip adress
|
|||||||
#define subjectGTWIRtoMQTT "home/IRtoMQTT"
|
#define subjectGTWIRtoMQTT "home/IRtoMQTT"
|
||||||
#define subjectIRtoMQTT "home/IRtoMQTT"
|
#define subjectIRtoMQTT "home/IRtoMQTT"
|
||||||
#define subjectMQTTtoIR "home/commands/MQTTtoIR"
|
#define subjectMQTTtoIR "home/commands/MQTTtoIR"
|
||||||
#define subjectIRtoMQTTport "home/IRtoMQTT/port"
|
#define subjectIRtoMQTTprotocol "home/IRtoMQTT/protocol"
|
||||||
#define subjectIRtoMQTTbits "home/IRtoMQTT/bits"
|
#define subjectIRtoMQTTbits "home/IRtoMQTT/bits"
|
||||||
/*
|
/*
|
||||||
RF supported protocols
|
RF supported protocols
|
||||||
|
|||||||
+10
-12
@@ -61,16 +61,16 @@ boolean IRtoMQTT(){
|
|||||||
if (irrecv.decode(&results)){
|
if (irrecv.decode(&results)){
|
||||||
trc(F("Receiving IR signal"));
|
trc(F("Receiving IR signal"));
|
||||||
unsigned long MQTTvalue = 0;
|
unsigned long MQTTvalue = 0;
|
||||||
int MQTTport = 0;
|
String MQTTprotocol;
|
||||||
int MQTTbits = 0;
|
String MQTTbits;
|
||||||
MQTTvalue = results.value;
|
MQTTvalue = results.value;
|
||||||
MQTTport = results.decode_type;
|
MQTTprotocol = String(results.decode_type);
|
||||||
MQTTbits = results.bits;
|
MQTTbits = String(results.bits);
|
||||||
irrecv.resume(); // Receive the next value
|
irrecv.resume(); // Receive the next 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("Sending advanced data to MQTT"));
|
trc(F("Sending advanced data to MQTT"));
|
||||||
client.publish(subjectIRtoMQTTport,(char *)MQTTport);
|
client.publish(subjectIRtoMQTTprotocol,(char *)MQTTprotocol.c_str());
|
||||||
client.publish(subjectIRtoMQTTbits,(char *)MQTTbits);
|
client.publish(subjectIRtoMQTTbits,(char *)MQTTbits.c_str());
|
||||||
trc(F("Sending IR to MQTT"));
|
trc(F("Sending IR to MQTT"));
|
||||||
String value = String(MQTTvalue);
|
String value = String(MQTTvalue);
|
||||||
trc(value);
|
trc(value);
|
||||||
@@ -83,12 +83,7 @@ boolean IRtoMQTT(){
|
|||||||
|
|
||||||
void MQTTtoIR(char * topicOri, char * datacallback) {
|
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
|
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
|
// IR DATA ANALYSIS
|
||||||
//send received MQTT value by IR signal (example of signal sent data = 1086296175)
|
//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){
|
if (signalSent){
|
||||||
boolean result = client.publish(subjectGTWIRtoMQTT, datacallback);
|
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)
|
irrecv.enableIRIn(); // ReStart the IR receiver (if not restarted it is not able to receive data)
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-25
@@ -54,19 +54,19 @@ boolean RFtoMQTT(){
|
|||||||
if (mySwitch.available()){
|
if (mySwitch.available()){
|
||||||
trc(F("Receiving 433Mhz signal"));
|
trc(F("Receiving 433Mhz signal"));
|
||||||
unsigned long MQTTvalue = 0;
|
unsigned long MQTTvalue = 0;
|
||||||
int MQTTport = 0;
|
String MQTTprotocol;
|
||||||
int MQTTbits = 0;
|
String MQTTbits;
|
||||||
int MQTTlength = 0;
|
String MQTTlength;
|
||||||
MQTTvalue = mySwitch.getReceivedValue();
|
MQTTvalue = mySwitch.getReceivedValue();
|
||||||
MQTTport = mySwitch.getReceivedProtocol();
|
MQTTprotocol = String(mySwitch.getReceivedProtocol());
|
||||||
MQTTbits = mySwitch.getReceivedBitlength();
|
MQTTbits = String(mySwitch.getReceivedBitlength());
|
||||||
MQTTlength = mySwitch.getReceivedDelay();
|
MQTTlength = String(mySwitch.getReceivedDelay());
|
||||||
mySwitch.resetAvailable();
|
mySwitch.resetAvailable();
|
||||||
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("Sending advanced signal to MQTT"));
|
trc(F("Sending advanced signal to MQTT"));
|
||||||
client.publish(subjectRFtoMQTTport,(char *)MQTTport);
|
client.publish(subjectRFtoMQTTprotocol,(char *)MQTTprotocol.c_str());
|
||||||
client.publish(subjectRFtoMQTTbits,(char *)MQTTbits);
|
client.publish(subjectRFtoMQTTbits,(char *)MQTTbits.c_str());
|
||||||
client.publish(subjectRFtoMQTTlength,(char *)MQTTlength);
|
client.publish(subjectRFtoMQTTlength,(char *)MQTTlength.c_str());
|
||||||
trc(F("Sending RF to MQTT"));
|
trc(F("Sending RF to MQTT"));
|
||||||
String value = String(MQTTvalue);
|
String value = String(MQTTvalue);
|
||||||
trc(value);
|
trc(value);
|
||||||
@@ -78,26 +78,12 @@ boolean RFtoMQTT(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MQTTtoRF(char * topicOri, char * datacallback) {
|
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
|
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
|
// RF DATA ANALYSIS
|
||||||
//We look into the subject to see if a special RF protocol is defined
|
//We look into the subject to see if a special RF protocol is defined
|
||||||
|
String topic = topicOri;
|
||||||
int valuePRT = 0;
|
int valuePRT = 0;
|
||||||
int valuePLSL = 0;
|
int valuePLSL = 0;
|
||||||
int pos = topic.lastIndexOf(RFprotocolKey);
|
int pos = topic.lastIndexOf(RFprotocolKey);
|
||||||
@@ -134,7 +120,10 @@ void MQTTtoRF(char * topicOri, char * datacallback) {
|
|||||||
mySwitch.send(data, 24);
|
mySwitch.send(data, 24);
|
||||||
// Acknowledgement to the GTWRF topic
|
// Acknowledgement to the GTWRF topic
|
||||||
boolean result = client.publish(subjectGTWRFtoMQTT, datacallback);
|
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));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user