How can i end the {cayenne.loop()} if there is no connection?


hi there iam using wemos d1 to connect to cayenne and i want to control it with bluetooth when there is no internet connection but the problem is that cayenne.loop will be repeated and i cant connect with bluetooth.
how can i end the cayenne loop if there is no connection?.


there is no easy way to this unless you can modify the Connect() code from the library. we are having this feature on cayenne roadmap.


and how can i do that?
as i have seen some people have used CAYENNE_CONNECTED()
wont it work?


sorry but i have not tried out anything on this. Let me check with the developer and try to find a solution for the same.


thank you for your help i will be waiting for your solution please inform me as soon as you get any thing on this topic.

Without Internet device reset
Show connected

Here is a basic way to work a offline code whenever there is a connection loss.


  while (true)
    digitalWrite(LED_BUILTIN, LOW);   
    digitalWrite(LED_BUILTIN, HIGH);  

Whenever there is a connection loss it stays in the while loop and runs the code. one thing to note is that you will need to make this while loop false by some kind of external method, maybe be an external switch or another Arduino communicating with it. You have to figure it out. Also if you try to connect again by breaking the while loop and there is no internet connection then it will forever stay in loop looking for connection.


thank you for the help.
I don’t have my arduino at this moment so i will try it when i have it.

i have one question tho :

if i tried to use the interrupts by applying a counter(in the structure of the interrupts) that counts the pwm on one of the pins and after some time(1000 count maybe) if the pwm didn’t stop on that pin the interrupt will work and will go to some line after the cayenne loop.

(this way will apply some delay on the program but will make me able to check for internet connection in every cycle of the program)

will this way work?

please share your opinion,much appreciated.


I did not get what you are trying to do. can you share the code for what you mean for the above and provide more details.


i will post it here once i code it.


A very simple question,
Can i toggle ON/OFF an LED by using
CAYENNE_DISCONNECTED() & CAYENNE_CONNECTED() to simply function as a status LED for assuring that my IOT device is successfully connected ?


You can do it, but you have to figure out some way to check there is a internet connection? As if you exit the CAYENNE_DISCONNECTED() and there is no internet connection then the code will loop in