Connection problems with server

hey guys, we are pretty close on completing our Home monitoring project using WiFi and GSM. But we encounter a problem with our connections thru the WiFi. It seems that when I use the blynk cloud server, my project disconnects, but when I use my local blynk server which I set up couple of months ago the project seems to work fine eliminating probable hardware problems (since the projects works perfectly with our local server).
Here’s a look at my serial monitor and my code using online server:


It stops and disconnects after about a minute or two. thanks for any help!

#define BLYNK_PRINT Serial

#include "WiFiEsp.h"

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";

char ssid[] = "adsadsads";
char pass[] = "adsadsads";


#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

#define DHTPIN 4
#define DHTTYPE DHT22   
const int flamepin=A2;
const int threshold=200;// sets threshold value for flame sensor
int flamesensvalue=0; // initialize flamesensor reading
int mVperAmp = 100; // use 100 for 20A Module and 66 for 30A Module
double Voltage1 = 0;
double VRMS1 = 0;
double AmpsRMS1 = 0;
double Voltage2 = 0;
double VRMS2 = 0;
double AmpsRMS2 = 0;
double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;
double kWh = 0;
int RMSPower = 0;
int peakPower = 0;
double kWh1 = 0;
int RMSPower1 = 0;
int peakPower1 = 0;
double kWh2 = 0;
int RMSPower2 = 0;
int peakPower2 = 0;

void current1() {
 Voltage1 = getVPP1();
 VRMS1 = (Voltage1/2.0) *0.707; 
 AmpsRMS1 = (((VRMS1* 1000)/mVperAmp)-.05);
 Serial.print(AmpsRMS1);
 Serial.println(" Amps RMS");
 Blynk.virtualWrite(V13, AmpsRMS1);
 pinMode(0, INPUT);

RMSPower1 = 220*AmpsRMS1;
if (RMSPower1 > peakPower1)
{
  peakPower1 = RMSPower1 ;
}

kWh1 = kWh1 + (RMSPower1*(.004/3600));
Blynk.virtualWrite(V0, kWh1);

}


 
 

void current2() {
 Voltage2 = getVPP2();
 VRMS2 = (Voltage2/2.0) *0.707; 
 AmpsRMS2 = (((VRMS2 * 1000)/mVperAmp)-.05);
 Serial.print(AmpsRMS2);
Serial.println(" Amps RMS");
 Blynk.virtualWrite(V14, AmpsRMS2);
 pinMode(1, INPUT);

RMSPower2 = 220*AmpsRMS2;
if (RMSPower2 > peakPower2)
{
  peakPower2 = RMSPower2 ;
}

kWh2 = kWh2 + (RMSPower2*(.004/3600));
Blynk.virtualWrite(V1, kWh2);

}


void flame ()
{
  flamesensvalue=analogRead(flamepin);// reads analog data from flame sensor
 Serial.print("flame sensor:");
 
  pinMode(2,INPUT);
  Serial.println(flamesensvalue);
   Blynk.virtualWrite(V4, flamesensvalue);
}

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

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);
}

void setup()
{

  Serial.begin(115200);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  WiFi.init(&EspSerial);

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

  dht.begin();
  
timer.setInterval(3000L, flame);
timer.setInterval(1000L, current1);
timer.setInterval(1000L, current2);
timer.setInterval(2000L, sendSensor);
}

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



float getVPP1()
{
  float result1;
  
  int readValue;           
  int maxValue = 0;         
  int minValue = 1024;        
  
   uint32_t start_time = millis();
   while((millis()-start_time) < 1000) //sample for 1 Sec
   {
       readValue = analogRead(0);
       // see if you have a new maxValue
       if (readValue > maxValue) 
       {

           maxValue = readValue;
       }
       if (readValue < minValue) 
       {

           minValue = readValue;
       }
   }
   
   // Subtract min from max
   result1 = ((maxValue - minValue) * 5.0)/1024.0;

   return result1;
 }

float getVPP2()
{
  float result2;
  
  int readValue;           
  int maxValue = 0;         
  int minValue = 1024;        
  
   uint32_t start_time = millis();
   while((millis()-start_time) < 1000) //sample for 1 Sec
   {
       readValue = analogRead(1);
       // see if you have a new maxValue
       if (readValue > maxValue) 
       {

           maxValue = readValue;
       }
       if (readValue < minValue) 
       {

           minValue = readValue;
       }
   }
   
   // Subtract min from max
   result2 = ((maxValue - minValue) * 5.0)/1024.0;

   return result2;
 }

here’s my code and serial monitor for my local server:


please note that the project does not disconnects with the local server

#define BLYNK_PRINT Serial

#include "WiFiEsp.h"

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

char ssid[] = "PLDTHOMEDSLPAKABITKADIN";
char pass[] = "lunaria112296";


#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

#define DHTPIN 4
#define DHTTYPE DHT22   
const int flamepin=A2;
const int threshold=200;// sets threshold value for flame sensor
int flamesensvalue=0; // initialize flamesensor reading
int mVperAmp = 100; // use 100 for 20A Module and 66 for 30A Module
double Voltage1 = 0;
double VRMS1 = 0;
double AmpsRMS1 = 0;
double Voltage2 = 0;
double VRMS2 = 0;
double AmpsRMS2 = 0;
double kWh1 = 0;
int RMSPower1 = 0;
int peakPower1 = 0;
double kWh2 = 0;
int RMSPower2 = 0;
int peakPower2 = 0;

