Trigger for button doesn't work


Hey, I’m trying to turn on led if button is pushed with trigger. For some reason the trigger just won’t work. I can see online that button is pushed but the LED won’t turn on. Trigger which turns on one led on if other one is on is working okay though. I have no idea why it doesn’ work. Posting code.

#include <CayenneMQTTESP8266.h>
#include <DHT.h>
#define CAYENNE_PRINT Serial

char ssid[] = "fsfsfsfsfs";
char password[] = "Tgdgdgdg";

char username[]="gotta";
char mqtt_password[] = "be careful";
char client_id[] = "next time";
int buttonstate;

void setup() {
  // put your setup code here, to run once:
pinMode(D6, OUTPUT);
digitalWrite(D6, HIGH);
pinMode(D5, OUTPUT);
digitalWrite(D5, HIGH);
pinMode(D7, INPUT);

void loop() {
  // put your main code here, to run repeatedly:
int  buttonstate = digitalRead(D7);
if(buttonstate == HIGH) {
  Cayenne.virtualWrite(2, HIGH);
}else {
  Cayenne.virtualWrite(2, LOW);

  digitalWrite(D6, getValue.asInt());
  digitalWrite(D5, getValue.asInt());


And one more funny thing. If i set the button as digital sensor instead of actuator i can’t see on pc browser when it switches. I can see it on my phone tho. That’s a bit weird.


I think it would be best to code the actions you desire rather than relying on triggers or remove the code and just rely on triggers. I recently added another mega based plc and noticed that Cayenne will handle the button actions for you without coding, how that works I’m not sure. I’m not familiarized with mqtt yet so I could wrong. Give it a try with a base code and see what happens



Yeah but the code is just basic stuff. It has to be some network problems because i can’t understand what could be wrong with it.


There are currently some bugs with MQTT triggers, so you may very well be seeing some of them here. I’m not sure what the timeline is on releasing a fix but I know the Cayenne team is working on it now.


What do you have connected to D7? a physical button?