App not communicating with hardware

Hello Dears,
I have developed a smart home hardware which was running perfectly on an ESP32 module but from last two days, my Blynk app has become non-responsive. App shows the device is connected but when I send any command from the app it does not reach the hardware.

The hardware, ESP32, has been programmed through Arduino IDE and Blynk Provisioning(a preview version).

Any help would be appreciable.

Thanks

Sarwar

What has changed in the last 2 days?

What Blynk library version are you using?

Local server or Cloud server?

What does your serial monitor show when you boot your ESP32?

Pete.

Dear Pete. Thanks for your quickest response.
Infact, nothing changed. Device has been working functionally OK. The only thing that I have been observing initially was the device lost connection after EIGHT/TEN hours. I had to restart the device to get it connected again. This problem was not solved yet but then came another.
I am using Cloud Server and the library version is 0.6.1
And here is what I receive on my Serial monitor:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9232
load:0x40080400,len:6400
entry 0x400806a8
[159]
[159] Hardware v1.0.0
[159] Firmware v1.0.1
[161] WAIT_CONFIG => CONNECTING_NET
[274] Connecting to WiFi: ******************
[486] CONNECTING_NET => CONNECTING_CLOUD
[488] Disconnected
[488]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.6.1 on ESP32

[493] Connecting to blynk-cloud.com:80
[917] Ready (ping: 223ms).
[1187] CONNECTING_CLOUD => RUNNING


Sarwar

I think you need to post your code.
Don’t forget to use triple backticks at the beginning and end of the code so that it displays correctly.
Triple backticks look like this:

