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

Server disconnection

Hi guys,

I’m having some random disconnections from blynk server. My code is fairly simple and i have notifications on the phone app so i can know when the esp8266 goes offline.
I started to have some sporadic drops that look like they are fast reconnections, but don’t know why. My virtual writes are timed, 1 second appart, and i make about 6 virtual writes at the same time. From those 6, 3 are just for trying to debug this problem.
I made 3 time counters. One for esp uptime, other for wifi connection and the last for blynk connection. I found out that when the app notifies me that the hardware goes offline, actually wifi and the esp keep on going, so its not a hardware crash or code crash neither wifi dropout. I’m using my internet and its a fiber and reliable connections and i don’t have any issues with other devices.

Could it be that blynk server is experiencing some problems? Anyone relates? My last drop was from 4 hours uptime. But it does not look to have a pattern.

Thanks

Scroll down to the bottom of this page and you’ll see the Blynk cloud server stats:

Based on your location, I would assume that you are using the Frankfurt server.

My guess is that it’s an issue with your ISP, but seeing your code may help.

Pete.

Hi Pete! So sorry that i only saw this reply now! And thanks, in advanced

Well i don’t really know what to think.
My ISP could bue related, ok, but i tested the device in several different fixed connections and even on 4G, the results vary a lot.
For example,

My device is running at 4 days and connection to blynk dropped at almost 3 hours ago.

To sort this out i’ve made another test device on the same project.
This device consists on an arduino uno with ethernet 5100 shield.(running wired)
The code is basicly the example sketch with virtual write to send the time that a) the arduino is running and b) blynk is connected.

Its running at 3 days and the connection has reset in the last 3 hours too. But they did not drop at the same time, the wireless one and the wired. It’s random. At start it managed to be connected for a whole day and a half. But then it stared to drop more frequently. Devices do not restart as i have a condition not to start blynk automaticly.

At three days ago i was getting server disconnection almost each 30
To 30 minutes. No changes to the code or anything and now it’s running smoother.
I ping the server constantly and it replies steady, no match to my dropouts.

The only thing i can think of is if i have my blynk software for the device a not very good version. But i find this weird. But i’m using the 0.6.1 on the Uno and on the ESP.

You’ve not really discussed your 4G setup and results. If you were using a phone hotspot for this then it’s probably not a valid test scenario.

Ping is a bit of a blunt instrument, as it’s not using the same ports or transport protocols as the Blynk devices. All it proves is that a connection to server is available, not what your ISP may be doing to the data packets along the way.

Do you have a friend (preferably one who uses a different ISP) who could test this on their home network?

I assume that you’ve rebooted your router, checked your DHCP lease setting, removed ant repeaters from your network, checked for IP conflicts etc etc?

That’s the latest version of the library, in use by thousands of people without any issues.

Pete.

1 Like

My 4g setup was a Router with Vodafone card, actually i was using it near the Vodafone office here in Portugal. lol Guess they should have nice connection. It presented max 4g signal. Feeding to the ESP via Wifi. The amount of dropouts look similar as they are look so random… [edit] but they were fairly low.

True about the ping tool, but if i’ve had some sort of DNS failure along the way it could help me get somewhere. Recently i had someone in the USA trying to use my hardware via API and it wasn’t working out because of DNS issues. Changed the Javascript for a version with the blynk server ip directly and it worked out.

What you are mentioning happened. I’ve length tested at least 4 different networks. Mine, friends home, friends office, 4g.
I have another two networks that it was constantly dropping out. Those were from a work site and something really awkward was going on with wifi. Supposedly different routers with different connections but the esp was struggling to send packets as wifi connection did not drop but blynk connection failed very frequently. And then i’ve used another wifi device and getting to it’s served webpage was really slow and sometimes did not happen, so i just did not consider that experience as valid. Really something strange going on there but as i didn’t control the network just disregarded it.

The whole network settings you are telling me are under control.

