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


#1

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?.


#2

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.


#3

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


#4

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.


#5

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.


#6

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

CAYENNE_CONNECTED() {
  Serial.println("connected.......");
}

CAYENNE_DISCONNECTED() {
  Serial.println("disconnected......");
  while (true)
  {
    Serial.println("blocking");
    digitalWrite(LED_BUILTIN, LOW);   
    delay(1000);                      
    digitalWrite(LED_BUILTIN, HIGH);  
    delay(2000);
  }
}

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.


#7

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.


#8

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.


#9

i will post it here once i code it.


#10

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 ?


#11

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