Cayenne_connected

I use the exact same thing your trying to do. You need to call CAYENNE_CONNECTED and CAYENNE_DISCONNECTED and put your digital write for you LED under those functions. However, to get the disconnected part to work you need to edit your cayenne library.

Cayenne library → Blynk → BlynkProtocal.h

There will be about 8 or 9 functions named “BlynkOnDisconnected();” that are commented out. Uncomment all of these and now when the system gets disconnected it calls that function in your code. Here is a example of what I use for testing my boards:

in header to hold values:

unsigned long onlineTime;
unsigned long prevTime;
byte disco = 0;

after loop or wherever in your sketch as long as its not under another function or loop:

CAYENNE_CONNECTED()  //set LED on if connected
{
	prevTime = millis();
	digitalWrite(LED_BUILTIN, HIGH);
}

CAYENNE_DISCONNECTED()  //set LED off if disconnected
{
	digitalWrite(LED_BUILTIN, LOW);
	disco++;
}




CAYENNE_OUT(V23)  // counts disconnects
{
	Cayenne.virtualWrite(V23, disco);
}

CAYENNE_OUT(V24)  // tracks system power on time in minutes
{
	float time2 = (mills() / 1000) / 60;
	Cayenne.virtualWrite(V24, time2);
}

CAYENNE_OUT(V25)  // tracks online time in minutes
{
	onlineTime = ((mills() - prevTime) / 1000) / 60;
	Cayenne.virtualWrite(V25, onlineTime);
}
1 Like