Just notice that on the wired uno i’ve changed the connection drop notification to 1 second, meaning that i’ll be notified very shortly after the connection is lost.

This shouldn’t make a difference to your results.
The default timeout for the Blynk library/server timeout is 10 seconds. As you have no re-connect routine then the notification setting simply means that you’ll get that notification slightly quicker.

You can increase the timeout period in the sketch if you wish. This will increase it from 10 to 60 seconds…

#define BLYNK_HEARTBEAT 60

Of course, that may not be what you want to do - it depends on your project.

I may be worth you sharing your code, just in case there are any issues with it. I’d be happy to run it on a device if you wish, to compare the results.

Pete.

I’ve increased heartbeat in some devices before. These tests take time as it can look fine on one day and the next it fails a lot more. So i didn’t increase the heartbeat as i was trying to figure out if it had anything to do with wifi manager and the esp. But as a “control group”, i’ve setup this wired one for comparison recently. And i’ve put heartbeat to 1. I notice that disconnection notifications are far more quick to appear but i’ve just realized that i am stressing the connection on the wired. But as it’s should be more stable , it would not matter, as long as there are no limit on cloud server side to the amount of heartbeats?

Just take a look at an example of what was happening saturday.
I didn’t touch it as it’s on the friends office network, and it started running ok by itself on the next day.
Office connectivity was ok as we could teamviewer to the office and no one was physically there. Also, the connection only had blynk drops, no wifi drops. Altough, there are some wifi disconnection drops also sometimes.

Now i’ll show you other blynk projects that i have, also have some disconnections at sometime.


Consider the top one, Porteiro. It’s right by my wifi router and has no wifi manager on it. Just triggers a relay, super simple example basic code with wifi credentials built in. And the uptime should be way bigger than 13th July as my router and wifi uptime are past 15 days.
Just an example.
My home internet connection is great. The isp never fails.

The other one is expected to have some drops as it’s thru a Wifi Repeater.

What i mean to show is that i think i don’t have any device on blynk that does not experience some disconnection at some point. It’s not an awful thing as it quickly re-connects. My biggest problem is when it goes crazy like on saturday and i’m unable to use it reliably.

My device consists on being a Powerpoint remote control.
What this means is that i give someone a webpage and the device on my end side just goes forward or backwards.
Really simple but the main advantage is that i do not need to setup firewalls or stuff like that. it’s supposed to just work for anyone and almost 0 setup time.
So you can understand my problem as i don’t want clicks to fail. The thing that cannot happen is to someone click “next” and if the hardware is temporarily disconnected it won’t assume the “click”.
Then i worry to get the best stable connection possible.
And it’s not good to have it ok one day and the next maybe not so good.

I’m waiting on a Arduino leonardo eth to eliminate the wifi part of this equation.

This is the wired test code:

#define BLYNK_PRINT Serial
#define BLYNK_HEARTBEAT 1
#include <SPI.h>
#include <BlynkSimpleEthernet.h>
#define HOST_NAME "Project001"
char auth[] = "";

#define W5100_CS 10
#define SDCARD_CS 4

int fo = 0;

//long wifiTimer = 0;
long blynkTimer = 0;
//long wifiTimerOld = 0;
long blynkTimerOld = 0;
bool blynkOn = false;
String HTTP_req;
BlynkTimer timer;

byte mac[] = {
    0x90, 0xA2, 0xDA, 0x00, 0xE8, 0xE9};

EthernetServer server(80);

String TimeShowFormatted(long ms)
{
  long days = 0;
  long hours = 0;
  long mins = 0;
  long secs = 0;
  String secs_o = ":";
  String mins_o = ":";
  String hours_o = ":";
  secs = ms / 1000;            // set the seconds remaining
  mins = secs / 60;            //convert seconds to minutes
  hours = mins / 60;           //convert minutes to hours
  days = hours / 24;           //convert hours to days
  secs = secs - (mins * 60);   //subtract the coverted seconds to minutes in order to display 59 secs max
  mins = mins - (hours * 60);  //subtract the coverted minutes to hours in order to display 59 minutes max
  hours = hours - (days * 24); //subtract the coverted hours to days in order to display 23 hours max
  if (secs < 10)
  {
    secs_o = ":0";
  }
  if (mins < 10)
  {
    mins_o = ":0";
  }
  if (hours < 10)
  {
    hours_o = ":0";
  }
  return days + hours_o + hours + mins_o + mins + secs_o + secs;
}

