[SOLVED] If don't connect to Internet device go slowly

I’ve try to put in my sketch
if(Blynk.connect() == true){
blinksend
}
but not work, what result show Blink.connect()?
true or false, 0 or 1, TRUE or FALSE?
I can call it every where or I must call only in setup?

Best place to get information is from our documentation page:
http://docs.blynk.cc/#blynk-firmware-connection-management

1 Like

I managed to limit the problem, I discovered that the problem is the time between the connection attempt of Blink and the response of esp8266 which takes a few seconds if it do not find any router or Internet connection is down, in this so the micro controller is constantly engaged and performs other operations in long intervals making the functions of capture of events impossible. This sketch can be changed to adapt the delay time depending on the connection, allows, in case the device does not have a wifi near groped the connection every minute and if not successful, to free the microcontroller for about 55 seconds and retry later, also it works in the case the connection is lost and returns available later.

//#define BLYNK_DEBUG
//#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
#include <looper.h>

// Set ESP8266 Serial object
#define EspSerial Serial1

ESP8266 wifi(EspSerial);
looper Scheduler;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "auth_token";
byte blynkisconnected = 1; //status Blink.connected()
byte idbchk = 0;// blinkcheck index
byte idacq = 0;// acquisition index, is used for give time to wifi for connecting
byte val = 0; //test value to send
void setup()
{
  Scheduler.addTask(sendtest, 1000); // add task to the scheduler, execute sendtest every 1 second
  Scheduler.addTask(acquisition, 1000); // add task to the scheduler, execute acquisition every 1 second
  Scheduler.addTask(blynkcheck, 10000); // add task to the scheduler, execute blynkcheck every 10 second
  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(10);
  Blynk.begin(auth, wifi, "SSID", "password");
}

void loop()
{
  Scheduler.scheduler();
  if (blynkisconnected == 1)Blynk.run();
}
void sendtest() {
  if (blynkisconnected == 1) Blynk.virtualWrite(V0, val);//if Blynk is connected, write val on virtual pin 0
}
void blynkcheck() {
  if (blynkisconnected == 0) idbchk = idbchk + 1;//if Blink is disconnected add 1 to idbchk
  else idbchk = 0;
  if (idbchk > 5) { // if idbchk is equal to 6 so 60 seconds
    Blynk.begin(auth, wifi, "SSID", "password");
    delay(10);
    Blynk.run(); // try to connect
    idacq = 0;//set to 0 the acquisition id for give time to connect
    idbchk = 0; // set to 0 the blinkcheck id, next connection try, if blynk is disconnected, is after one minutes
    blynkisconnected = 1; //temporary set to true for pass the delay connection
  }
}
void acquisition() {
  idacq = idacq + 1; //first time and when idbchk is 6 execute this function after 4 second, after execute every 1 second
  if (idacq > 3) {// after 4 secons, to increase or decrease, depend to connection delay
    blynkisconnected = Blynk.connected();//acquisition Blynk.connected() status
  }
}
1 Like