Non-blocking connection with Cayenne

Hi.
First I want to apologize to the community for asking this question, if it has already been done and resolved, but I have not been able to find it. I also want to apologize for my bad English.
I have a project that works perfectly in local mode and I want to send the signals from the sensors to Cayenne through a wifi connection (I use Arduino Mega + ESP8266 and the library “CayenneMQTTESP8266Shield.h”). With the tests I have done the program is blocked because the Wi-Fi connection is bad or because the connection with the server is lost (it is blocked in the instruction "Cayenne.begin (username, password, clientID, wifi, ssid, wifiPassword) ; and every time I use Cayenne.virtualWrite … and the connection is interrupted ").
For me the most important thing is that the main program is not blocked and, if there is wifi connection, it should use it to send the data. How can I have to use the connection with Cayenne to avoid the program is blocked ?. Can you give me some example or link where this problem is solved?
Thank you

This issue has been brought up earlier and a solution for this issue is been requested several times. So we have kept this feature on cayenne roadmap and will be implemented soon.

Sorry. But this issue was not solution now ?

there is no new update on this topic.

i change library, add count of reconnect. If coun=max_count, function return to main prog.
if this interesting, i upload code

can you send me the code. i will test it out.

CayenneArduinoMQTTClient.txt (19.1 KB)

in string 26, variable byte error_max_count=5; // MAX count for reconnect

thank you, will have a look at it.

in code, i use

CAYENNE_CONNECTED() {
onlineStatus = true;
}

CAYENNE_DISCONNECTED() {
onlineStatus = false;
}

and after Cayenne.loop();
 if (onlineStatus==true){
  Serial.println("Wifi_status connect");}
  else {
   Serial.println("Wifi_status not connect");
    delay(5000);
   //What we do in this case
  }

why are you restarting the esp?

For reconnect wifi. Sometimes there is a wifi connection and there is no internet. After the restart, everything works. Router problem

if there is no wifi/internet after restarting the esp, then what?

again reset)
But it happens only once a week

say suppose, there is disconnect for 1hr, then the esp will keep on resetting continuously?

Yes. But i correction my code, for none rebutting often. Above I posted a simple solution

With your code from above, what does it do? can you provide a bit info about it.

This weather station, with post temperature to internet. Due to a problem with the router, Cayenne library re-odically went into an infinite cycle (wifi connection works and the internet does not). I have add to the library, restriction on connections

so the ESP.restart(); is not required in the code?

Not. It was an example. I edited the my message #8.

Okay. great. now i understood it.