void myTimerEvent()
{
  Blynk.virtualWrite(V10, TimeShowFormatted(millis()));
  //Blynk.virtualWrite(V11, TimeShowFormatted(wifiTimer));
  Blynk.virtualWrite(V12, TimeShowFormatted(blynkTimer));
  Blynk.virtualWrite(V0, 0);
  Blynk.virtualWrite(V1, 0);
  Blynk.virtualWrite(V2, 0);
  Blynk.virtualWrite(V3, 0);
}

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V0)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 0)
  {
    return;
  }
  else
  {
    digitalWrite(5, LOW);
    delay(10);
    digitalWrite(5, HIGH);
  }

  //Blynk.virtualWrite(V0, 0);
  // process received value
}
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 0)
  {
    return;
  }
  else
  {
    digitalWrite(6, LOW);
    delay(10);
    digitalWrite(6, HIGH);
  }
  //Blynk.virtualWrite(V0, 0);
  // process received value
}

BLYNK_WRITE(V2)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 0)
  {
    return;
  }
  else
  {
    digitalWrite(7, LOW);
    delay(10);
    digitalWrite(7, HIGH);
  }

  //Blynk.virtualWrite(V0, 0);
  // process received value
}
BLYNK_WRITE(V3)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 0)
  {
    return;
  }
  else
  {
    digitalWrite(8, LOW);
    delay(10);
    digitalWrite(8, HIGH);
  }
  //Blynk.virtualWrite(V0, 0);
  // process received value
}

void setup()
{
  Serial.begin(115200);
  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
  Ethernet.begin(mac);
  Serial.println(Ethernet.localIP());
  if (blynkOn == true)
  {
    Blynk.config(auth);
    blynkTimerOld = millis();
  }
  //Blynk.begin(auth);
  //Blynk.config(auth); //Com Configuracao Ethernet de IP
  HTTP_req = "";
  timer.setInterval(1000L, myTimerEvent);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  server.begin();
}

