Disconnection issue

Hi,
Updated to latest release this morning and now getting disconnection errors every 5 seconds or so in the Blynk app.(“Your ESP8266 was disconnected”). Serial monitor is not showing any errors and the program appears to run normally. Hardware is NodeMCU V1 and the latest libraries and Blynk installed.Is it possible to go back to the previous version of the Blynk app to test if the latest upgrade is the problem.
Have posted my code in case that is the problem.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
#include <RCSwitch.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include "DHT.h"
#include <Adafruit_BMP085.h>  // Adafruit BMP085 library
#include <Wire.h>
#define DHTPIN D1
#define DHTTYPE DHT22
Adafruit_BMP085 bmp;
int lightReading;
int reedSwitch = D6; // Reed Pin
float light;
float husl = 52.01;  //Every 10 meters corresponds to 1.2 hPa pressure change at sea level. 
//This station is 433.42 above sea level so therefore add 52.01 hPa to reading
WidgetLED led1(V1);
WidgetLED led2(V4);
WidgetLCD lcd(V2);
WidgetLCD lcd1(V14);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxx";
String mymin = " minutes";
const char* host = "esp8266-webupdate";
const char* ssid = "xxxxxxxxxx";
const char* password = "xxxxxxxxx";

RCSwitch mySwitch = RCSwitch();
DHT dht(DHTPIN,DHTTYPE,11);
SimpleTimer timer;


ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;

void setup()
{
  Serial.begin(9600);
  Serial.println();
  Serial.println("Booting Sketch...");
  WiFi.begin(ssid, password);
  Wire.begin(D4,D5);
  bmp.begin();
  dht.begin();
  mySwitch.enableTransmit(D0); // Transmitter is connected to ESP8266 Pin #D0
  Blynk.begin(auth, ssid, password);
  timer.setInterval(10000L, sendAllData);// Here you set interval (10sec) and which function to call 
  timer.setInterval(1000L, sendUptime); //  Here you set interval (1sec) and which function to call
  timer.setInterval(1000L,garage);
  
  MDNS.begin(host);
  httpUpdater.setup(&httpServer);
  httpServer.begin();
  MDNS.addService("http", "tcp", 80);
  Serial.printf("HTTPUpdateServer ready! Open http://%s.local/update in your browser\n", host);
  pinMode(reedSwitch, INPUT);
 } 

void garage()
{
int StatusSwitch = digitalRead(reedSwitch);
  if (StatusSwitch == HIGH)
  {
    Serial.println("Door is open!");
    Blynk.virtualWrite(V21,"open");
    lcd1.print(0,0, "Garage door");
    lcd1.print(0,1, "is open!!");
    led2.on();
  }
   else   //if input is low (0), then door is closed
  {
    Serial.println("Door is closed!");
    Blynk.virtualWrite(V21,"closed");
    lcd1.print(0,0, "Garage door");
    lcd1.print(0,1, "is closed");
    led2.off();
  }
}
  
void sendAllData()
  {
    float h = dht.readHumidity();
    float f = dht.readTemperature();
    float pr = (bmp.readPressure());
    float p = (pr/100) + husl; //adjust barometer for height above sea level
    lightReading = analogRead(A0); 
    lightReading = map(lightReading,0,1023,0,100);   //Set the light reading to a pecentage of 100 with a 100% being full sun     
    
    Serial.print("Temperature: ");
    Serial.print(bmp.readTemperature());
    Serial.println("'C");
    Serial.print("Pressure: ");
    Serial.print(p);
    Serial.println(" hPa");
    Serial.print(" Humidity: "); 
    Serial.print(h);
    Serial.print("%\t");
    Serial.print("Temperature: "); 
    Serial.print(f);
    Serial.print("'C ");
    Serial.print("\t");
    Serial.print("Light: ");
    Serial.println(lightReading);
        
    Blynk.virtualWrite(V10,f);
    Blynk.virtualWrite(V11,h);
    Blynk.virtualWrite(V9,f);
    Blynk.virtualWrite(V12,h);
    Blynk.virtualWrite(V13, lightReading);
    Blynk.virtualWrite(V15, lightReading);
    Blynk.virtualWrite(V16,p);
 }
  
  bool isFirstConnect = true; // Keep this flag not to re-sync on every reconnection

  // This function will run every time Blynk connection is established
  BLYNK_CONNECTED() 
  {
    if (isFirstConnect) 
      {
        // Request Blynk server to re-send latest values for all pins
        Blynk.syncAll();
        // You can also update an individual Virtual pin like this:
        //Blynk.syncVirtual(V0);
        isFirstConnect = false;
      }
  }
