Unreliable Blynk Arduino WiFi Connection

Hi There,
I was so pleased with the great result I achieved using Blynk for my project. This pleasure lasted for a couple of months until this message appears “Ardduino UNO is offline” and then my struggle and hassle stared for some mysterious reason. I really don’t know whether it’s because of the recent updates on Blynk Library and the app itself so that my arduino code is no longer compatible with it and is needed to be fixed.

My project is about starting a water pump by tapping on a push button (At Switch Mode) on my dashboard, or by clicking a physical push button. Also I’m measuring the temperature and humidity inside the pump control panel and display that on the dashboard using two value displays and two graph widgets. Lastly, I’m showing the status of the pump, system interlock and a valve using three LEDs widgets. here is a snap shot of my dashboard

Please have a look at my code. Your support is highly appreciated.

#define BLYNK_PRINT Serial     // Comment this out to disable prints and save space
#include <SPI.h>
#include <WiFi.h>
#include <BlynkSimpleWifi.h>
#include <SimpleTimer.h>
#include "DHT.h"               

#define DHTPIN A0              
#define DHTTYPE DHT22          

boolean val1;
boolean val2;
boolean flag1 = HIGH;
boolean flag2 = LOW;

int X1;                        //flag carrier1
int X2;                        //flag carrier2

boolean LED1 = LOW;
boolean LED2 = LOW;
boolean LED3 = LOW;
               
int t = 0;
int h = 0;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “XXXXXXXXXXXXXXXXXXXXXX”;   // Through Blynk Server

SimpleTimer timer;

DHT dht(DHTPIN, DHTTYPE);  

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, “XXXXXXX”, “XXXXXXXXXX”);
  dht.begin();               // DHT sensor

 pinMode(3, INPUT_PULLUP);    pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(8, INPUT);

  while (!Blynk.connect()) {/*Wait until connected*/}

  // Notify immediately on startup
  Blynk.notify("Hello..... Your system is connected");
  digitalWrite(3, HIGH);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(8, LOW);        //soft signal pin

  Blynk.virtualWrite(V0, LOW);
  Blynk.virtualWrite(V1, LOW);
  Blynk.virtualWrite(V2, LOW);

  Blynk.virtualWrite(V3, 0 + String(" *C"));
  Blynk.virtualWrite(V4, 0 + String("  %"));
  Blynk.virtualWrite(V5,0);
  Blynk.virtualWrite(V6,0);

  // Setup a function to be called frequently at a preset time 
  timer.setInterval(120000L, notifyTransfer);           // this function is going to be called every one minute, L indicates the data type LONG
}

void loop()
{
  val1 = digitalRead(8);             
  val2 = digitalRead(3);
  
  Blynk.run();                       //where all magic happens
  timer.run();                       
  action();                          //monitors the status of the two digital input pins (D3 & D8) and executes predefined functions accordingly
  getDHT();
  
  if (val1 != flag1)       
  {
    X1 = 0;
  }

  else if (val1 == flag1)
  {
    switch (flag1) 
    {
      case LOW:
        X1 = 1;
        flag1 = HIGH;
        break;
      case HIGH:
        X1 = 0;
        flag1 = LOW;
        break;
     }
  }

  if (val2 != flag2)
  {
    X2 = 0;
  }
    
  else if (val2 == flag2)
  {
    switch (flag2) 
    {
      case HIGH:
        X2 = 1;
        flag2 = LOW;
        break;
      case LOW:
        X2 = 0;
        flag2 = HIGH;
        break;
    }
  }
    
  if (X1 == 1 || X2 == 1) 
  { 
    Blynk.notify("The pump has been normalized\nتم اعادة المضخة للوضع الطبيعي");
  }
  if (X1 == 0 || X2 == 0)
    return;                        // Do nothing
}
                                                           
void action()                                                      
{                                                                   
  val1 = digitalRead(8);           
  val2 = digitalRead(3);            
  if ((val1 == val2) | val1)                                       
  {                                                                 
    Transfer_System();                                            
  }                                                                
  if ((val1 ^ val2) & val2)                                    
  {                                                               
    Normalize_System();                                             
  }                                                                 
}                                                                             
                                                                              
                                                                              
void Transfer_System()
{
  if ((val1 == val2) | val1)
  {
    System_interlock();
    timer.setTimeout(2000L, valvesTranfer);
  }
}


void Normalize_System()
{
  if ((val1 ^ val2) & val2)
  {
    stopPump();
    timer.setTimeout(2000L, valvesNormalize);
  } 
}


void System_interlock()
{
  if ((val1 == val2) | val1)  
  {
    digitalWrite(4, HIGH);
    LEDcheck();
  }
}