void serverhome()
{
  EthernetClient client = server.available();
  if (client)
  {
    //Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected())
    {
      if (client.available())
      {
        char c = client.read();
        if (HTTP_req.length() < 120)
          HTTP_req += c; // save the HTTP request 1 char at a time
        //Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank)
        {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close"); // the connection will be closed after completion of the response
          client.println();
          //Serial.println(HTTP_req);
          if (HTTP_req.indexOf("BLYNKON") >= 0)
          {
            // read switch state and analog input
            Serial.println("ON");
            blynkOn = true;
            Blynk.config(auth);
            blynkTimerOld = millis();
            break;
          }
          else if (HTTP_req.indexOf("BLYNKOFF") >= 0)
          {
            // read switch state and analog input
            Serial.println("OFF");
            blynkOn = false;
            break;
          }
          else
          {
            //Serial.println("home");
            break;
          }
        }
        if (c == '\n')
        {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r')
        {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(10);
    // close the connection:
    client.stop();
    HTTP_req = "";
    //Serial.println("client disconnected");
  }
}

void loop()
{

  if (Blynk.connected() != 1)
  {
    blynkTimerOld = millis();
    blynkTimer = 0;
  }
  //Serial.println("blynkrun");
  blynkTimer = millis() - blynkTimerOld;
  if (blynkOn == true)
  {
    blynkTimer = millis() - blynkTimerOld;
    Blynk.run();
    timer.run();
  }
  if (blynkOn == false)
  {
    serverhome();
  }
}

this is the wireless version:

#include <Arduino.h>

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DoubleResetDetector.h>
#include <ESPAsyncWebServer.h>
#include <ESPAsyncWiFiManager.h>
#include <ESP8266mDNS.h>
#define DRD_TIMEOUT 10
#define DRD_ADDRESS 0

DoubleResetDetector drd(DRD_TIMEOUT, DRD_ADDRESS);
bool initialConfig = false;
AsyncWebServer server(80);
DNSServer dns;
int fo = 0;
bool one = false;
bool two = false;
bool pair = true;
bool blynkOn = true;
long wifiTimer = 0;
long blynkTimer = 0;
long wifiTimerOld = 0;
long blynkTimerOld = 0;
BlynkTimer timer;

void configModeCallback(AsyncWiFiManager *myWiFiManager)
{
  Serial.println("Entered config mode");
  Serial.println(WiFi.softAPIP());
  //if you used auto generated SSID, print it
  Serial.println(myWiFiManager->getConfigPortalSSID());
  //entered config mode, make led toggle faster
}

String TimeShowFormatted(int ms)
{
  long days = 0;
  long hours = 0;
  long mins = 0;
  long secs = 0;
  String secs_o = ":";
  String mins_o = ":";
  String hours_o = ":";
  secs = ms / 1000;            // set the seconds remaining
  mins = secs / 60;            //convert seconds to minutes
  hours = mins / 60;           //convert minutes to hours
  days = hours / 24;           //convert hours to days
  secs = secs - (mins * 60);   //subtract the coverted seconds to minutes in order to display 59 secs max
  mins = mins - (hours * 60);  //subtract the coverted minutes to hours in order to display 59 minutes max
  hours = hours - (days * 24); //subtract the coverted hours to days in order to display 23 hours max
  if (secs < 10)
  {
    secs_o = ":0";
  }
  if (mins < 10)
  {
    mins_o = ":0";
  }
  if (hours < 10)
  {
    hours_o = ":0";
  }
  return days + hours_o + hours + mins_o + mins + secs_o + secs;
}

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
//char auth[] = "l";
char auth[] = ""; 
//char auth[] = "";  --TEST

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

void myTimerEvent()
{
  Blynk.virtualWrite(V10,TimeShowFormatted(millis()));
  Blynk.virtualWrite(V11,TimeShowFormatted(wifiTimer));
  Blynk.virtualWrite(V12,TimeShowFormatted(blynkTimer));
  Blynk.virtualWrite(V0,0);
  Blynk.virtualWrite(V1,0);
  Blynk.virtualWrite(V2,0);
  Blynk.virtualWrite(V3,0);
}

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V0)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue== 0){
    return;
  } else{
  digitalWrite(D1, LOW);
  delay(10);
  digitalWrite(D1, HIGH);
  }


  //Blynk.virtualWrite(V0, 0);
  // process received value
}
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue== 0){
    return;
  } else{
  digitalWrite(D2, LOW);
  delay(10);
  digitalWrite(D2, HIGH);
  }
  //Blynk.virtualWrite(V0, 0);
  // process received value
}

BLYNK_WRITE(V2)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue== 0){
    return;
  } else{
  digitalWrite(D3, LOW);
  delay(10);
  digitalWrite(D3, HIGH);
  }

  //Blynk.virtualWrite(V0, 0);
  // process received value
}
BLYNK_WRITE(V3)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue== 0){
    return;
  } else{
  digitalWrite(D4, LOW);
  delay(10);
  digitalWrite(D4, HIGH);
  }
  //Blynk.virtualWrite(V0, 0);
  // process received value
}

