Momentary Button

Hi… I trying to come up with a one shot button that automatically resets back to state 0.

Will this work? I ask because it isn’t… Channel 5 never goes back to 0.

CAYENNE_OUT_DEFAULT()
{
Cayenne.virtualWrite(5, 0, “digital_sensor”, “d”);
}

CAYENNE_IN(5)
{
value = getValue.asInt();
if (value == 1){
digitalWrite(RELAY, 1);
delay(500);
digitalWrite(RELAY, 0);
}
}

Did you try it on the cayenne app? try this code:

/*
  This example shows how to connect to Cayenne using an Ethernet W5100 shield and send/receive sample data.

  The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

  Steps:
  1. Set the Cayenne authentication info to match the authentication info from the Dashboard.
  2. Compile and upload the sketch.
  3. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
*/
#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";

void setup() {
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID);
}

int x = 0;
unsigned long lastMillis = 0;

void loop() {
  Cayenne.loop();
  if (x == 1) {
    if (millis() - lastMillis > 10000) {
      Serial.println("Switch is OFF");
      Cayenne.virtualWrite(5, 0);
      x = 0;
    }
  }
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
  // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
  Cayenne.virtualWrite(0, millis());
}

CAYENNE_IN(5)
{
  int  value = getValue.asInt();
  if (value == 1) {
    Serial.println("switch is ON");
    x = 1;
    lastMillis = millis();
  }
}

Hi… No I never was looking at the app… So I did and you are correct… The app will show the button turn off (State 0)… So what up on the dashboard then? You see the off command but Test button is still State 1…

image

there is an issue with the web dashboard, we are looking into it.