I am trying to segregate my code into ‘if online’ and ‘if online’ in cayenne - ideally i want my code to execute and at the end of my code for my uploads to happen.

In search i found a thread which suggests editing libraries for blinkprotocol.h and using the cayenne_connect and cayenne_disconnect - what i wasnt sure of is how this would stop a failure to connect in the loop when cayenne tries to reconnect constantly.

Hey man, that code worked - i can sense when cayenne is connected or not now.

What id like to know now is, cayenne tries to reconnect and keeps failing - Whats my best way to make it stop trying after a certain amount of trys and go back to my offline code? a while loop, or? kinda a hard thing to search for…

The CayenneMQTTDisconnect call is only used internally to handle disconnecting/reconnecting when it detects a connection failure. So to use it manually you’d probably need to modify CayenneArduinoMQTTClient.h to add some kind of disconnect() wrapper function.

If you only want to have it try to connect a certain number of times you’d probably need to modify the connect() function in CayenneArduinoMQTTClient.h so it exits the connection loop after a certain number of times. You could maybe specify it by adding a parameter, e.g. void connect(int attempts).