Non-blocking connection with Cayenne

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.

the code works fine but there are some changes needed:

  1. They can still specify the 5 as the default value in the function definition. So users will not have to set it. Only the ones who need it would. For example:
    void connect(size_t maxRetries=5)
    That way example code stays the same, but if a user wanted a specific retry count they could pass it as a parameter.
    2)Also, don’t use global variables error_count

Sorry, i beginner in write library. And I don 't know how to do it?

I rewrite file. For use restriction reconnect, it’s necessary write in arduino sketch file
#define maxRetries 2 // max counter of reconnect
before
#include <CayenneMQTT*.h>

CayenneArduinoMQTTClient .txt (19.3 KB)

Let me check it out

After some day, one bug.
If i use Cayenne library, for connect to wifi, it’s not stab reconnect.
Library wrote “connect to ssid” and freeze.
If i use for connect, wifi library, it’s work good

the cayenne library is based on wifi library. so using it separately does not make a difference.

Seems like this issue is not fixed yet?
Is kang2k code ready to be used? Or did You (Cayenne) issue any official update of Cayenne MQQT library?

I’m interested only in battery powered devices in noisy wifi environment and “blocking mode” is not acceptable.
Blynk can be connected in non-blocking mode, why not Cayenne?

Have a look at my thread here Battery Powered ESP8266 Temperature/Humidity Monitor with DHT11

1 Like