decrease code size again

This commit is contained in:
1technophile committed 2017-06-02 23:54:01 +02:00
1 parent 77aff42a27
commit 7382e19f67
3 files changed
+13 -13

No files matched your search

+6 -6
View File
@@ -76,7 +76,7 @@ boolean reconnect() {
#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)) {
#endif #endif
trc(F("connected to MQTT broker")); trc(F("connected to broker"));
// Once connected, publish an announcement... // Once connected, publish an announcement...
client.publish(will_Topic,Gateway_AnnouncementMsg,will_Retain); client.publish(will_Topic,Gateway_AnnouncementMsg,will_Retain);
//Subscribing to topic //Subscribing to topic
@@ -86,7 +86,7 @@ boolean reconnect() {
} else { } else {
trc(F("failed, rc=")); trc(F("failed, rc="));
trc(String(client.state())); trc(String(client.state()));
trc(F(" try again in 5 seconds")); trc(F("try again in 5s"));
// Wait 5 seconds before retrying // Wait 5 seconds before retrying
delay(5000); delay(5000);
} }
@@ -217,14 +217,14 @@ void storeValue(long MQTTvalue){
unsigned long now = millis(); unsigned long now = millis();
// find oldest value of the buffer // find oldest value of the buffer
int o = getMin(); int o = getMin();
trc(F("Minimum index: ")); trc(F("Min index: "));
trc(String(o)); trc(String(o));
// replace it by the new one // replace it by the new one
ReceivedSignal[o][0] = MQTTvalue; ReceivedSignal[o][0] = MQTTvalue;
ReceivedSignal[o][1] = now; ReceivedSignal[o][1] = now;
trc(F("store this code :")); trc(F("store code :"));
trc(String(ReceivedSignal[o][0])+"/"+String(ReceivedSignal[o][1])); trc(String(ReceivedSignal[o][0])+"/"+String(ReceivedSignal[o][1]));
trc(F("Col: value/timestamp")); trc(F("Col: val/timestamp"));
for (int i = 0; i < array_size; i++) for (int i = 0; i < array_size; i++)
{ {
trc(String(i) + ":" + String(ReceivedSignal[i][0])+"/"+String(ReceivedSignal[i][1])); trc(String(i) + ":" + String(ReceivedSignal[i][0])+"/"+String(ReceivedSignal[i][1]));
@@ -251,7 +251,7 @@ for (int i = 0; i < array_size;i++){
if (ReceivedSignal[i][0] == value){ if (ReceivedSignal[i][0] == value){
unsigned long now = millis(); unsigned 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 publish the received code duplicate--------------")); trc(F("---don't publish the code duplicate---"));
return true; return true;
} }
} }
+2 -2
View File
@@ -67,13 +67,13 @@ boolean IRtoMQTT(){
trc(rawCode); trc(rawCode);
irrecv.resume(); // Receive the next value irrecv.resume(); // Receive the next value
if (pubIRunknownPrtcl == false && MQTTprotocol == "-1"){ // don't publish unknown IR protocol if (pubIRunknownPrtcl == false && MQTTprotocol == "-1"){ // don't publish unknown IR protocol
trc(F("---don't publish the received code unknown protocol---")); trc(F("---don't publish the code unknown protocol---"));
} else if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of RF -->MQTT } else if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of RF -->MQTT
trc(F("Sending adv data to MQTT")); trc(F("Sending adv data to MQTT"));
client.publish(subjectIRtoMQTTprotocol,(char *)MQTTprotocol.c_str()); client.publish(subjectIRtoMQTTprotocol,(char *)MQTTprotocol.c_str());
client.publish(subjectIRtoMQTTbits,(char *)MQTTbits.c_str()); client.publish(subjectIRtoMQTTbits,(char *)MQTTbits.c_str());
client.publish(subjectIRtoMQTTRaw,(char *)rawCode.c_str()); client.publish(subjectIRtoMQTTRaw,(char *)rawCode.c_str());
trc(F("Sending IR to MQTT")); trc(F("Sending IRtoMQTT"));
String value = String(MQTTvalue); String value = String(MQTTvalue);
trc(value); trc(value);
boolean result = client.publish(subjectIRtoMQTT,(char *)value.c_str()); boolean result = client.publish(subjectIRtoMQTT,(char *)value.c_str());
+5 -5
View File
@@ -58,7 +58,7 @@ boolean RFtoMQTT(){
client.publish(subjectRFtoMQTTprotocol,(char *)MQTTprotocol.c_str()); client.publish(subjectRFtoMQTTprotocol,(char *)MQTTprotocol.c_str());
client.publish(subjectRFtoMQTTbits,(char *)MQTTbits.c_str()); client.publish(subjectRFtoMQTTbits,(char *)MQTTbits.c_str());
client.publish(subjectRFtoMQTTlength,(char *)MQTTlength.c_str()); client.publish(subjectRFtoMQTTlength,(char *)MQTTlength.c_str());
trc(F("Sending RF to MQTT")); trc(F("Sending RFtoMQTT"));
String value = String(MQTTvalue); String value = String(MQTTvalue);
trc(value); trc(value);
boolean result = client.publish(subjectRFtoMQTT,(char *)value.c_str()); boolean result = client.publish(subjectRFtoMQTT,(char *)value.c_str());
@@ -106,15 +106,15 @@ void MQTTtoRF(char * topicOri, char * datacallback) {
} }
if ((topic == subjectMQTTtoRF) && (valuePRT == 0) && (valuePLSL == 0) && (valueBITS == 0)){ if ((topic == subjectMQTTtoRF) && (valuePRT == 0) && (valuePLSL == 0) && (valueBITS == 0)){
trc(F("Sending data by RF, default parameters")); trc(F("MQTTtoRF default parameters"));
mySwitch.setProtocol(1,350); mySwitch.setProtocol(1,350);
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("Ack of reception published")); if (result)trc(F("Ack published"));
} else if ((valuePRT != 0) || (valuePLSL != 0)|| (valueBITS != 0)){ } else if ((valuePRT != 0) || (valuePLSL != 0)|| (valueBITS != 0)){
trc(F("Sending data by RF, MQTT parameters")); trc(F("MQTTtoRF user parameters"));
if (valuePRT == 0) valuePRT = 1; if (valuePRT == 0) valuePRT = 1;
if (valuePLSL == 0) valuePLSL = 350; if (valuePLSL == 0) valuePLSL = 350;
if (valueBITS == 0) valueBITS = 24; if (valueBITS == 0) valueBITS = 24;
@@ -126,7 +126,7 @@ void MQTTtoRF(char * topicOri, char * datacallback) {
// Acknowledgement to the GTWRF topic // Acknowledgement to the GTWRF topic
boolean result = client.publish(subjectGTWRFtoMQTT, datacallback);// we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also boolean result = client.publish(subjectGTWRFtoMQTT, datacallback);// we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
if (result){ if (result){
trc(F("Signal sent by RF and ack published")); trc(F("MQTTtoRF OK and ack published"));
trc(String(data)); trc(String(data));
}; };
} }