15 second delay

Hi
I have a button on my Dashboard to drive a relay, but since the introduction of MQTT, the button takes up to 15 seconds to respond, which I believe is the new refresh rate of the Dashboard. The code is then does a virtual write to reset the button state, but that takes another 15 sec to occur.

Is there a way to bring the button action and response into real-time speed?

Cheers
Brian

have a look at this Sending MQTT messages within rate limits

Thankyou, that was very helpful

Cheers

Brian

The page you linked to resolved a door state sensor delay, so progress has been made, however is there a way to send a Button Actuator signal from the Dashboard to the Arduino to turn on a relay without being confronted by the timing delays? This action is only required occasionally, so I don’t want to reduce the data refresh rate to 1-2 seconds, but I do not want to wait 15 seconds for the button command to be forwarded to the microcontroller.

Perhaps the new triggering engine will have this capability, so that it can act as an interrupt signal

for actuator widgets which uses CAYENNE_IN() is instantaneous, there is no 15 second delay.

Hi

That is very interesting because I am seeing quite a delay. Here is the code I’m using to get the state of the Dashboard button and use it to control a door, but only if the door is already open. I am also using virtualWrite to reset the dashboard button. (I used Triggers in the previous system, and hope to revert to them when the bugs are out of the new Trigger engine.

CAYENNE_IN(DoorButton) // Get current value of Close Door button
{
if (getValue.asInt() == 1) { // if button is active
switch (digitalRead(DoorStateSensorPin)) { // check door state
case 0: // if open, do this
digitalWrite(RELAY_CONTROL_PIN, LOW); // turn on relay
delay(100);
digitalWrite(RELAY_CONTROL_PIN, HIGH); // turn off relay 100mS later
Cayenne.virtualWrite(DoorButton,LOW); // reset button state to inactive
break;
case 1: // if closed, do this
Cayenne.virtualWrite(DoorButton,LOW); // reset button state to inactive
break;
}
}
else Cayenne.virtualWrite(DoorButton,LOW); // reset button state to inactive
}

After further testing, I can confirm that the Dashboard button did NOT activate the relay until after the next data refresh cycle (I am also monitoring temperature and atm pressure, and can see these numbers flick with each refresh cycle)

give this code a try. not sure whether it is the way you wanted. use NO pin on relay.

int x;
int y;
unsigned long lastMillis = 0;
unsigned long lastMillis1 = 0;

void loop()
{
  Cayenne.loop();
  y = digitalRead(DoorStateSensorPin);
  if ( y == 0) //door is open
  {
    digitalWrite(RELAY_CONTROL_PIN, x);//turn on relay
    delay(100); //this delay in your code is very small.
    x = 0;
    digitalWrite(RELAY_CONTROL_PIN, x);//turn off relay
    if (millis() - lastMillis > 10000) {
      lastMillis = millis();
      Cayenne.virtualWrite(DoorButton, LOW);//make dashboard button to low
    }
  }
  else //door is closed
  {
    if (millis() - lastMillis1 > 10000) {
      lastMillis1 = millis();
      Cayenne.virtualWrite(DoorButton, LOW);//make dashboard button to low
    }
  }

}
CAYENNE_IN(DoorButton) // Get current value of Close Door button
{
  x = getValue.asInt();
}
1 Like

Hi, thanks for that suggested code. It helped me understand what can and cannot be done in the Cayenne environment.

Cheers

Brian

1 Like

same here with led strip color sliders