void setup()
{
  timer.setInterval(1000L, myTimerEvent);
  WiFi.setSleepMode(WIFI_NONE_SLEEP);
  // Debug console
  Serial.begin(115200);
  pinMode(BUILTIN_LED, OUTPUT);
  // start ticker with 0.5 because we start in AP mode and try to connect
  AsyncWiFiManager wifiManager(&server, &dns);
  //wifiManager.setSTAStaticIPConfig(IPAddress(10,0,0,60), IPAddress(10,0,0,252), IPAddress(255,255,255,0), IPAddress(8,8,8,8)); //  ---> SET MANUAL IP
  wifiManager.setAPCallback(configModeCallback);
  if (drd.detectDoubleReset())
  {
    Serial.println("Double Reset Detected");
    initialConfig = true;
    SPIFFS.format();
  }
  if (initialConfig)
  {
    Serial.println("Starting configuration portal.");
    AsyncWiFiManager wifiManager(&server, &dns);
    //wifiManager.resetSettings();
    if (!wifiManager.startConfigPortal("PPTCtrl1"))
    {
      Serial.println("Not connected to WiFi but continuing anyway.");
    }
    else
    {
      //if you get here you have connected to the WiFi
      Serial.println("connected...yeey :)");
    }

    ESP.reset(); //reset and try again
    delay(5000);
  }

  //fetches ssid and pass and tries to connect
  //if it does not connect it starts an access point with the specified name
  //here  "AutoConnectAP"
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect())
  {
    Serial.println("failed to connect and hit timeout");
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(1000);
  }

  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");
  wifiTimerOld = millis();
  
  //keep LED on
  digitalWrite(BUILTIN_LED, LOW);
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);
  pinMode(D4, OUTPUT);
  digitalWrite(D1, HIGH);
  digitalWrite(D2, HIGH);
  digitalWrite(D3, HIGH);
  digitalWrite(D4, HIGH);
  //Blynk.config(auth);
  //Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  server.on("/BLYNKON", HTTP_GET, [](AsyncWebServerRequest *request) {
    Serial.println("Serving BlynkON");
    blynkOn = true;
    Blynk.config(auth);
    blynkTimerOld = millis();
    String webpage2;
    String IPaddress = WiFi.localIP().toString();
    webpage2 += "<form action='http://" + IPaddress + "/' method='GET'>";
    webpage2 += "<input type='submit' value='Back'>";
    request->send(200, "text/html", webpage2);
  });

  server.on("/BLYNKOFF", HTTP_GET, [](AsyncWebServerRequest *request) {
    Serial.println("Serving BlynkOFF");
    blynkOn = false;
    String IPaddress = WiFi.localIP().toString();
    String webpage2;
    webpage2 += "<form action='http://" + IPaddress + "/' method='GET'>";
    webpage2 += "<input type='submit' value='Back'>";
    request->send(200, "text/html", webpage2);
  });

  server.on("/PREV", HTTP_GET, [](AsyncWebServerRequest *request) {
    request->send_P(fo, "text/html", "OK");
    if (one == true && pair == false)
    {
      digitalWrite(D1, LOW);
      Serial.println("BT1 PREV");
    }
    if (two == true && pair == false)
    {
      digitalWrite(D3, LOW);
      Serial.println("BT2 PREV");
    }
    if (pair == true && one == false && two == false)
    {
      digitalWrite(D1, LOW);
      digitalWrite(D3, LOW);
      Serial.println("PAIR PREV");
    }
    delay(10);
    digitalWrite(D1, HIGH);
    digitalWrite(D3, HIGH);
  });

  server.on("/NEXT", HTTP_GET, [](AsyncWebServerRequest *request) {
    request->send_P(fo, "text/html", "OK");
    if (one == true && pair == false)
    {
      digitalWrite(D2, LOW);
      Serial.println("BT1 NEXT");
    }
    if (two == true && pair == false)
    {
      digitalWrite(D4, LOW);
      Serial.println("BT2 NEXT");
    }
    if (pair == true && one == false && two == false)
    {
      digitalWrite(D2, LOW);
      digitalWrite(D4, LOW);
      Serial.println("PAIR NEXT");
    }
    delay(10);
    digitalWrite(D2, HIGH);
    digitalWrite(D4, HIGH);
  });

  server.on("/ONE", HTTP_GET, [](AsyncWebServerRequest *request) {
    Serial.println("Serving ONE");
    one = true;
    two = false;
    pair = false;
    String IPaddress = WiFi.localIP().toString();
    String webpage2;
    webpage2 += "<form action='http://" + IPaddress + "/' method='GET'>";
    webpage2 += "<input type='submit' value='Back'>";
    request->send(200, "text/html", webpage2);
  });

  server.on("/TWO", HTTP_GET, [](AsyncWebServerRequest *request) {
    Serial.println("Serving TWO");
    one = false;
    two = true;
    pair = false;
    String IPaddress = WiFi.localIP().toString();
    String webpage2;
    webpage2 += "<form action='http://" + IPaddress + "/' method='GET'>";
    webpage2 += "<input type='submit' value='Back'>";
    request->send(200, "text/html", webpage2);
  });

  server.on("/PAIR", HTTP_GET, [](AsyncWebServerRequest *request) {
    Serial.println("Serving PAIR");
    one = false;
    two = false;
    pair = true;
    String IPaddress = WiFi.localIP().toString();
    String webpage2;
    webpage2 += "<form action='http://" + IPaddress + "/' method='GET'>";
    webpage2 += "<input type='submit' value='Back'>";
    request->send(200, "text/html", webpage2);
  });

  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
    Serial.println("Serving Home Page");
    String webpage2;
    String IPaddress = WiFi.localIP().toString();
    webpage2 = "<html>";
    webpage2 += "<head><title>Wifi PPTCtrl1 - Setup</title>";
    webpage2 += "<style>";
    webpage2 += "body { background-color: #FFFFFF; font-family: Arial, Helvetica, Sans-Serif; Color: black;}";
    webpage2 += "</style>";
    webpage2 += "</head>";
    webpage2 += "<body>";
    webpage2 += "<h1><br>Wifi PPTCtrl1 - Setup</h1>";
    webpage2 += "<form action='http://" + IPaddress + "/BLYNKON' method='GET'>";
    webpage2 += "<input type='submit' value='BlynkON'>";
    webpage2 += "</form> ";
    webpage2 += "<form action='http://" + IPaddress + "/BLYNKOFF' method='GET'>";
    webpage2 += "<input type='submit' value='BlynkOFF'>";
    webpage2 += "</form> ";
    webpage2 += "<form action='http://" + IPaddress + "/ONE' method='GET'>";
    webpage2 += "<input type='submit' value='BT1 CTRL'>";
    webpage2 += "</form> ";
    webpage2 += "<form action='http://" + IPaddress + "/TWO' method='GET'>";
    webpage2 += "<input type='submit' value='BT2 CTRL'>";
    webpage2 += "</form> ";
    webpage2 += "<form action='http://" + IPaddress + "/PAIR' method='GET'>";
    webpage2 += "<input type='submit' value='PAIR CTRL'>";
    webpage2 += "</form> ";
    request->send(200, "text/html", webpage2); // Send a response to the client asking for input
  });
  server.begin();
  if (!MDNS.begin("pptctrl1"))
  {
    Serial.println("Error setting up MDNS responder!");
  }
  Serial.println("mDNS responder started - pptctrl1");
  if (blynkOn == true){
  Blynk.config(auth);
  blynkTimerOld = millis();
  }

}