void sendUptime()
  {
    // This function sends Arduino up time every 1 second to Virtual Pin (V5)
    // In the app, Widget's reading frequency should be set to PUSH
    // You can send anything with any interval using this construction
    // Don't send more that 10 values per second
    Blynk.virtualWrite(V5, millis() / 1000);
    lcd.print(0,0,"Time connected");
    lcd.print(0,1, millis()/1000/60 + mymin);
    if (led1.getValue()) 
    {
      led1.off();
    } 
    else 
    {
      led1.on();
    }
  }
  
//Remote control of switches
//-------------------------------------------------
  BLYNK_WRITE(0)
  {
    mySwitch.send(354206,24);  //turn on switch 1B
  }
  BLYNK_WRITE(3)
  {
    mySwitch.send(354198,24); //turn off switch 1B
  }
  BLYNK_WRITE(6)
  {
    mySwitch.send(14331050,24); //turn on switch 3A
  }
  BLYNK_WRITE(7)
  {
    mySwitch.send(14331042,24); //turn off switch 3A
  }
  BLYNK_WRITE(8)
  {
    mySwitch.send(14331054,24); //turn on switch 1A
  }
  BLYNK_WRITE(9)
  {
    mySwitch.send(14331046,24); //turn off switch 1A
  }
  BLYNK_WRITE(17)
  {
    mySwitch.send(14331052,24); //turn on switch 2A
  }
  BLYNK_WRITE(18)
  {
    mySwitch.send(14331044,24); //turn off switch 2A
  }


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

Thanks

is it an ‘issue’ if everything runs normally?

is it exactly 5 seconds? or variable lengths of time?

have you looked at teh debugging?

#define BLYNK_PRINT Serial //this is the debugging for Blynk
//#define BLYNK_DEBUG        // Optional, this enables 'full' debugging detailed prints

Everything is not running normally, the time connected will update every five seconds or so but nothing else appears to be working. Remote control no longer works and other updates only seem to happen randomly if at all.

It is variable form a couple of seconds to five or so.

Will do that now.
Thanks for the reply

sorry, but you confused me with this statement…

Sorry, I could of explained that clearer. What I meant to say was that it appears to run normally in the serial monitor but not in the Blynk app.

yep, then the blynk_print’s should tell you what is going on…

post up a screen shot of those :slight_smile:

Doesn’t make a lot of sense to me, hope you can decipher it :slight_smile:

sometimes when i see Blynk doing that it is from flooding…

but dunno why it would arise after the new software update…

try changing your two 1sec timer intervals to 10 seconds and see if it improves?

Have done as you suggested but makes no difference. However it appears to be working ok with just one timer set to fire every 10 seconds. As soon as i enable it for 1 second intervals or set two timers it will start disconnecting again. Have no idea why it has begun acting this way. Maybe @Dmitriy can shed some light. :grin:

not sure i understand why this is not in setup?

doesnt this mean you call running SYNC.ALL every time you run void sendAllData()?

sync.all is not a trivial call…

Did that but makes no difference, will just have to content myself with one timer for now. Hopefully I can find the problem soon.

The only way I can get it to work reliably now is by switching off all the timers. Having to do that means I can only send data from the Blynk app to my hardware but cannot receive any data from my hardware to the Blynk app. I have even used different hardware but it didn’t make any difference. I don’t understand why as up until this morning everything was working reliably. Look forward to any comments. :grimacing:

I have very similar code to you and it didn’t skip a beat when i went to the new app v1.16.4 this morning… Put local server v19.0 on at the same time.

Please try to comment httpServer.handleClient(); does that help?

No it didn’t make any difference. I have commented anything to do with OTA but the problem remains. It will only work when I comment all the timers

Have you tried commenting out each timer in turn?

Yes did that earlier but to no avail. It would seem to run ok but as soon as I touched a button to send a command to turn relay or light on it bombs out. With the timers turned off I am able to send commands ok but of course I get no feedback from my sensors

Your bugs are probably in one timer. Test each in turn.

Tell us which timer has the bug and we might find it for you.

Up until today it had been running reliably but I will do as you say and see how it goes. :slight_smile:

Do you have reading widgets on application side? What exactly did you update? App, libs? Is that cloud?