void System_Normalize()
{
  if ((val1 ^ val2) & val2) 
  {
    digitalWrite(4, LOW);
    LEDcheck();
  }
}


void valvesTranfer()
{
  if ((val1 == val2) | val1) 
  {
    digitalWrite(5, HIGH);
    LEDcheck();
    timer.setTimeout(8000L, startPump);
  }
}


void valvesNormalize()
{
  if ((val1 ^ val2) & val2) 
  {
    digitalWrite(5, LOW);
    LEDcheck();
    timer.setTimeout(8000L, System_Normalize);
  }
}


void startPump()
{
    if ((val1 == val2) | val1) 
  {
    digitalWrite(6, HIGH);
    LEDcheck();
  }
}


void stopPump()
{
  if ((val1 ^ val2) & val2) 
  {
    digitalWrite(6, LOW);
    LEDcheck();
  }
}


void LEDcheck() 
{
  Blynk.run();                                   
  if (digitalRead(4) != LED1) 
  {
    LED1 = digitalRead(4);
    Blynk.virtualWrite(0, LED1);                  // writing the digitalRead value to virtual pin0
  }
  if (digitalRead(5) != LED2) 
  {
    LED2 = digitalRead(5);
    Blynk.virtualWrite(1, LED2);
  }
  if (digitalRead(6) != LED3) 
  {
    LED3 = digitalRead(6);
    Blynk.virtualWrite(2, LED3);
  }
}

void notifyTransfer()
{
  int Button1 = digitalRead(8);
  int Button2 = !digitalRead(3);       // Inverte state, since button is "Active LOW", 
  if (Button1 || Button2)              
    Blynk.notify("Attention!!... The pump has been transferred\nتحذير!!.. تم تحويل المضخة");
}

void getDHT()
{
  //Blynk.run();                    
  h = dht.readHumidity();
  t = dht.readTemperature();
  Blynk.virtualWrite(V3, t + String(" *C"));     //sends data to the value display on smart phone
  Blynk.virtualWrite(V4, h + String("  %"));     
  Blynk.virtualWrite(V5,t);                             //sends data to the chart display on smart phone
  Blynk.virtualWrite(V6,h);
}

Hello. What Blynk version do you have? Android? And what Blynk version library do you use?

Hello Dmitriy, I’m using Blynk 1.8.2 on iPhone 6 and Blynk library v0.3.3 with Arduino IDE v-1.6.7

So you didn’t change anything? It just stop connecting or it just happens periodically?

Well, at first it happens periodically specially when I switch off my iPhone it goes on and off. Right after updating the Blynk app, the LEDs on my dashboard stopped updating their status and the push button widget started to have some glitch. Then I decided to update the Blynk library but unfortunately, even that didn’t help. In stead, my arduino uno went offline… Any clue. Do you think my code is infested with many bugs :slightly_smiling:

hi alowaisheer,

I read many times that the loop() should only have - blynk.run and timer.run() in it?

i’m not sure why, or if it affecting your program, but could be something to try?

my Blynk just got messed up too after the App update to 1.8.2 - and it has given me the opportunity to redesign and reevaluate my program (and my programing skills!)

Thanks Mr. Dave for your advise. I really appreciate it. I will try it and see how it goes and hope this will help. But seriously, why updating the Blynk app would be affecting your app and creating some issues that didn’t exist? It’s really disappointing. Yes, this would cause some people to take the challenge and try to solve the problem depending on their level of programming skills, while other will just give Blynk away as thy found it unreliable and not easy to deal with.
Thanks guys for your quick response.

Well, in a broader perspective, if you don’t develop no progress will be made. And if you develop there is always a chance of introducing new bugs with new features. After all, it’s made by humans and we are not infallible. At this stage Blynk is getting really grown-up and better all the time. I feel both the organization as such and their product matures over time and it all goes really quickly now. A disadvantage of that is that the product may not be as stable as we wish it to be, but again, if you don’t fall on your ass every now and then, no progress will be made anyway :slight_smile: I for on am very glad the Blynk team sticks out their necks and makes something really good for the big crowd.

1 Like

Hi , no one seems to have mentioned how strong your wifi signal is. I have greatly improved it in my home by simply moving the Wifi router from ground level to a first floor bedroom, near the centre of the house. Could this be the problem?
Your Wifi signal may have got less effective because of outside interference.

Thanks Lichtignaal for your highlights and comments. I totally agree with you. My point just to show the issue from consumers/users prospective, keeping in mind that some one would pay fees for using Blynk.
After all, thanks to all of you blynkers. I really appreciate this interaction.

Hi Wphull,
My wifi signal is strong enough to establish reliable connectivity to the web. In fact, I made some tests and brought my project just few meters away from my router and it’s still tha same. Thanks for your highlight anyways.