Code size reduction for UNO

This commit is contained in:
1technophile committed 2019-07-25 10:41:21 +02:00
1 parent c1242f7c91
commit 1a5d808de9
9 files changed
+39 -38

No files matched your search

+1 -1
View File
@@ -66,7 +66,7 @@ void setupONOFF(){
// we acknowledge the sending by publishing the value to an acknowledgement topic // we acknowledge the sending by publishing the value to an acknowledgement topic
pub(subjectGTWONOFFtoMQTT, ONOFFdata); pub(subjectGTWONOFFtoMQTT, ONOFFdata);
}else{ }else{
trc(F("MQTTtoONOFF Fail reading from json")); trc(F("MQTTtoONOFF failed json read"));
} }
} }
} }
+1 -1
View File
@@ -154,7 +154,7 @@ bool _2GtoMQTT(){
pub(subjectGTW2GtoMQTT, "SMS KO");// 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 pub(subjectGTW2GtoMQTT, "SMS KO");// 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
} }
}else{ }else{
trc(F("MQTTto2G Fail reading from json")); trc(F("MQTTto2G failed json read"));
} }
} }
+10 -12
View File
@@ -75,9 +75,7 @@
#define WHYNTER_BITS 32U #define WHYNTER_BITS 32U
#endif #endif
void setupIR() void setupIR(){
{
//IR init parameters //IR init parameters
#if defined(ESP8266) || defined(ESP32) #if defined(ESP8266) || defined(ESP32)
irsend.begin(); irsend.begin();
@@ -90,8 +88,8 @@ trc(IR_EMITTER_PIN);
trc(F("IR_RECEIVER_PIN ")); trc(F("IR_RECEIVER_PIN "));
trc(IR_RECEIVER_PIN); trc(IR_RECEIVER_PIN);
trc(F("ZgatewayIR setup done ")); trc(F("ZgatewayIR setup done "));
} }
void IRtoMQTT(){ void IRtoMQTT(){
decode_results results; decode_results results;
@@ -127,7 +125,7 @@ void IRtoMQTT(){
trc(rawCode); trc(rawCode);
IRdata.set("raw", rawCode); IRdata.set("raw", rawCode);
// if needed we directly resend the raw code // if needed we directly resend the raw code
if (RawDirectForward){ #ifdef RawDirectForward
#if defined(ESP8266) || defined(ESP32) #if defined(ESP8266) || defined(ESP32)
uint16_t rawsend[results.rawlen]; uint16_t rawsend[results.rawlen];
for (uint16_t i = 1; i < results.rawlen; i++) { for (uint16_t i = 1; i < results.rawlen; i++) {
@@ -139,19 +137,19 @@ void IRtoMQTT(){
rawsend[i] = results.rawbuf[i]; rawsend[i] = results.rawbuf[i];
} }
irsend.sendRaw(rawsend, results.rawlen, RawFrequency); irsend.sendRaw(rawsend, results.rawlen, RawFrequency);
trc(F("raw signal redirected")); trc(F("raw redirected"));
} #endif
irrecv.resume(); // Receive the next value irrecv.resume(); // Receive the next value
unsigned long MQTTvalue = IRdata.get<unsigned long>("value"); unsigned long MQTTvalue = IRdata.get<unsigned long>("value");
if (pubIRunknownPrtcl == false && IRdata.get<int>("protocol") == -1){ // don't publish unknown IR protocol if (pubIRunknownPrtcl == false && IRdata.get<int>("protocol") == -1){ // don't publish unknown IR protocol
trc(F("--no pub. unknown protocol--")); trc(F("--no pub unknown prt--"));
} else if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of RF -->MQTT } else if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of IR -->MQTT
trc(F("Adv data IRtoMQTT")); trc(F("Adv data IRtoMQTT"));
pub(subjectIRtoMQTT,IRdata); pub(subjectIRtoMQTT,IRdata);
trc(F("Store to avoid duplicate")); trc(F("Store val"));
storeValue(MQTTvalue); storeValue(MQTTvalue);
if (repeatIRwMQTT){ if (repeatIRwMQTT){
trc(F("Pub. IR for repeat")); trc(F("Pub. IR for rpt"));
pub(subjectMQTTtoIR,MQTTvalue); pub(subjectMQTTtoIR,MQTTvalue);
} }
} }
@@ -369,7 +367,7 @@ void IRtoMQTT(){
} }
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)
}else{ }else{
trc(F("MQTTtoIR Fail reading from json")); trc(F("MQTTtoIR failed json read"));
} }
} }
} }
+1 -1
View File
@@ -110,7 +110,7 @@ void MQTTtoPilight(char * topicOri, JsonObject& Pilightdata) {
trc(F("MQTTtoPilight msg & protocol ok")); trc(F("MQTTtoPilight msg & protocol ok"));
result = rf.send(protocol, message); result = rf.send(protocol, message);
}else{ }else{
trc(F("MQTTtoPilight fail reading from json")); trc(F("MQTTtoPilight failed json read"));
} }
if (result > 0) { if (result > 0) {
+1 -1
View File
@@ -88,7 +88,7 @@ void RFtoMQTT(){
RFtoMQTTdiscovery(MQTTvalue); RFtoMQTTdiscovery(MQTTvalue);
#endif #endif
pub(subjectRFtoMQTT,RFdata); pub(subjectRFtoMQTT,RFdata);
trc(F("Store to avoid duplicate")); trc(F("Store val"));
storeValue(MQTTvalue); storeValue(MQTTvalue);
if (repeatRFwMQTT){ if (repeatRFwMQTT){
trc(F("Pub RF for rpt")); trc(F("Pub RF for rpt"));
+1 -1
View File
@@ -263,7 +263,7 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group
pub(subjectGTWRF2toMQTT,RF2data); pub(subjectGTWRF2toMQTT,RF2data);
} }
}else{ }else{
trc(F("MQTTtoRF2 Fail reading from json")); trc(F("MQTTtoRF2 failed json read"));
} }
} }
} }
+1 -1
View File
@@ -231,7 +231,7 @@ bool RFM69toMQTT(void) {
trc(F("MQTTtoRFM69 sending failed")); trc(F("MQTTtoRFM69 sending failed"));
} }
}else{ }else{
trc(F("MQTTtoRFM69 Fail reading from json")); trc(F("MQTTtoRFM69 failed json read"));
} }
} }
} }
+2 -2
View File
@@ -131,10 +131,10 @@ void _rfbDecode() {
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("Adv data SRFBtoMQTT")); trc(F("Adv data SRFBtoMQTT"));
pub(subjectSRFBtoMQTT,SRFBdata); pub(subjectSRFBtoMQTT,SRFBdata);
trc(F("Store to avoid duplicate")); trc(F("Store val"));
storeValue(MQTTvalue); storeValue(MQTTvalue);
if (repeatSRFBwMQTT){ if (repeatSRFBwMQTT){
trc(F("Publish SRFB for repeat")); trc(F("Publish SRFB for rpt"));
pub(subjectMQTTtoSRFB,SRFBdata); pub(subjectMQTTtoSRFB,SRFBdata);
} }
} }
+21 -18
View File
@@ -317,6 +317,18 @@ void pub(char * topic, char * payload){
client.publish(topic, payload); client.publish(topic, payload);
} }
void pub(String topic, char * payload){
client.publish((char *)topic.c_str(),payload);
}
void pub(char * topic, unsigned long payload){
char val[11];
sprintf(val, "%lu", payload);
client.publish(topic,val);
}
#ifdef simplePublishing
void pub(char * topic, String payload){ void pub(char * topic, String payload){
client.publish(topic,(char *)payload.c_str()); client.publish(topic,(char *)payload.c_str());
} }
@@ -325,10 +337,6 @@ void pub(String topic, String payload){
client.publish((char *)topic.c_str(),(char *)payload.c_str()); client.publish((char *)topic.c_str(),(char *)payload.c_str());
} }
void pub(String topic, char * payload){
client.publish((char *)topic.c_str(),payload);
}
void pub(String topic, int payload){ void pub(String topic, int payload){
char val[12]; char val[12];
sprintf(val, "%d", payload); sprintf(val, "%d", payload);
@@ -359,12 +367,6 @@ void pub(char * topic, unsigned int payload){
client.publish(topic,val); client.publish(topic,val);
} }
void pub(char * topic, unsigned long payload){
char val[11];
sprintf(val, "%lu", payload);
client.publish(topic,val);
}
void pub(char * topic, long payload){ void pub(char * topic, long payload){
char val[11]; char val[11];
sprintf(val, "%l", payload); sprintf(val, "%l", payload);
@@ -382,6 +384,7 @@ void pub(String topic, unsigned long payload){
sprintf(val, "%lu", payload); sprintf(val, "%lu", payload);
client.publish((char *)topic.c_str(),val); client.publish((char *)topic.c_str(),val);
} }
#endif
bool reconnect() { bool reconnect() {
@@ -762,15 +765,15 @@ void setup_wifimanager(bool reset_settings){
void setup_ethernet() { void setup_ethernet() {
if (gateway[0] != 0 || Dns[0]!=0) if (gateway[0] != 0 || Dns[0]!=0)
{ {
trc(F("Advanced ethernet config")); trc(F("Adv eth cfg"));
Ethernet.begin(mac, ip, Dns, gateway, subnet); Ethernet.begin(mac, ip, Dns, gateway, subnet);
}else{ }else{
trc(F("Simple ethernet config")); trc(F("Spl eth cfg"));
Ethernet.begin(mac, ip); Ethernet.begin(mac, ip);
} }
trc(F("OpenMQTTGateway ip: ")); trc(F("ip: "));
Serial.println(Ethernet.localIP()); Serial.println(Ethernet.localIP());
trc(F("Ethernet ok")); trc(F("Eth ok"));
} }
#endif #endif
@@ -1045,13 +1048,13 @@ int getMin(){
} }
bool isAduplicate(unsigned long value){ bool isAduplicate(unsigned long value){
trc(F("isAduplicate?")); trc(F("isAdupl?"));
// check if the value has been already sent during the last time_avoid_duplicate // check if the value has been already sent during the last time_avoid_duplicate
for (int i = 0; i < array_size;i++){ 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 pub. duplicate--")); trc(F("no pub. dupl"));
return true; return true;
} }
} }
@@ -1066,7 +1069,7 @@ void receivingMQTT(char * topicOri, char * datacallback) {
if (strstr(topicOri, subjectMultiGTWKey) != NULL) // storing received value so as to avoid publishing this value if it has been already sent by this or another OpenMQTTGateway if (strstr(topicOri, subjectMultiGTWKey) != NULL) // storing received value so as to avoid publishing this value if it has been already sent by this or another OpenMQTTGateway
{ {
trc(F("Store signal")); trc(F("Store str"));
unsigned long data = 0; unsigned long data = 0;
#ifdef jsonPublishing #ifdef jsonPublishing
if (jsondata.success()) data = jsondata["value"]; if (jsondata.success()) data = jsondata["value"];
@@ -1078,7 +1081,7 @@ void receivingMQTT(char * topicOri, char * datacallback) {
if (data != 0) { if (data != 0) {
storeValue(data); storeValue(data);
trc(F("Data JSON stored")); trc(F("JSON str"));
} }
} }