Code size reduction for UNO
This commit is contained in:
1 parent
c1242f7c91
commit
1a5d808de9
9 files changed
+113
-112
No files matched your search
@@ -66,7 +66,7 @@ void setupONOFF(){
|
||||
// we acknowledge the sending by publishing the value to an acknowledgement topic
|
||||
pub(subjectGTWONOFFtoMQTT, ONOFFdata);
|
||||
}else{
|
||||
trc(F("MQTTtoONOFF Fail reading from json"));
|
||||
trc(F("MQTTtoONOFF failed json read"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
}else{
|
||||
trc(F("MQTTto2G Fail reading from json"));
|
||||
trc(F("MQTTto2G failed json read"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+32
-34
@@ -75,32 +75,30 @@
|
||||
#define WHYNTER_BITS 32U
|
||||
#endif
|
||||
|
||||
void setupIR()
|
||||
{
|
||||
|
||||
//IR init parameters
|
||||
#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 "));
|
||||
void setupIR(){
|
||||
//IR init parameters
|
||||
#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 "));
|
||||
}
|
||||
|
||||
void IRtoMQTT(){
|
||||
decode_results results;
|
||||
|
||||
|
||||
if (irrecv.decode(&results)){
|
||||
trc(F("Creating IR buffer"));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& IRdata = jsonBuffer.createObject();
|
||||
|
||||
trc(F("Rcv. IR"));
|
||||
trc(F("Creating IR buffer"));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& IRdata = jsonBuffer.createObject();
|
||||
|
||||
trc(F("Rcv. IR"));
|
||||
#ifdef ESP32
|
||||
String taskMessage = "Task running on core ";
|
||||
taskMessage = taskMessage + xPortGetCoreID();
|
||||
@@ -116,18 +114,18 @@ void IRtoMQTT(){
|
||||
String rawCode = "";
|
||||
// Dump data
|
||||
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.
|
||||
rawCode = rawCode + (results.rawbuf[i] * RAWTICK);
|
||||
#else
|
||||
#else
|
||||
rawCode = rawCode + (results.rawbuf[i] * USECPERTICK);
|
||||
#endif
|
||||
#endif
|
||||
if ( i < results.rawlen-1 ) rawCode = rawCode + ","; // ',' not needed on last one
|
||||
}
|
||||
trc(rawCode);
|
||||
IRdata.set("raw", rawCode);
|
||||
// if needed we directly resend the raw code
|
||||
if (RawDirectForward){
|
||||
#ifdef RawDirectForward
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
uint16_t rawsend[results.rawlen];
|
||||
for (uint16_t i = 1; i < results.rawlen; i++) {
|
||||
@@ -139,23 +137,23 @@ void IRtoMQTT(){
|
||||
rawsend[i] = results.rawbuf[i];
|
||||
}
|
||||
irsend.sendRaw(rawsend, results.rawlen, RawFrequency);
|
||||
trc(F("raw signal redirected"));
|
||||
}
|
||||
trc(F("raw redirected"));
|
||||
#endif
|
||||
irrecv.resume(); // Receive the next value
|
||||
unsigned long MQTTvalue = IRdata.get<unsigned long>("value");
|
||||
if (pubIRunknownPrtcl == false && IRdata.get<int>("protocol") == -1){ // don't publish unknown IR protocol
|
||||
trc(F("--no pub. unknown protocol--"));
|
||||
} else if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of RF -->MQTT
|
||||
trc(F("Adv data IRtoMQTT"));
|
||||
trc(F("--no pub unknown prt--"));
|
||||
} else if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of IR -->MQTT
|
||||
trc(F("Adv data IRtoMQTT"));
|
||||
pub(subjectIRtoMQTT,IRdata);
|
||||
trc(F("Store to avoid duplicate"));
|
||||
trc(F("Store val"));
|
||||
storeValue(MQTTvalue);
|
||||
if (repeatIRwMQTT){
|
||||
trc(F("Pub. IR for repeat"));
|
||||
trc(F("Pub. IR for rpt"));
|
||||
pub(subjectMQTTtoIR,MQTTvalue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef simpleReceiving
|
||||
@@ -369,7 +367,7 @@ void IRtoMQTT(){
|
||||
}
|
||||
irrecv.enableIRIn(); // ReStart the IR receiver (if not restarted it is not able to receive data)
|
||||
}else{
|
||||
trc(F("MQTTtoIR Fail reading from json"));
|
||||
trc(F("MQTTtoIR failed json read"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ void MQTTtoPilight(char * topicOri, JsonObject& Pilightdata) {
|
||||
trc(F("MQTTtoPilight msg & protocol ok"));
|
||||
result = rf.send(protocol, message);
|
||||
}else{
|
||||
trc(F("MQTTtoPilight fail reading from json"));
|
||||
trc(F("MQTTtoPilight failed json read"));
|
||||
}
|
||||
|
||||
if (result > 0) {
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ void RFtoMQTT(){
|
||||
RFtoMQTTdiscovery(MQTTvalue);
|
||||
#endif
|
||||
pub(subjectRFtoMQTT,RFdata);
|
||||
trc(F("Store to avoid duplicate"));
|
||||
trc(F("Store val"));
|
||||
storeValue(MQTTvalue);
|
||||
if (repeatRFwMQTT){
|
||||
trc(F("Pub RF for rpt"));
|
||||
|
||||
@@ -263,7 +263,7 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group
|
||||
pub(subjectGTWRF2toMQTT,RF2data);
|
||||
}
|
||||
}else{
|
||||
trc(F("MQTTtoRF2 Fail reading from json"));
|
||||
trc(F("MQTTtoRF2 failed json read"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ bool RFM69toMQTT(void) {
|
||||
trc(F("MQTTtoRFM69 sending failed"));
|
||||
}
|
||||
}else{
|
||||
trc(F("MQTTtoRFM69 Fail reading from json"));
|
||||
trc(F("MQTTtoRFM69 failed json read"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,10 +131,10 @@ void _rfbDecode() {
|
||||
if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of RF -->MQTT
|
||||
trc(F("Adv data SRFBtoMQTT"));
|
||||
pub(subjectSRFBtoMQTT,SRFBdata);
|
||||
trc(F("Store to avoid duplicate"));
|
||||
trc(F("Store val"));
|
||||
storeValue(MQTTvalue);
|
||||
if (repeatSRFBwMQTT){
|
||||
trc(F("Publish SRFB for repeat"));
|
||||
trc(F("Publish SRFB for rpt"));
|
||||
pub(subjectMQTTtoSRFB,SRFBdata);
|
||||
}
|
||||
}
|
||||
|
||||
+73
-70
@@ -317,71 +317,74 @@ void pub(char * topic, char * 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){
|
||||
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){
|
||||
char val[11];
|
||||
sprintf(val, "%lu", payload);
|
||||
client.publish(topic,val);
|
||||
}
|
||||
|
||||
void pub(char * topic, long payload){
|
||||
char val[11];
|
||||
sprintf(val, "%l", payload);
|
||||
client.publish(topic,val);
|
||||
}
|
||||
#ifdef simplePublishing
|
||||
|
||||
void pub(char * topic, double payload){
|
||||
char val[16];
|
||||
sprintf(val, "%d", payload);
|
||||
client.publish(topic,val);
|
||||
}
|
||||
void pub(char * topic, String payload){
|
||||
client.publish(topic,(char *)payload.c_str());
|
||||
}
|
||||
|
||||
void pub(String topic, unsigned long payload){
|
||||
char val[11];
|
||||
sprintf(val, "%lu", payload);
|
||||
client.publish((char *)topic.c_str(),val);
|
||||
}
|
||||
void pub(String topic, String payload){
|
||||
client.publish((char *)topic.c_str(),(char *)payload.c_str());
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
@@ -762,15 +765,15 @@ void setup_wifimanager(bool reset_settings){
|
||||
void setup_ethernet() {
|
||||
if (gateway[0] != 0 || Dns[0]!=0)
|
||||
{
|
||||
trc(F("Advanced ethernet config"));
|
||||
trc(F("Adv eth cfg"));
|
||||
Ethernet.begin(mac, ip, Dns, gateway, subnet);
|
||||
}else{
|
||||
trc(F("Simple ethernet config"));
|
||||
trc(F("Spl eth cfg"));
|
||||
Ethernet.begin(mac, ip);
|
||||
}
|
||||
trc(F("OpenMQTTGateway ip: "));
|
||||
trc(F("ip: "));
|
||||
Serial.println(Ethernet.localIP());
|
||||
trc(F("Ethernet ok"));
|
||||
trc(F("Eth ok"));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -811,7 +814,7 @@ void loop()
|
||||
digitalWrite(led_receive, LOW);
|
||||
digitalWrite(led_info, LOW);
|
||||
digitalWrite(led_send, LOW);
|
||||
|
||||
|
||||
unsigned long now = millis();
|
||||
//MQTT client connexion management
|
||||
if (!client.connected()) { // not connected
|
||||
@@ -1045,18 +1048,18 @@ int getMin(){
|
||||
}
|
||||
|
||||
bool isAduplicate(unsigned long value){
|
||||
trc(F("isAduplicate?"));
|
||||
// check if the value has been already sent during the last time_avoid_duplicate
|
||||
for (int i = 0; i < array_size;i++){
|
||||
if (ReceivedSignal[i][0] == value){
|
||||
unsigned long now = millis();
|
||||
if (now - ReceivedSignal[i][1] < time_avoid_duplicate){ // change
|
||||
trc(F("--don't pub. duplicate--"));
|
||||
return true;
|
||||
trc(F("isAdupl?"));
|
||||
// check if the value has been already sent during the last time_avoid_duplicate
|
||||
for (int i = 0; i < array_size;i++){
|
||||
if (ReceivedSignal[i][0] == value){
|
||||
unsigned long now = millis();
|
||||
if (now - ReceivedSignal[i][1] < time_avoid_duplicate){ // change
|
||||
trc(F("no pub. dupl"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
trc(F("Store signal"));
|
||||
trc(F("Store str"));
|
||||
unsigned long data = 0;
|
||||
#ifdef jsonPublishing
|
||||
if (jsondata.success()) data = jsondata["value"];
|
||||
@@ -1078,7 +1081,7 @@ void receivingMQTT(char * topicOri, char * datacallback) {
|
||||
|
||||
if (data != 0) {
|
||||
storeValue(data);
|
||||
trc(F("Data JSON stored"));
|
||||
trc(F("JSON str"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user