Doubt - Events Offline

Hi Community,

Greetings to all from Honduras,
I am new to this wonderful world of Cayenne and I am testing for an important project.

I would like you to help me understand:
What happens to a scheduled event, if the connection is lost or dropped?

That is to say: let’s make it more practical.
What happens if I schedule an Event, that a relay activates for me to open or close an electrovalve?

But it turns out that at the moment that the Event should be activated the connection between Arduino and Cayenne is lost or disconnected.

What happens with that Event that was scheduled?
What happens when the connection is resumed, if the Event execution time has passed?

William,

When there is no internet connection during the event time, it won’t run.
You can try sending the state back of the actuator to check if the action you added in event is same.

Hi Shramik,

thanks for your response,

I do not understand what you mean by the state, I messed up a bit. XD

Could you be more clear, explaining what you suggest?

I am worried that the moment when the event should be triggered, the actuator will not work and then I should wait for the next event, which in the best case would be until the next day, if I leave it 1 event per day.

I do not know if I explain myself.
I remain attentive to your kind help.

What I mean is:
Suppose you schedule to button to turn ON. So the state of the button should be ON which you can send to the dashboard indicating you whether the button is ON/off
You can then turn it ON manually.
This is just an workaround you can adapt so that whenever the event is failed due to internet issue you can turn it ON manually.

1 Like

Hi Shramik,

Thanks for your help,
I understand, I was looking for a more precise way of making the event as it would take into consideration that the actuator must be activated having connection or after a disconnection of communication between Arduino and Cayenne.

But it is clear to me what you suggest and I will have to validate what options there are or simply maintain a logical state that tells me if the actuator had activated during the day.

So you have an idea of ​​what I’m looking for:
We want that during period “T” an emptying of an aqueous solution of an aqueduct for a hydroponic project is made.
we want to control this between a 12V electrovalve and an arduino relay shield.
I wanted to leave an event that every 3 days would run and send the instruction to arduino and this in turn send the trigger to the shield relay and open the electrovalve thus allowing a solution to empty.
After 10 minutes another event that would do the same to send another trigger that would close the electrovalve.

The process we want to leave automatic since we do not depend on a permanent human resource in the hydroponic chamber that activates the emptying manually or from the button in the application.

so what i understand is you want to turn ON a relay every other 3 day and shut it OFF after 10 minutes?

Yeah Shramik!

But the important thing about this is that if there is no internet connection, there is a way to identify that this process did not occur.
And we can activate the relay manually …

I’ve been reading about triggers and notifications in Cayenne and I see a possible option like that.

if you want I can you give you a dirty workaround which might work for your use case? but it will just be considering more button and variables.

OK,

thank you so much,

Suggestions are welcome and to make tests has been said. XD …

Thansk

you will need two button widget.

  1. DAY which you will schedule to every 3 days.(channel 1)

  2. HOUR which you have to schedule every 3 hours.(channel 2)

now the Arduino code.

int day;
int hour;
void loop()
{
  Cayenne.loop();
  if (day == 1)
  {
    if (hour == 1)
    {
      digitalWrite(relay, HIGH);
      day = 0;
      Cayenne.virtualWrite(1, day);
    }
  }
}
CAYENNE_IN(1)
{
  day = getValue.asInt();
}
CAYENNE_IN(2)
{
  hour = getValue.asInt();
}

above is a basic code on how to go about. you may need to change some bit.

1 Like

OK Shramik,
I appreciate your support,

With this I have come up with a different approach, to what I want.

this occurred to me:
Event 1 (Event ON - Every 3 days) Turn on the Channel 1 button
Even 2 (Event OFF - 10 or 15 minutes after the Event ON every 3 days, as well as the event 1) Turn off the channel 1 button.

What is complicating my life is:
How do I make the Relay activate if at the exact moment that the Event ON was executed? At that precise moment the connection to the internet was lost.

At the button level in Cayenne the change will be made from OFF to ON, but at the physical level of the device, in reality it will not.

I am right?

