BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Push notification freeze the communication problem


#1

Hello.
I would like to ask your help.
I’m working on a project, which detect the water level in a waste water tank by a loadcell. The board is UNO, ESP8266-01, loadcell with HX711. Measure the weight of a metal float, as the water is increasing, the weight is going down.
I put a “push notification” in case of any error (high level,…). Everything is working fine, if I put the “//” to remark the push notification line (inaktivate the notification). If I want to use it, the notification is working, but sometimes after 1 hour, sometimes after 5 hours the connection is blocked, with probable the server. The ESP is on the wifi, I can ping it from the PC. On the serial monitor I see it always make ping, the respond time looks OK. But my mobile doesn’t get any datas, and also block the program loop for short times when try to connect maybe (means, less datas written on the serial monitor.)
Previously I tried the email notificatin, that did not work neighter, but the push notification was working.
Please could somebody check, what could be the problem?
Many thanks.
Gábor

    // Loadcell verzió;
    #define BLYNK_PRINT Serial
    #include <ESP8266_Lib.h>
    #include <BlynkSimpleShieldEsp8266.h>
    #include <SoftwareSerial.h>
    #include "HX711.h"
    #define BLYNK_GREEN     "#23C48E"
    #define BLYNK_YELLOW    "#ED9D00"
    #define BLYNK_RED       "#D3435C"
    #define calibration_factor -7050.0
    //#define DOUT  3
    //#define CLK  2

    SoftwareSerial EspSerial(10, 11); // RX, TX
    HX711 scale(3, 2); //DOUT, CLK;

    char auth[] = "3da357bfbf0746f6bc01360dce5f4960";
    char ssid[] = "net";
    char pass[] = "1121314151611";

    ESP8266 wifi(&EspSerial);

    WidgetLED led0(V0);
    WidgetLED led1(V1);
    WidgetLED led4(V4);
    WidgetLED led5(V5);
    WidgetLED led6(V6);
    WidgetLED led7(V7);
    WidgetLED led8(V8);
    WidgetLED led9(V9);

    BlynkTimer timer;

    // Parameters;
    const byte relayPin = 5;  //relé;
    const byte resetPin = 6;  //reset gomb;
    const byte printPin = 7;  //DIP 1 kapcsoló;
    const byte readyPin = 8;  //zöld LED;
    const byte lampPin = 9;  //piros LED;
    const byte soundPin = 12;  //berregő;
    const int pulseTime = 700; // villogás ciklus;
    const int s1Delay = 100;  // relé-, magashiba késleltetés;
    const long levelTime = 180000; // visszatöltési idő korlát;
    const int fastCLimit = 5; // gyors visszatöltések megengedett száma;

    float mert;
    unsigned int mertTemp;
    float sulymert;
    int vizszint;
    const int sulyuszo = 14;  //gramm;2819
    const int uszohossz = 1310;  //mm;
    const float kiszoritas = 1.8;  //g/mm;
    const int tartaly = 1470;  //mm;
    float cal = 1243;
    float szorzo = 32.39;
    const int szintMagas = 1050;
    float barSzorzo = 0;
    int ciklSzintMax;
    int ciklSzintMaxTemp;
    int ciklSzintMin;
    int ciklSzintMinTemp;
    int szintMin;
    int szintMax;
    int szintBar;
    int mertFilterC = 0;

    // States;
    byte oFlow = 0;
    byte relay = 0;
    byte resetState = 0;
    byte testState = 0;
    byte reseting = 0;
    byte soundEn = 0;
    byte urites = 0;
    byte toltes = 0;
    byte ciklusVeg = 0;

    // Flags;
    byte tempBlynkData = 0;
    byte tempBlynkData2 = 0;
    byte soundStart = 0;
    byte pulse;
    byte notif1 = 0;

    String strOra;
    String strPerc;
    String strMperc;
    String strIdo;

    // Errors;
    byte errRelay = 0;
    byte errRelayMem = 0;
    byte errRelayTemp = 0;
    byte errHighLevel = 0;
    byte errHighLevelMem = 0;
    byte errHighLevelTemp = 0;
    byte errSensorTemp = 0;
    byte errSensor = 0;
    byte errSensorMem = 0;
    byte errFastC = 0;
    byte errFastCMem = 0;
    byte errFastCTemp = 0;
    byte actError = 0;
    byte errMem = 0;

    // Timers, counters;
    unsigned long tKapcs = 0;
    unsigned long tKapcsKi = 0;
    unsigned long blynkMillis = 0;
    unsigned long meresMillis = 0;
    unsigned long errFilter = 0;
    unsigned long errorMillis = 0;
    unsigned long resetMillis = 0;
    unsigned long pMillis = 0;
    unsigned long wMillis = 0;
    unsigned long prevwMillis = 0;
    unsigned int counterCycle = 0;
    long cycleTime = 0;
    unsigned int counterFastC = 0;
    long minCycleTime = 0;
    unsigned long soundMillis = 0;
    unsigned long T1;
    unsigned long ora;
    unsigned long perc;
    unsigned long mPerc;

    void blynkData() {
      if(tempBlynkData == 0) {
        led0.on();

        //aktuális hiba;
        if (actError) {
          led1.setColor(BLYNK_RED);
        }else if (errMem) {
          led1.setColor(BLYNK_YELLOW);
        }else{
          led1.setColor(BLYNK_GREEN);
        }

        Blynk.virtualWrite(V2, vizszint);
        Blynk.virtualWrite(V20, szintBar);



          Serial.println(ciklSzintMaxTemp);
          Serial.println(vizszint);
          Serial.println(ciklSzintMinTemp);
          Serial.print(toltes);
          Serial.println(urites);

          Serial.println(sulymert);
          Serial.println("-------");
          Serial.print(errRelay);
          Serial.print(errFastC);
          Serial.print(errHighLevel);
          Serial.println(errSensor);   
          Serial.print(errRelayMem);
          Serial.print(errFastCMem);
          Serial.print(errHighLevelMem);
          Serial.println(errSensorMem);

        //kontrol;
        led0.off();
        delay(10);
        
      }else if(tempBlynkData == 1) {
        //kontroll;
        led9.setColor(BLYNK_YELLOW);

        //magas szint;
        if (errHighLevel) {
          led4.on();
        }else{
          led4.off();
        }

        //relé;
        if (relay) {
          led5.setColor(BLYNK_GREEN);
        }else{
          led5.setColor(BLYNK_RED);
        }

        //memória relé;
        if (errRelayMem) {
          led6.setColor(BLYNK_RED);
        }else{
          led6.setColor(BLYNK_GREEN);
        }

        //memória gyors;
        if (errFastCMem) {
          led7.setColor(BLYNK_RED);
        }else{
          led7.setColor(BLYNK_GREEN);
        }

        //memória magas;
        if (errHighLevelMem) {
          led8.setColor(BLYNK_RED);
        }else{
          led8.setColor(BLYNK_GREEN);
        }

        //memória szenzor;
        if (errSensorMem) {
          led9.setColor(BLYNK_RED);
        }else{
          led9.setColor(BLYNK_GREEN);
        }

        T1 = errorMillis/1000;
        idoSzamolas();
        Blynk.virtualWrite(V10, strIdo);              //hiba ideje;

        delay(10);
          
      }else if(tempBlynkData == 2) {

        Blynk.virtualWrite(V3, ciklSzintMaxTemp);
        Blynk.virtualWrite(V19, ciklSzintMinTemp);
        
        //futási idő;
        T1 = millis()/1000;
        idoSzamolas();    
        Blynk.virtualWrite(V12, strIdo);

        //futó ciklusidő;
        T1 = (millis() - wMillis)/1000;
        idoSzamolas();  
        Blynk.virtualWrite(V13, strIdo);

        //utolsó ciklusidő;
        T1 = cycleTime/1000;
        idoSzamolas();  
        Blynk.virtualWrite(V14, strIdo);

        //minimum ciklusidő;
        T1 = minCycleTime/1000;
        idoSzamolas(); 
        Blynk.virtualWrite(V15, strIdo);

        //ciklusok száma;
        Blynk.virtualWrite(V16, counterCycle);
        
        //gyors ciklusok száma;
        Blynk.virtualWrite(V17, counterFastC);

        delay(10);
      }
      tempBlynkData = 0;
      blynkMillis = millis();
    }

    BLYNK_WRITE(V11) {
        int reqButton = param.asInt();
        int reqState;
        tempBlynkData = 1;
    }

    BLYNK_WRITE(V18) {
        int reqButton = param.asInt();
        int reqState;
        tempBlynkData = 2;
    }

    void idoSzamolas() {
      ora = T1/3600;
      perc = (T1 - ora*3600)/60;
      mPerc = T1 - (ora * 3600 + perc * 60);

      if(ora < 10) {
        strOra = "0" + String(ora, DEC);
      }else{
        strOra = String(ora, DEC);
      }

      if(perc < 10) {
        strPerc = "0" + String(perc, DEC);
      }else{
        strPerc = String(perc, DEC);
      }

      if(mPerc < 10) {
        strMperc = "0" + String(mPerc, DEC);
      }else{
        strMperc = String(mPerc, DEC);
      }
      
      strIdo = strOra + ":" + strPerc + ":" + strMperc;
    }

    void notif() {
      if (notif1 == 1){
    //    Blynk.email("ng71fon@gmail.com", "Subject:Csatorna állapot", "Csatorna riasztás!!!");
        Blynk.notify("Csatorna riasztas");
        notif1 = 2;
      }
    }

    void meres() {
      mert = (scale.get_units());

      if (((mert * 100) < (mertTemp + 100)) && ((mert * 100) > (mertTemp - 100)) || (mertFilterC > 0)) {
        mertTemp = mert * 100;
        if ((mert > 1) && ((mertTemp - cal) > 0)) {
          sulymert = ((mertTemp - cal) * szorzo) / 100;
          vizszint = int (((sulyuszo - sulymert) / kiszoritas) + (tartaly - uszohossz));
          mertFilterC = 0;
        }
      }else{
        mertFilterC++;
      }
      
      Serial.print("mert ");
      Serial.println(mert);
    }

    void tulcsordulas() {
      if ((millis() + 500) < millis()){
        oFlow = 1;
      }else{
        oFlow = 0;
      }

      if (oFlow == 1) {
        digitalWrite(readyPin, HIGH);
        digitalWrite(lampPin, HIGH);
        digitalWrite(soundPin, HIGH);
        delay (700);
        resetMillis = 0;
        pMillis = 0;
        wMillis = 0;
        prevwMillis = 0;
        soundMillis = 0;
        tKapcs = 0;
        tKapcsKi = 0;
      }
    }

    void relekezeles() {
      relay = !(digitalRead (relayPin)); // 0=nincs fázis, 1=OK; 

      if (relay == LOW) { //nincs fázis;
        if (errRelayTemp == 0) {
          errRelay = HIGH;
          errRelayMem = HIGH;
          errorMillis = millis();
          errRelayTemp = 1;
          soundEn = 1;
    //      pr = 1;
        }
      }else{
        errRelay = LOW;
        errRelayTemp = 0;
      }
    }

    void resetkezeles() {
      resetState = !(digitalRead(resetPin)); // 0=nincs megnyomva, 1=megnyomva;

      if (resetState == HIGH) {
        soundEn = 0;
      }
          
      if (resetState == LOW) {       //nincs megnyomva;
        reseting = 0;
        testState = 0;
        resetMillis = millis();
      }
      
      if (millis() > (resetMillis + 2000)) {
        reseting = 1;  
      }

      if (millis() > (resetMillis + 5000)) {
        testState = 1;
      }
      
      if (resetState == HIGH) {
    //    pr = 1;
      }

      if(reseting == 1) {
        errRelayMem = LOW;
        errFastCMem = LOW;
        errHighLevelMem = LOW;
        errSensorMem = LOW;
        errorMillis = 0;
        counterFastC = 0;
        minCycleTime = 0;     
        soundMillis = 0;  
        soundStart = LOW;
        reseting = 0;
      }
    }

    void szintkezeles() {
      if (vizszint  > 0) {
        if ((urites == 0) && ( toltes == 0)) {
          if (ciklSzintMinTemp == 0) {
            ciklSzintMinTemp = vizszint;
          }

          if (ciklSzintMaxTemp == 0) {
            ciklSzintMaxTemp = vizszint;
          }

          if (vizszint > (ciklSzintMinTemp + 40)) {
            toltes = 1;
          }

          if (vizszint < (ciklSzintMaxTemp - 40)) {
            urites = 1;
          }     
        }

        if ((toltes == 1) && (urites == 0)) {
          ciklSzintMinTemp = vizszint;

          if (vizszint > ciklSzintMaxTemp) {
            ciklSzintMaxTemp = vizszint;
          }
          
          if (vizszint < (ciklSzintMaxTemp - 40)) {
            urites = 1;
            ciklSzintMax = ciklSzintMaxTemp;
          }      
        }
      
        if ((toltes == 1) && (urites == 1)) {
          ciklusVeg = 1;     
        }
      
        if ((toltes == 0) && (urites == 1)) {
          ciklSzintMaxTemp = vizszint;
         if (vizszint < ciklSzintMinTemp) {
           ciklSzintMinTemp = vizszint;
        }
          
        if (vizszint > (ciklSzintMinTemp + 40)) {
          toltes = 1;
          urites = 0;
          ciklSzintMin = ciklSzintMinTemp;
        }
      }

      szintBar = (vizszint - ciklSzintMin) * (1023/(szintMagas - ciklSzintMin));
      
        // Magas szint kezelés;
        if (vizszint >= szintMagas) {
          if (errHighLevelTemp == 0) {
            errHighLevel = HIGH;
            errHighLevelMem = HIGH;
            errorMillis = millis();
            errHighLevelTemp = 1;
            soundEn = 1;
          }    
        }else{
          errHighLevel = LOW;
          errHighLevelTemp = 0;
        }
      }
    }

    void ciklusido() {
      if (ciklusVeg == 1) {
        counterCycle++;
        wMillis = millis();
        cycleTime = wMillis - prevwMillis;

        if (cycleTime < levelTime) {
          counterFastC++;
        }

        if (cycleTime >= levelTime) {
          counterFastC = 0;
        }
        ciklusVeg = 0;
        prevwMillis = wMillis;
      }

      if ((minCycleTime > cycleTime) || (minCycleTime == 0)) {
        if ((cycleTime > 5000)){
          minCycleTime = cycleTime;
        }
      }
    }

    void hibakezeles() {
       // Gyors ciklus hiba;
      if (counterFastC >= fastCLimit) {
        if (errFastCTemp == 0) {
          errFastC = HIGH;
          errFastCMem = HIGH;
          errFastCTemp = 1;
          soundEn = 1;
          errorMillis = millis();
    //      pr = 1;
        }
      }else{
        errFastC = LOW;
        errFastCTemp = 0;
      }

      // Szenzor hiba;
      if (millis() > 5000) {
        if ((sulymert > (sulyuszo + 200)) || ((sulymert < 5) && (sulymert > 0))) {
    //    if ((sulymert > (sulyuszo + 200)) || (sulymert < 1800)) {
          if (errSensorTemp == 0) {
            errSensor = HIGH;
            errSensorMem = HIGH;
            errorMillis = millis();
            errSensorTemp = 1;
            soundEn = 1;
          }
        }else{
          errSensor = LOW;
          errSensorTemp = 0;
        }
      }
      
      if ((errRelay == HIGH) || (errHighLevel == HIGH) || (errFastC == HIGH) || ( errSensor == HIGH)) {
        actError = 1;
        if (notif1 == 0) {
          notif1 = 1;
          notif();
        }
      }else{
        actError = 0;
        
        if (notif1 == 2) {
          notif1 = 0;
        }
      }

      if ((errRelayMem == HIGH) || (errHighLevelMem == HIGH) || (errFastCMem == HIGH) || (errSensorMem == HIGH)) {
        errMem = 1;
      }else{
        errMem = 0;
      }
    }

    void kimenetek() {
      // Villogtatás pulzus;
      if ((millis() - pMillis) > pulseTime) {
        pMillis = millis();
        if (pulse == LOW)
          pulse = HIGH;
        else
          pulse = LOW;
      }
      
      if (testState == 1) {
        digitalWrite(readyPin, HIGH);
        digitalWrite(lampPin, HIGH);
        digitalWrite(soundPin, pulse);
      }
      
      if (testState == 0) {
        if (actError == 1) {
          digitalWrite(lampPin, pulse);
          digitalWrite(readyPin, LOW);
        }else{
          if (errMem == 1) {
            digitalWrite(lampPin, HIGH);
            digitalWrite(readyPin, LOW);
          }else{
            digitalWrite(lampPin, LOW);
            digitalWrite(readyPin, HIGH);
          }
        }

        if ((actError == 1) && (millis() > errorMillis) && (millis() < (errorMillis + 30000)) && (resetState == LOW) && (soundEn == HIGH)){
          soundStart = HIGH;
        }else{
          soundStart = LOW;
        }

        if (soundStart == HIGH) {
          digitalWrite(soundPin, pulse);
        }else{
          digitalWrite(soundPin, LOW);
        }
      }

      if ((errRelay == LOW) && (errHighLevel == LOW) && (errFastC == LOW) && (errSensor == LOW)) {
        actError = 0;
      }
    }

    void setup(){
      pinMode(relayPin, INPUT);
      pinMode(resetPin, INPUT);
      pinMode(readyPin, OUTPUT);
      pinMode(lampPin, OUTPUT);
      pinMode(soundPin, OUTPUT);
      pinMode(printPin, INPUT);
      scale.set_scale(calibration_factor);
      Serial.begin(9600);
      EspSerial.begin(9600);
      delay(10);

      Blynk.begin(auth, wifi, ssid, pass);

      led1.on();
      led5.on();
      led6.on();
      led7.on();
      led8.on();
      led9.on();

    //  timer.setInterval(20000L, notif);
      timer.setInterval(8000L, blynkData);
      timer.setInterval(500L, tulcsordulas);
      timer.setInterval(1200L, relekezeles);
      timer.setInterval(500L, resetkezeles);
      timer.setInterval(1000L, meres);
      timer.setInterval(500L, szintkezeles);
      timer.setInterval(1000L, ciklusido);
      timer.setInterval(500L, hibakezeles);
      timer.setInterval(500L, kimenetek);
    }

    void loop(){
      Blynk.run();
      timer.run();
    }


