Breakage connection to the server when you run the application on your phone

When you run the application on the phone, my NodeMCU loses connection to the server. There is a multiple reconnection. At the same time come up at the bottom of the phone screen inscription: “device was disconnected” and “device is offline”.
I turned on the debugger. Code attached. As well as the link to watch the video as it happens.

Please help me with my problem.


Video

Debug.csv (46,3 КБ)

I looked at your debug but not your video.

You will see other posts on this site with cmd skipped and DHT.

Normally your bugs relate to not using SimpleTimer.

Are you able to post your code?

Watched the video but it didn’t really tell me very much.

Any code?

 #define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_PRINT Serial
#include <ArduinoOTA.h>// OTA
//#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "928c24381aa04c45807a32c6081f2ada";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "ReliableWiFi_2.4";//;"Blynk"
char pass[] = "27051977";//"12345678";

#define DHTPIN 0          // What digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
#define I2C_SCL 12      // Barometric Pressure Sensor (BMP085)
#define I2C_SDA 13
Adafruit_BMP085 bmp;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}
float dst, bt, bp, ba;
char dstmp[20], btmp[20], bprs[20], balt[20];
bool bmp085_present = true;

void setup()
{
  // Debug console
  Serial.begin(9600);
  
  ArduinoOTA.begin();
  ArduinoOTA.setHostname("Svet_OTA");
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  dht.begin();
  Wire.begin(I2C_SDA, I2C_SCL);
  delay(10);
if (!bmp.begin()) {
  Serial.println("Could not find a valid BMP085 sensor, check wiring!");
  while (1) {}
  }
  // Setup a function to be called every second
  timer.setInterval(5000L, sendSensor);
  timer.setInterval(2000L, sendUptime);//bmp180
  timer.setInterval(10000L, sendWifi);

}
void sendWifi() {
  Blynk.virtualWrite(7, map(WiFi.RSSI(), -105, -40, 0, 100) );
}
void sendUptime()
{
  float bp =  bmp.readPressure()/1;
  Blynk.virtualWrite(1, bp); // virtual pin

  //float ba =  bmp.readAltitude();
  Blynk.virtualWrite(2, bp/133.3); // virtual pin

  float bt =  bmp.readTemperature();
  Blynk.virtualWrite(3, bt); // virtual pin

  float dst =  bmp.readSealevelPressure(520)/100;
  Blynk.virtualWrite(4, dst); // virtual pin

}
void loop()
{ ArduinoOTA.handle();
  Blynk.run();
  timer.run(); // Initiates SimpleTimer
}

@Bob_Reliable do you have any of your widgets set with a timed frequency in the app? If you do try changing them all to PUSH.

I will post some test code shortly.

Surprisingly, it looks like it worked.
A 10-minute no errors.
I’ll be watching on, however, it is unclear why there were errors when the item has been selected in the widget settings - 1 second.

Set up a new project as shown below (3 value displays, V5 temp + humidity, V7 WiFi, V4 pressure).
Ensure the app frequency for each widget is set as PUSH.

Mine has been running for 1100 seconds without any problems (on a WeMos but they are pretty much the same as a nodemcu).

Then run this code for a few hours with the token from the new project.

// breakage.ino
#define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_PRINT Serial
#include <ArduinoOTA.h>// OTA
//#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>

char auth[] = "enter new token here";
char ssid[] = "ReliableWiFi_2.4";//;"Blynk"
char pass[] = "27051977";//"12345678";
char server[] = "blynk-cloud.com";

#define DHTPIN 0          // What digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
#define I2C_SCL 12      // Barometric Pressure Sensor (BMP085) D6 nodemcu
#define I2C_SDA 13      // D7 nodemcu
Adafruit_BMP085 bmp;

float dst, bt, bp, ba;
char dstmp[20], btmp[20], bprs[20], balt[20];
bool bmp085_present = true;