well, you didn’t understand my code properly.
the main issue here is not turning OFF the button as you did, it is about not turning ON the button.
so the second button is scheduled for every 3 hours a day. so if one is missed, the relay can turn ON on next schedule and if not, the next 3 hours schedule. In this way, the relay will turn ON on every 3rd day. (if there is no internet connection then there is not much i can do)
for turning OFF you can just count the millis.

1 Like

XD,

Apologies shramik, I misunderstood the code, I’m getting the idea little by little.

But if I understand, the problem is not to turn off the button but rather turn it on at a specific time.

I’ll do the relevant tests,
You have been very kind with the support, I thank you.
Regards,

this workaround only take into consideration to turn ON the relay on every 3rd day and not on specific time on 3rd day.
i hope this helps you.

1 Like

It would seem that you have an internet connection that is / should be always on (when not experiencing issues); possibly consider an option like the following:

Send a command to the Arduino and have it reply with a status (Ping…Pong!)

The code below will turn on the ElectroValve, wait 150,000ms and then turn it off, reporting to Cayenne each action.

In your Arduino definitions:

#define TriggerChannel 1 // 1  should equal your actual pin
#define ElectroValvePin 4 // 4 should equal your actual pin

//Set Cayenne VirtualChannel numbers to friendly names (can be anything).
  #define CayenneOnOffDisplay 2 // change to your channel  - Indicator Off/On
  #define CayenneGraphDisplay 3 // optional, reports channel status as "voltage" so you can show a graph in project

In your Arduino setup:

Long cycleTime = 150000;
pinMode(ElectroValvePin, OUTPUT);

In your Arduino loop code:


CAYENNE_IN(TriggerChannel)
{

 //Turn on the Electro Valve / Pump
  digitalWrite(ElectroValvePin, HIGH);

// Optional - to simulate switch / start time
  delay(1000); 

/* Read the actual value from the ElectroValvePin  and send an indicating
 signal back to cayenne on CayenneOnOffDisplay indicating the pump is turned on.
*/
  Cayenne.virtualWrite(CayenneOnOffDisplay, digitalRead(ElectroValvePin),"digital_actuator","d"); 

// Same as above but can be displayed as a graph over time in Cayenne... 
  Cayenne.virtualWrite(CayenneGraphDisplay, digitalRead(ElectroValvePin), "voltage","v"); 

// leave the pump on until the cycle timer expires
  delay(cycleTime); 

  digitalWrite(ElectroValvePin, HIGH); //Turn off the Electro Valve / Pump
 // report to Cayenne the actual state of the output
  Cayenne.virtualWrite(CayenneOnOffDisplay, digitalRead(ElectroValvePin),"digital_actuator","d");

 // Same as above but can be displayed as a graph over time in Cayenne...
  Cayenne.virtualWrite(CayenneGraphDisplay, digitalRead(ElectroValvePin), "voltage","v");

}

Notes:

1: The first time the Arduino reports using this code it will create the appropriate widget, at which point you can “plus” it into your project permanently.

2: If the original widget doesn’t offer a graph you can delete the widget in cayenne, and change ‘digital_actuator’ to ‘digital_sensor’ and that widget will offer a data graph.

3: If you prefer the graph and its ability to see history, you only need 1 Cayenne VirtualChannel, and can remove all lines containing CayenneOnOffDisplay

Let me know if this works and what you think?!?

This is my first coding suggestion, new IoT programmer.

Found this article: https://community.mydevices.com/t/data-types-for-cayenne-mqtt-api/3714 and highly recommend the Data-Type table at the top to make sure that data consistently updates!!

The voltage graph seems to be broken unless you view live data as the time frame for all settings besides live is Dec 31.

@MBfromOK the code you gave is perfectly fine for most cases but does not handle the situation when the user does not have an internet connection.
also in your code do not use delay, try using millis instead. as during the delay the code does execute any other stuff and the device may go offline.

@MBfromOK did you get it working?

While I was able to implement coding that would use millis instead of delay I found that it extremely complicated my code and caused the program to crash (the code loop ran so fast it overflowed the buffer and restarted repeatedly).

I am still troubleshooting that aspect, but have other projects to work on, so I reverted to my original working sketch in the meantime.

it is a good practise to use millis as https://www.arduino.cc/en/tutorial/BlinkWithoutDelay