```

Pete.

Dear Pete,
I appreciate your concern and fault has been traced.
I remember, the fault had been observed ever since I had updated my android blynk app about three days back. I deleted my preview app and rebuilt the app and problem gone.
But the issue of disconnection after eight to ten hours is still there.
Could you please help in this regard?

Sarwar

Last year I have had the same issue, blynk disconnect every 10 or 12 hours, searching here in the forum I’ve found a post describing how to fix this issue but for sorry I don’t have the Link to that post and I write dwon here the code that you should implement … it works for me very fine and I have no more blocks …

/* NoBlynkBlock.ino by Costas for https://community.blynk.cc/t/blynk-is-blocking-if-internet-is-down/16809
will recover from server or router going down   

*/

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char ssid[]   = "xxx";
char pass[]   = "xxx";
char auth[]   = "xxx";
char server[] = "blynk-cloud.com";

BlynkTimer timer;
unsigned int myServerTimeout  =  3500;  //  3.5s server connection timeout (SCT)
unsigned int myWiFiTimeout    =  3200;  //  3.2s WiFi connection timeout   (WCT)
unsigned int functionInterval =  7500;  //  7.5s function call frequency   (FCF)
unsigned int blynkInterval    = 25000;  // 25.0s check server frequency    (CSF)

void setup()
{
  Serial.begin(115200);
  Serial.println();
  if(WiFi.status() == 6){
    Serial.println("\tWiFi not connected yet.");
  }
  timer.setInterval(functionInterval, myfunction);// run some function at intervals per functionInterval
  timer.setInterval(blynkInterval, checkBlynk);   // check connection to server per blynkInterval
  unsigned long startWiFi = millis();
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED){
    delay(500);
    if(millis() > startWiFi + myWiFiTimeout){
      Serial.println("\tCheck the WiFi router. ");
      break;
    }       
  }
  Blynk.config(auth, server);
  checkBlynk();
}

void myfunction(){
  Serial.println("\tLook, no Blynk  block.");
  if(WiFi.status()== 3){
    Serial.println("\tWiFi still  connected.");
  }
  if(Blynk.connected()){
    Blynk.virtualWrite(V11, millis() / 1000);
  }
}

void checkBlynk() {
  if (WiFi.status() == WL_CONNECTED)  
  {
    unsigned long startConnecting = millis();    
    while(!Blynk.connected()){
      Blynk.connect();  
      if(millis() > startConnecting + myServerTimeout){
        Serial.print("Unable to connect to server. ");
        break;
      }
    }
  }
  if (WiFi.status() != 3) {
    Serial.print("\tNo WiFi. ");
  } 
  Serial.printf("\tChecking again in %is.\n", blynkInterval / 1000);
  Serial.println(); 
}

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

Your WiFi code seems quite odd.

In your void setup you check if WiFi is connected before making any connection attempts, then you attempt to connect for 3.2 seconds and if unsuccessful do nothing.

At several other points in your code you check is the WiFi is still connected, but never attempt a re-connection if it is disconnected.

I’d put the WiFi connection code in a funct5ion and call it once from void setup, then again whenever you realise that WiFi is disconnected.

Pete.

Hi Pete,
Your considerations are correct and actually my code is as you said… This code was the template I found from github.

In my running code I removed the first check (if WIFI is connected), has no sense, ODD :slight_smile:

In the two interval timer functions, one function I use to check the if WIFI is active otherwise I activate another timer 1 min if still not availble I send HW reset to the router using a Relay and I wait another 2 min if still not active I restart the ESP.

With the second function I check blynk conecction only if WIFI is available…

Regards
Bek

Why don’t you simply post your actual code, rather than something that isn’t being used, along with a full description of your hardware and how it is being used to control your router?

Pete.

Hi Pete,
Of course, the code is very huge to post but I will try to synthetize it as much as possible.

The project is Remote Home Surveillance for a compound of 15 cameras connetected to 15 wireless 0.9 to 1.4 Ghz AV Transmitters.

The ESP32 controls:

  1. Video receiver using I2C to zap between the 15 channels frequencies
  2. One relay to turn On and Off the Router (Reset)
  3. One relay to turn On and Off the DVR connected to Internet and AV receiver
  4. The DVR receives the AV from the AV Receiver.
  5. From remote I can watch anytime all of the 15 Cameras using Blynk, Firebase, Gsm or by voice over internet with ALEXA on my mobile.

Hardware,
The ESP32 is an TTGO-Tcall with Gsm simcard .
2 Relays board
1 AV Receiver 1.2 Ghz 15 channels
15 Wireless cameras with 15 ch AV Transmitters
RC 433 Transmitter to turn On or Off each single video transmitter

Here is the setup code:

void setup() 
{
//RELE WITH LOW TRIGGER, ON IF LOW AND OFF IF HIGH
     pinMode(NETGEER_PIN_0, OUTPUT);
     pinMode(AV_RX_DVR_PIN_2, OUTPUT);

     digitalWrite(NETGEER_PIN_0, HIGH);  //RELAY IS NC WHEN HIGH POWER ON
     digitalWrite(AV_RX_DVR_PIN_2, HIGH);   //RELAY IS NC WHEN HIGH POWER ON

     Serial.begin(115200);
     
     avReceiver.init_I2C();   //Initialize AV receiver I2C
     
     EEPROM.begin(EEPROM_SIZE);   
     
     initWDG(MIN_5,EN);     //Enable watch dog for 5 min in setup then 1 min in main loop
     
     resetWdg();            //reset timer (feed watchdog) 
     
     sim800Available = sms.init();    //Initialize GSM SIM800
     
     mySwitch.enableTransmit(RC_TX_PIN);  // Initialize the RC 433 mHz transmitter

     smsSent= sms.SendSMS("Sim800 Ok, Connecting to WIFI and Blynk.....");  // Send SMS
     
     myBlynk.init();    //Initialize Blynk
     
     blynkConnected=myBlynk.blynkStatus();    //Get Blynk Status
     
     wifiAvailable = myBlynk.wifiStatus();    //GEt Wifi Status

     //Send SMS
     if (wifiAvailable) {if(smsSent) smsSent= sms.SendSMS("WIFI Connected..");}
     else {if(smsSent) smsSent= sms.SendSMS("WIFI failed to connect");}
          
     if (blynkConnected) {if(smsSent) smsSent= sms.SendSMS("BLYNK Connected...");}
     else {if(smsSent) smsSent= sms.SendSMS("BLYNK failed to connect...");}

     if (blynkConnected)   //Initialize blynk wedgets
              {
                myBlynk.blynkSmsLed (sim800Available & smsSent);
                myBlynk.sendAvRxIndex(Av_Rx);
                myBlynk.streamSelect(streamWebDdns);
                myBlynk.sendPulseRepetetion(pulseRC, repetionRC);
             }
      else  sendToHMI("Internet failure", "Internet failure : ", "Internet failure",FB_NOTIFIER, "Internet failure" );
    
      if (!wifiAvailable) sendToHMI("Wifi failure", "Wifi failure: ", "Wifi failure",FB_NOTIFIER, "Wifi failure" );
      
      else if(fireBaseOn)  //Firebase normally Off and can be activated from Blynk and vice versa
        {
          FBConnected = fb.init();   //Initialize Firebase
          if(FBConnected ) smsSent= sms.SendSMS("FireBase connected...");
          else sms.SendSMS("FireBase Failed to connect...!!!");
        }

      
     //Initialize all millis timers 
    Sms_24_hoursTimer       = millis();
    internetSurvilanceTimer = millis();
    liveTimerOff            = millis();
    liveTimerOn             = millis();
    wifiIDETimer            = millis();
    restartAfterResetNG     = millis();
    NetgeerResetGooglLostTimer = millis();
    blynkNotActiveTimer     = millis();
    routerResetTimer        = millis();
    resetNetgeerAfterInternetLossTimer = millis();
   
    createHandleGroup();    //Create a Handle group for data polling from Blynk
    looadRoomData();        //Lood cameras channels frequencies and relative RC433 transmitter channel
    enableWDG(DIS);         //Disable Watch dog previously enabled 5 min
    initWDG(SEC_60,EN);     //Enable Watch dog for 1 min
    
    String ver = VERSION_ID;    // Send the SW version to Blynk
    if (blynkConnected) myBlynk.sendVersion(ver);
    
    char buf[10]; //make this the size of the String
    ver.toCharArray(buf, 10);    
    if(smsSent) smsSent= sms.SendSMS(buf);   // Send the SW version to mobile by SMS
}

Here is the Init Blynk:

void blynk::init() 
{
  Serial.println();

    wifiMulti.addAP("GIGACUBE_BEK", WIFI_PASSWORD);
    wifiMulti.addAP("NETGEER_BEK", WIFI_PASSWORD);
    wifiMulti.addAP("OPPO Reno2 Bek" , WIFI_PASSWORD);
  
  timer.setInterval(functionInterval, sendTimeToBlynk_7500ms);// run some function at intervals per functionInterval
  timer.setInterval(blynkInterval, checkBlynk);   // check connection to server per blynkInterval
  unsigned long startWiFi = millis();
//  WiFi.begin(ssid, pass);
  while (wifiMulti.run() != WL_CONNECTED){
    delay(500);
    if(millis() > startWiFi + myWiFiTimeout){
      Serial.println("\tCheck the WiFi router. ");
      break;
    }       
  }
  
  if(wifiMulti.run()== 3){
    Serial.println("");
    Serial.println("\tWiFi connected.");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    _wifiIsConnected = true;
  }

Here is the Blynk check connection

void sendTimeToBlynk_7500ms(){
  Serial.println("\tLook, no Blynk  block.");
  if(wifiMulti.run()== 3){
    Serial.println("\tWiFi still  connected.");
    _wifiIsConnected = true;
  }
  if(Blynk.connected()){
    counterTime();
    if(!blynkActive)
    {
      Blynk.virtualWrite(V4, days);
      Blynk.virtualWrite(V20, hours);
      Blynk.virtualWrite(V21, minutes);
      Blynk.virtualWrite(V11, seconds);
      Serial.println("\tTick update to blynk.");
    }
    
    sendTime_7500ms = !sendTime_7500ms;
    _blynkIsConnected = true;
  }
}

void checkBlynk() {
  if (wifiMulti.run() == WL_CONNECTED)  
  {
    unsigned long startConnecting = millis(); 
    _blynkIsConnected = true;   
    _wifiIsConnected = true;
    while(!Blynk.connected()){
      _blynkIsConnected = false;
      Blynk.connect();  
      if(millis() > startConnecting + myServerTimeout){
        Serial.print("Unable to connect to server. ");
        break;
      }
    }
  }
  if (wifiMulti.run() != 3) {
    Serial.print("\tNo WiFi. ");
    _wifiIsConnected = false;
    _blynkIsConnected = false;
  } 
  Serial.printf("\tChecking again in %is.\n", blynkInterval / 1000);
  Serial.println(); 
}

Here is the main loop

void loop(void) 
{
       resetWdg();    //reset timer (feed watchdog) 
       
      if( smsEvent =sms.smsRun()) processSms();   // SMS Polling
       
       blynkConnected=myBlynk.blynkStatus();  //check blynk is connected through the intervaled function
       
       netgeerCtrl();                         //Router control
       
       if ( blynkConnected )
          {
            myBlynk.blynkRun();       //Blynk run
      
            queuValidData = (xQueueReceive(g_event_queue_handle, &queuDataID, 5 / portTICK_RATE_MS) == pdPASS);
            if(queuValidData)   //If any data is received through the Handle
                  {
                    myBlynk.getData ();     //Get the data value
                    queuData = myBlynk.blynkData;
                    processBlynkQueu();     //Process the received data
                  }
            //Reset timers and router data as long as blynk is connected
            InternetLoss = false;   resetNetgeerAfterInternetLossTimer = millis();
            netGeerReset = false;   restartAfterResetNG = millis();
          }

       if( !InternetLoss && !blynkConnected)   //IF blynk connection is lost for first time
          {
            if(smsSent) smsSent= sms.SendSMS("Blynk Disconnected , Internet Loss!!!");  //Send sms
            InternetLoss = true;            //Internet Loss is on
            resetNetgeerAfterInternetLossTimer = millis();
            blynkEvent=false; 
            myBlynk.sendToBlynk = false;
            myBlynk.sendToBlynkLeds = false;
          }

      if (FBConnected )   //Polling firebase stream callback
          { 
            if(fbEvent = fb.firebaseRun()) processFirebase(); 
            
            if(sendTime_7500ms)
            {
             fb.SendString (FB_SECONDS, String(_seconds) ) ;
             sendTime_7500ms = false;
            }
          }
      
      if (zapOnOff ) zappingAvCh (zapOnOff, zapTimer);  //ZApping 15 camera control
      
      if ( (millis() - Sms_24_hoursTimer) >=  SMS_24_HOURS  )   //Alive sms every 24 hour
          {
            Sms_24_hoursTimer       = millis();
            sms.SendSMS("VTR Alive");
           }
   
       myBlynk.blynkRunTimer();     //Run blynk timer
}

void netgeerCtrl(void)
{
        // Internet Loss is on for 1 min
       if ( ( (millis() - resetNetgeerAfterInternetLossTimer) >= INTERNET_LOSS_TO_RESET_NG_TIMER) && InternetLoss && !blynkConnected && !netGeerReset)
        {
              if(smsSent) smsSent= sms.SendSMS("Blynk Disconnected for 2 min, Reset Netgeer");  //Send SMS
              ResetNetgeer();  //Call reset Router
        }

        //In reset router call the routerResetStart is set On      
       if ( (  (millis() - routerResetTimer) >= routerTimer) && routerResetStart)
                {
                digitalWrite(NETGEER_PIN_0, HIGH);      //High will close the relay contact to power on again the router
                routerResetStart=false;
                routerResetTimer        = millis();
                restartAfterResetNG     = millis();
                netGeerReset = true;
                blynkInitDone = false;
                pingGoogle =false;
            }

        //If netGeerReset still On after 1 min and not reset yet then Send sms and restart the ESP32
       if (  ( (millis() - restartAfterResetNG) >=  RESTART_AFTER_NG_RESET_TIMER) && netGeerReset )
          {
            if(smsSent) smsSent= sms.SendSMS("Resetaring 3 min after Netgeer Reset");
            DEBUG_PRINTLN("Resetaring 3 min after Netgeer Rreset");
            ESP.restart(); 
          }
          
}     



void ResetNetgeer(void)
          {
              digitalWrite(NETGEER_PIN_0, LOW);   //Low will open the relay contact to power off the Router
              // Set routerResetStart and start the timer of 1 min
              if(!routerResetStart){routerResetTimer  = millis();routerResetStart = true;DEBUG_PRINTLN("Netgeer Reset done: ");}
          }


bool pingGoogleConnection(void)
{
       bool pingInternet= Ping.ping("www.google.com");
       DEBUG_PRINT("Ping Google: ");DEBUG_PRINTLN(pingInternet ? F("succesiful") : F("failed"));
       return (pingInternet);
}

Best regards
Bek

I. Not surprised you’re getting disconnections with that void loop.
Why not use BlynkTimer instead of doing all of those millis comparisons?

Pete.

Yes I know and I would have sworn you would tell me something like that :slight_smile: it is in my plan to use Blynk timers because before, when I started with Blynk , I was using only gsm and Firebase.

Regards
Bek