void sendSensor()
{ 
  /*
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    
    return;
  }
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
  */
  Serial.println("Temperature and Humidity checked");
  Blynk.virtualWrite(V5, "Checked: " + String(millis() / 1000));
}

void setup()
{
  
  Serial.begin(115200);  // Debug console 
  ArduinoOTA.begin();
  ArduinoOTA.setHostname("Svet_OTA");
  Blynk.begin(auth, ssid, pass, server);
  
  dht.begin();
  Wire.begin(I2C_SDA, I2C_SCL);
  delay(10);
  if (!bmp.begin()) {
    Serial.println("Could not find a valid BMP085 sensor, check wiring!");
    //while (1) {}
  }
  
  timer.setInterval(5000L, sendSensor);
  timer.setInterval(2000L, sendUptime);//bmp180
  timer.setInterval(10000L, sendWifi);

}
void sendWifi() {
  Blynk.virtualWrite(7, map(WiFi.RSSI(), -105, -40, 0, 100) );
  Serial.print("WiFi Strength: ");
  Serial.println(map(WiFi.RSSI(), -105, -40, 0, 100));
}
void sendUptime()
{
  /*
  float bp =  bmp.readPressure()/1;
  Blynk.virtualWrite(1, bp); // virtual pin

  //float ba =  bmp.readAltitude();
  Blynk.virtualWrite(2, bp/133.3); // virtual pin

  float bt =  bmp.readTemperature();
  Blynk.virtualWrite(3, bt); // virtual pin

  float dst =  bmp.readSealevelPressure(520)/100;
  Blynk.virtualWrite(4, dst); // virtual pin
  */
  Serial.println("Pressure checked");
  Blynk.virtualWrite(4, "Checked: " + String(millis() / 1000));
}
void loop()
{ 
  ArduinoOTA.handle();
  Blynk.run();
  timer.run(); // Initiates SimpleTimer
}

This doesn’t fix your problem but it confirms Blynk is fine.
Your problem will relate to one of your sensors.
Remove the comments against one sensor and test.
Add back the comments and test the other one.
Then test both.

I think it’s an either or. Either the app calls the data or your hardware sends the data, not both.

Is this correct @Dmitriy and is there any “fix” for it?

@Costas not sure what fix do you mean. In theory ESP should work just fine during “reading” and “writing” mode. However in practice we see that it usually doesn’t work or works badly. My opinion - esp has bugs in software network layer and there is some issue with “reading”/“writing” mode at same time. On normal MCUs :slight_smile: everything is fine.

@Dmitriy I’m thinking that some way the overall system could check if there are frequency requests from the app and data being sent from the app for the same pin. Maybe only for buggy ESP’s and I don’t have a clue how it would be done.

Edit: I am going to set my WeMos to request data from the app for the 3 display widgets to see if it crashes.

The thing here is that reading requests are totally fine and cool feature. Moreover, I just moved them to server side (from app). And in nearest future users don’t have to use timers in sketch. It could be replaced with BLYNK_READ. I hope that @vshymanskyy will able to find a reason, so BLYNK_READ will be used more often.

@Costas created https://github.com/blynkkk/blynk-library/issues/261

1 Like

@Dmitriy I think the problem is Blynkers not realising that with the app (soon to be server) and the hardware both trying to read sensors at the same time it will cause problems.

@Bob_Reliable my system is holding up fine with data requests from both sides, app at 250ms for 3 value displays. But I am only running a simulation without sensors. In your case the simultaneous requests are crashing your system. So PUSH for all sensors or set a time in the app and don’t include any calls in the sketch. It takes up to 2 seconds to read the data from some sensors!!!

@Costas I installed all void - timer.setInterval time of 3 seconds or more, and all widgets chose Push. Now there is no error. It seems all is well.

1 Like

It most practical applications 300 or more would be fine :slight_smile:
Don’t forget to disable debug if all is fine now.

Oh sure. Already disabled)))