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
+108 -107

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"));
} }
} }
+28 -30
View File
@@ -75,32 +75,30 @@
#define WHYNTER_BITS 32U #define WHYNTER_BITS 32U
#endif #endif
void setupIR() void setupIR(){
{ //IR init parameters
#if defined(ESP8266) || defined(ESP32)
irsend.begin();
#endif
//IR init parameters irrecv.enableIRIn(); // Start the receiver
#if defined(ESP8266) || defined(ESP32)
irsend.begin();
#endif
irrecv.enableIRIn(); // Start the receiver
trc(F("IR_EMITTER_PIN "));
trc(IR_EMITTER_PIN);
trc(F("IR_RECEIVER_PIN "));
trc(IR_RECEIVER_PIN);
trc(F("ZgatewayIR setup done "));
trc(F("IR_EMITTER_PIN "));
trc(IR_EMITTER_PIN);
trc(F("IR_RECEIVER_PIN "));
trc(IR_RECEIVER_PIN);
trc(F("ZgatewayIR setup done "));
} }
void IRtoMQTT(){ void IRtoMQTT(){
decode_results results; decode_results results;
if (irrecv.decode(&results)){ if (irrecv.decode(&results)){
trc(F("Creating IR buffer")); trc(F("Creating IR buffer"));
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer; StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
JsonObject& IRdata = jsonBuffer.createObject(); JsonObject& IRdata = jsonBuffer.createObject();
trc(F("Rcv. IR")); trc(F("Rcv. IR"));
#ifdef ESP32 #ifdef ESP32
String taskMessage = "Task running on core "; String taskMessage = "Task running on core ";
taskMessage = taskMessage + xPortGetCoreID(); taskMessage = taskMessage + xPortGetCoreID();
@@ -116,18 +114,18 @@ void IRtoMQTT(){
String rawCode = ""; String rawCode = "";
// Dump data // Dump data
for (uint16_t i = 1; i < results.rawlen; i++) { for (uint16_t i = 1; i < results.rawlen; i++) {
#if defined(ESP8266) || defined(ESP32) #if defined(ESP8266) || defined(ESP32)
if (i % 100 == 0) yield(); // Preemptive yield every 100th entry to feed the WDT. if (i % 100 == 0) yield(); // Preemptive yield every 100th entry to feed the WDT.
rawCode = rawCode + (results.rawbuf[i] * RAWTICK); rawCode = rawCode + (results.rawbuf[i] * RAWTICK);
#else #else
rawCode = rawCode + (results.rawbuf[i] * USECPERTICK); rawCode = rawCode + (results.rawbuf[i] * USECPERTICK);
#endif #endif
if ( i < results.rawlen-1 ) rawCode = rawCode + ","; // ',' not needed on last one if ( i < results.rawlen-1 ) rawCode = rawCode + ","; // ',' not needed on last one
} }
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,23 +137,23 @@ 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);
} }
} }
} }
} }
#ifdef simpleReceiving #ifdef simpleReceiving
@@ -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);
} }
} }
+72 -69
View File
@@ -317,71 +317,74 @@ void pub(char * topic, char * payload){
client.publish(topic, payload); client.publish(topic, payload);
} }
void pub(char * topic, String payload){
client.publish(topic,(char *)payload.c_str());
}
void pub(String topic, String payload){
client.publish((char *)topic.c_str(),(char *)payload.c_str());
}
void pub(String topic, char * payload){ void pub(String topic, char * payload){
client.publish((char *)topic.c_str(),payload); client.publish((char *)topic.c_str(),payload);
} }
void pub(String topic, int payload){
char val[12];
sprintf(val, "%d", payload);
client.publish((char *)topic.c_str(),val);
}
void pub(String topic, float payload){
char val[12];
dtostrf(payload,3,1,val);
client.publish((char *)topic.c_str(),val);
}
void pub(char * topic, float payload){
char val[12];
dtostrf(payload,3,1,val);
client.publish(topic,val);
}
void pub(char * topic, int payload){
char val[6];
sprintf(val, "%d", payload);
client.publish(topic,val);
}
void pub(char * topic, unsigned int payload){
char val[6];
sprintf(val, "%u", payload);
client.publish(topic,val);
}
void pub(char * topic, unsigned long payload){ void pub(char * topic, unsigned long payload){
char val[11]; char val[11];
sprintf(val, "%lu", payload); sprintf(val, "%lu", payload);
client.publish(topic,val); client.publish(topic,val);
} }
void pub(char * topic, long payload){ #ifdef simplePublishing
char val[11];
sprintf(val, "%l", payload);
client.publish(topic,val);
}
void pub(char * topic, double payload){ void pub(char * topic, String payload){
char val[16]; client.publish(topic,(char *)payload.c_str());
sprintf(val, "%d", payload); }
client.publish(topic,val);
}
void pub(String topic, unsigned long payload){ void pub(String topic, String payload){
char val[11]; client.publish((char *)topic.c_str(),(char *)payload.c_str());
sprintf(val, "%lu", payload); }
client.publish((char *)topic.c_str(),val);
} void pub(String topic, int payload){
char val[12];
sprintf(val, "%d", payload);
client.publish((char *)topic.c_str(),val);
}
void pub(String topic, float payload){
char val[12];
dtostrf(payload,3,1,val);
client.publish((char *)topic.c_str(),val);
}
void pub(char * topic, float payload){
char val[12];
dtostrf(payload,3,1,val);
client.publish(topic,val);
}
void pub(char * topic, int payload){
char val[6];
sprintf(val, "%d", payload);
client.publish(topic,val);
}
void pub(char * topic, unsigned int payload){
char val[6];
sprintf(val, "%u", payload);
client.publish(topic,val);
}
void pub(char * topic, long payload){
char val[11];
sprintf(val, "%l", payload);
client.publish(topic,val);
}
void pub(char * topic, double payload){
char val[16];
sprintf(val, "%d", payload);
client.publish(topic,val);
}
void pub(String topic, unsigned long payload){
char val[11];
sprintf(val, "%lu", payload);
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,18 +1048,18 @@ 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;
}
} }
} }
} return false;
return false;
} }
void receivingMQTT(char * topicOri, char * datacallback) { void receivingMQTT(char * topicOri, char * datacallback) {
@@ -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"));
} }
} }