How to stop the cayenne.loop() when there is no wifi?

I’m using Arduino Mega +ESP 01 as the hardware for my project and some sensors like DHT11,MQ-2 to be monitored and a relay to be controlled over Cayenne Dashboard. And there are two relays included to trigger automatically when threshold levels of sensors exceed. System works fine when it’s connected to Wi-Fi.
My Question is when the Wi-Fi is not available I need to run my code without feeding data to Cayenne since there are automatic triggers included in the code. But the system stops working right after the Wi-Fi disconnected.
This is the library I used.
#include <CayenneMQTTESP8266Shield.h>

you can give Online/offline code a try.