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.
i use this with ESP8266 (Arduino IDE) try if working with Mega ?
// This function will run every time the Cayenne connection is established.
CAYENNE_CONNECTED()
{
CAYENNE_LOG("Connection established");
Serial.println("\n++ Cayenne Connected ! ++"); // can be deleted
}
CAYENNE_DISCONNECTED()
{
CAYENNE_LOG("Connection finished");
Serial.println("\n-- Cayenne Disconnected ! --"); // can be deleted
//<==== HERE i do something when Cayenne is disconnected
}
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…
/** MQTT Disconnect - send an MQTT disconnect packet and close the connection
* @param client - the client object to use
* @return success code
*/
DLLExport int MQTTDisconnect(MQTTClient* client);
BUT how to turn it into a command line in the Arduino IDE to cut Off Cayenne Connection ? @shramik_salgaonkar@adam The kings of programming do you have an idea ?
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).