#2

This picture shows the probem, when ping always:

This picture i in normal working:


#3

You have a lot of timers that will periodically coincide in their function calls. I recommend spacing out the times to lessen that.

EG…

A timer set for 1 second will always run it’s function call at same time as any other timer with 1 second resolution.

Timers with 10 and 60 second settings will coincide 6 times in the span of an hour, etc.


#4

Thanks for your answer.
I put the function calls into bigger groups to reduce the timers. Give the ESP 3,3V directly from the 9VDC adapter through AMS1117 (not from the UNO output). If I put email and blynk notification also, after wifi connection the program blocked, no communication with Blynk server. If I put // in fornt of the email, only blynk notification is in the program, it start to work, but after some hours (last time ~20 hours) loose the Blynk server, always try ping (the ping times are OK).
I put to a MEGA board, everything is working, even email and notification together also…
Probable it will be the final solution.
Thanks.


#5

That’s interesting. When you compile the code for an Arduino, what does the compiler say about how much memory is used/available?

Pete.


#6

I tried 2pcs of UNO. Both used 24110 byte (74%) storage from 32256 and 1415 byte (69%) dynamic from 2048.
On Mega 24980 byte (9%) storage from 253952 and 1415 byte (17%) dynamic from 8192.
All of the boards are from ebay, but they are working 2-3 years OK.