void loop()
{
  if (WiFi.status() == WL_CONNECTED){
    wifiTimer = millis() - wifiTimerOld;
  }
  if (WiFi.status() == 6 ) {
    //Serial.println(WiFi.status());
    wifiTimer = 0;
    wifiTimerOld = millis();
  }
  
  if (Blynk.connected() != 1){
    blynkTimerOld = millis();
    blynkTimer = 0;
  }
  if (blynkOn == true)
  {
    blynkTimer = millis()-blynkTimerOld;
    Blynk.run();
    timer.run();
  }
  drd.loop();
  MDNS.update();
}

Thank you so much for your help.

I’m just curious if any of your devices experience a connection as reliable as it’s uptime to blynk-cloud.

As you’re trying to troubleshoot connection issues then I’d have expected you to be testing something simpler than this.

Both versions of your code seem to be using port 80 for a webserver, which is also used for Blynk communications, so that is where I’d start looking.

Maybe @khoih has some thoughts on possible conflicts with the way that his ESP_WiFiManager is being used?

Pete.

Yeah in the meanwhile i’ve started a webserver just to start or stop blynk on a web browser. ( wired test version)

The other is the original and is more complex, yes, as it uses the wifi manager.

But the wired, for me, is quite simple! ahah. i’ve made far more complex than this before. lol. Sorry if i’ve mislead you. Anyways as i need to do local network calls to the arduino whenever i use it without internet access i should have some way to control it. And testing more like a “real world scenario” seemed the way for me, ruling out the wifi part.

