Relay trigger once connected to cayenne

Hi all,

I’m quite new to arduino/Cayenne.

I’m using a NodeMCU ESP8266 with Cayenne - The board has a button on it and a relay connected to it as well.

We have V3 on Cayenne - connected to the relay so each time the virtual and real button is pressed, the relay is triggered. (This is used to control my garage door).

Although, when I power cycle the device - and it connects to the Cayenne service - the virtual button is triggered.

"[1752] Connected to WiFi
[1752] My IP: 192.168.0.131
[5001] Connecting to arduino.mydevices.com:8442
[5779] Connecting to arduino.mydevices.com:8442
[11420] Connecting to arduino.mydevices.com:8442
[12315] Ready (ping: 193ms).
Cayenne Button Pressed (Serial output for troubleshooting) —> I didn’t press this.


And when I removed the button entirely from Cayenne - It stopped triggering upon bootup.

> #define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space

> #include <ESP8266WiFi.h>
> #include "CayenneDefines.h"
> #include "BlynkSimpleEsp8266.h"
> #include "CayenneWiFiClient.h"

> #include <Wire.h>
> #include <DHT.h>

> #define VIRTUAL_PIN V3
> #define RELAY D1
> #define BUTTON D2 

> // Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
> char token[] = "";

> // Your network name and password.
> char ssid[] = "";
> char password[] = "";

> long rssi;
> IPAddress ip;

> void setup() {
> //  digitalWrite(RELAY, HIGH); // Keep relay off while device turning on
>   Serial.begin(230400);
>   Cayenne.begin(token, ssid, password);
>   pinMode(BUTTON, INPUT);
> }

> void loop() {
>   Cayenne.run();


> int buttonState = digitalRead(BUTTON);
> if (buttonState == HIGH) {
>   pinMode(RELAY, OUTPUT); 
>   digitalWrite(RELAY, LOW);
>   Serial.println("Button Pressed"); // Test if button works
> } else {
>   digitalWrite(RELAY, HIGH);
> }

>   }

> CAYENNE_IN(V3) {          
> pinMode(RELAY, OUTPUT);
> Serial.println("Cayanne button pressed");
> unsigned char i, j ;// define variables
> for (i = 0; i <2; i++)  {
>   digitalWrite(RELAY, LOW); 
>   delay(150);
>   digitalWrite(RELAY,HIGH);
> }
> }

I can confirm on an Arduino Uno with an ethernet shield that the CAYENNE_IN function runs when it connects. I’d say this is a bug so I’ll change your topic.

1 Like

@adam @hovsay this is an issue that I knew existed for the Raspberry Pi, but not Arduino. Certainly I think we can do something to keep the device’s last state upon bootup. Is this the behavior that you had expected?

-B

Thanks for clarifying - now I can stop running around in circles :slight_smile: - any known work-around until it’s sorted?

I actually didn’t check the LED issue, only the CAYENNE_IN. I’ll give it a try tomorrow.

Definitely have noticed this from the start with my RPI3. All 4 of my relays activate on reboot and reconnect to Cayenne.

Fortunately in my project only fans are initiated so I have to keep an eye on the state of each button in case there is a loss of power, which would mean I’m losing all battery power overnight on the solar panel system.

A Option for “Remember last State” & “Normal” would be great :relaxed:

This is high priority for next year’s roadmap, we plan to allow ability to “remember last state” in near future! Hang in there.

-B