void current1() {
 Voltage1 = getVPP1();
 VRMS1 = (Voltage1/2.0) *0.707; 
 AmpsRMS1 = (((VRMS1* 1000)/mVperAmp)-.05);
 Serial.print(AmpsRMS1);
 Serial.println(" Amps RMS");
 Blynk.virtualWrite(V13, AmpsRMS1);
 pinMode(0, INPUT);

RMSPower1 = 220*AmpsRMS1;
if (RMSPower1 > peakPower1)
{
  peakPower1 = RMSPower1 ;
}

kWh1 = kWh1 + (RMSPower1*(.004/3600));
Blynk.virtualWrite(V0, kWh1);
Blynk.virtualWrite(V10, RMSPower1);

}

void current2() {
 Voltage2 = getVPP2();
 VRMS2 = (Voltage2/2.0) *0.707; 
 AmpsRMS2 = (((VRMS2 * 1000)/mVperAmp)-.05);
 Serial.print(AmpsRMS2);
Serial.println(" Amps RMS");
 Blynk.virtualWrite(V14, AmpsRMS2);
 pinMode(1, INPUT);

RMSPower2 = 220*AmpsRMS2;
if (RMSPower2 > peakPower2)
{
  peakPower2 = RMSPower2 ;
}

kWh2 = kWh2 + (RMSPower2*(.004/3600));
Blynk.virtualWrite(V1, kWh2);

}

void flame ()
{
  flamesensvalue=analogRead(flamepin);// reads analog data from flame sensor
 Serial.print("flame sensor:");
 
  pinMode(2,INPUT);
  Serial.println(flamesensvalue);
   Blynk.virtualWrite(V4, flamesensvalue);
}

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

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(V6, t);
}

void setup()
{

  Serial.begin(115200);
  EspSerial.begin(ESP8266_BAUD);
  WiFi.init(&EspSerial);

 // Blynk.begin(auth, wifi, ssid, pass);
  Blynk.begin(auth, wifi, ssid, pass, "192.168.1.11", 8442);
  dht.begin();
  
timer.setInterval(3000L, flame);
timer.setInterval(1000L, current1);
timer.setInterval(1000L, current2);
timer.setInterval(2000L, sendSensor);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}

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



float getVPP1()
{
  float result1;
  
  int readValue;           
  int maxValue = 0;         
  int minValue = 1024;        
  
   uint32_t start_time = millis();
   while((millis()-start_time) < 1000) //sample for 1 Sec
   {
       readValue = analogRead(0);
       // see if you have a new maxValue
       if (readValue > maxValue) 
       {

           maxValue = readValue;
       }
       if (readValue < minValue) 
       {

           minValue = readValue;
       }
   }
   
   // Subtract min from max
   result1 = ((maxValue - minValue) * 5.0)/1024.0;

   return result1;
 }

float getVPP2()
{
  float result2;
  
  int readValue;           
  int maxValue = 0;         
  int minValue = 1024;        
  
   uint32_t start_time = millis();
   while((millis()-start_time) < 1000) //sample for 1 Sec
   {
       readValue = analogRead(1);
       // see if you have a new maxValue
       if (readValue > maxValue) 
       {

           maxValue = readValue;
       }
       if (readValue < minValue) 
       {

           minValue = readValue;
       }
   }
   
   // Subtract min from max
   result2 = ((maxValue - minValue) * 5.0)/1024.0;

   return result2;
 }

What “ping blynk-cloud.com” shows?

@Adrian_Lunaria Your Ping to the Cloud Server was showing 665ms at boot (not great, but not that bad either) and only 59ms on local Server… so if your project is sending lots of information back and forth it will have a much higher chance of disconnection issues on the slower Cloud Server link (possibly your area and/or issues with your Internet supplier)

But!!! If you have a Local Server anyhow, why worry about it?

You can just setup port forwarding on your router and possibly even a DNS redirection service (I use noip.com ) and use your Local Server from anywhere in the world :wink: Even if your internet is a bit slow… the server and all devices will be running fine on their own local network.

@Gunner sorry for late reply, we carried on testing with our local server and it’ works fine.I already searched on the port forwarding, knowing that my router is not capable of such thing. Now can I know how to use the DNS redirecting? I dont have any idea on that particular topic :blush: thanks!

All routers should have that capability somewhere? What make and model? Is it supplied by your internet supplier… if so ask them how.

That green link above in my last post is the free service I use…

Here is the full link…

Ohh i’ll contact my isp for support later. If I do the port forwarding, would I still need to use the DNS service you posted?

Depends… I need both in order for my phone to connect properly when I was at home… basically it means you use a readable (and rememberable) name like thisismyserver.ddns.net instead of a public IP number that just might change after a power outage or just because, ya know… tuesday… All depending on your ISP.

Thanks for your help! I’ll try both later when I got home.