I will change the port right away for starters. Wasn’t aware they could conflict

The point I was making is that if you’re running into issues, and questioning the state of the Blynk servers, or the quality of the Blynk library, or trying to disprove issues relating to your ISP; then the best approach would be to go for a super-simple sketch which does something like write the uptime to a widget on a virtual pin once every second (via a Blynktimer).
If that sketch doesn’t go offline in the same way then you know that you don’t have issues with the Infrastucture or the libraries. You can then start adding-in other functionality until you discover what it is that is causing your problem.

Pete.

Both versions of your code seem to be using port 80 for a webserver, which is also used for Blynk communications, so that is where I’d start looking.

what please? do you know how TCP/IP works?

:rofl:

I did not understand this, sorry.

Dear sir,

Does having a repeater affect the connection to the Blynk server?

It shouldn’t do, but if you’re having disconnection problems then the first rule of troubleshooting is to strip things back to basics. From a home networking point of view this means ensuring that your device is in good range of your router, and that the device is connecting to your router’s wireless network - not the network from a wireless repeater/extender or secondary WAP.

Wireless extenders that pick up the WiFi signal from the router and re-broadcast it - either with the same or a different SSID - aren’t my bit of kit anyway. Wherever possible I preferred wired connections to secondary wireless access points, and manual management of WiFi channels to avoid conflicts.

Having said that, most of the disconnection issue I see being reported here are caused by bad coding. Bit, trying to troubleshoot people’s home network issues via a forum are virtually impossible. As a result, my advice is to disconnect any additional WiFi repeaters and reboot the router. If this fixes the problem then the user can start to add elements back in until the culprit is found (although sometimes the cause will never be found, but but least the issue was identified as a network problem and if it occurs again the problem can be investigated in a more methodical way)./

Pete.

Just as follow up, i’ve arranged some Arduino Leonardo Ethernet copy and it’s running a very similar code to the one i’ve posted here, and i have the uno with ethernet shield running just the blynk connection service and posting arduino uptime and server connection uptime to virtual pins as a “behaviour comparison” to seek for disconnections and if they happen at the same time. my biggest problem has been guaranteeing some usb power supply that does not sleep along the way as i’ve ran out of usb power supply adapter in my house… but both have been stable as until now i have 22 hours of uptime without drop in the server connection.

@PeteKnight,

After 2 days running ± without connection drops i think this is more than ok for my need. I think the problem was with having my server set to the port 80 also. Really not clear thinking for myself. i’ll switch it back to 80 just to clear this out but it seems like the issue was found. Thank you so much for your time, help and patience. And knowledge too. :slight_smile:

Regards,
João

1 Like

Okay, I’ll mark this topic as “solved”, but leave it open. Feel free to come back with more observations or issues.

Pete.

a TCP client connecting to a remote IP and port 80 has nothing to do with local TCP server on port 80. the client uses a free TCP port number usually with number higher then 10000.

@Juraj Ok, i see what you mean. But this has been the only thing i’ve changed so maybe you have another idea for possible culprit?
Thanks