ESP8266 cayenne.begin() don't give the control back

Hi comunity, Im new with cayenne. Im trying to include the library in an existing code, but I found that it works diferentely as many other libreries (such as WiFi.begin).
If you invoke begin on setup of loop functions when internet connection is down (or destination host not reachable), the function never give you back the control of the program, it keep trying to connect, hanging all the actions that the program need to do (in my case respond HTTP web pages request and serial communication with Arduino).
Could anyone help me with any idea/sugestion?
Appreciate!
David

@dforco,

Without busting up the Cayenne routines into piece parts, you might see if the ESP Watchdog will work for you. Potentially it is kicking the dog in the ESP functions called by the Cayenne routines, but it is worth a try.

Put this in your setup() before Cayenne.begin():

ESP.wdtEnable(5000); //5 seconds

Put this in your loop():

ESP.wdtFeed();

In theory, if you get stuck in a loop, this should reset the ESP and try the full initialization all over again.

Cheers,

Craig

Thanks a lot Craig for taking your time to reply.
I though also that solution also, but if internet is down or server is down, I will change keeping in connection loop to keeping in a reboot loop. In both cases I’m losing all the other functions that the ESP i supposed to be doing in my project.
do you know if there is any way to try connect as a fire & forget, such as WiFi library does?

No. If you look at the Cayenne lib, there is no graceful exit.

while (WiFi.status() != WL_CONNECTED) {

 delay(500);

}

You would need to create a new Cayenne.begin() by copying CayenneMQTTWifiClient.h and replacing the function with an exit. Then create another CayenneMQTTESP8266.h that points to your new header, and use that in your sketch.

Next you need to call your begin in your main loop, and configure it in such a way as to only call it if not connected, preventing Cayenne.loop() from getting called if not connected.

Then run your other stuff until you are ready to retry again.

Can get complicated, but maybe I’ll look at it on the weekend… send beer.

Cheers,

Craig

1 Like

Thanks a lot kreggly!!! I was avoiding to cannibalize the library, but with the information you are kindly suggesting I see that there are no other way :smiley:
I really appreciate your time… I will try to implement it on weekend,
Have a great day!
David

1 Like