Simple IFTTT / Particle.subscribe is not working

The code below is not activating the relays. The Photon is on a relay shield and I’ve had other sketches work on this same device. So, I’m confident that it’s not related to hardware.

I am using Sense/IFTTT. I do see the event in console.particle.

I am very new at this. So, please be patient.

int relay1 = D6;
int relay2 = D5;
int led = D7;

void setup() {
  pinMode(led, OUTPUT);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  digitalWrite(led, LOW);
  
  Particle.subscribe("Coffee_Maker_In_Kitchen_ turned On", coffee, MY_DEVICES);
}

void loop() {
}

void coffee(const char *event, const char *data) // "openWindows"
{
  digitalWrite(relay1,HIGH);
  digitalWrite(relay2,HIGH);
  digitalWrite(led,HIGH);
}

First, I’d go for a much shorter event name (without blanks).
Next I’d try ALL_DEVICES (for testing only) and/or double-check whether the IFTTT event is actually sent as PRIVATE.

Ok, I changed the name of the device and updated the sketch as ALL_DEVICES.
I tried running the IFTTT as private and public. This didn’t work either.

Updated sketch

int relay1 = D6;
int relay2 = D5;
int led = D7;

void setup() {
    pinMode(led, OUTPUT);
    pinMode(relay1, OUTPUT);
    pinMode(relay2, OUTPUT);
    digitalWrite(led, LOW);
 
     Particle.subscribe("Coffee turned On",coffee,ALL_DEVICES);
}

void loop() {
}

void coffee(const char *event, const char *data)
{
    digitalWrite(relay1,HIGH);
    digitalWrite(relay2,HIGH);
   digitalWrite(led,HIGH);
}

Here is the IFTTT applet



You can try to subscribe to just “Coffee” (anything starting with that should be caught) and also use the console to emit a test event.

1 Like

Awesome! Thanks.
That worked.
I thought I would have to use the whole phrase. Using just “coffee” was the key.

1 Like

So… I took the coffee sketch and added it to what I started working on before I couldn’t get the “coffee” to work.
By the way this is supposed to open three windows that are attached to linear actuators that are attached to three different Particle Photons and three Photon Relay boards.
Originally, the AC_… was working to close the windows (write relays LOW)
Now the windows open and stay open (relays HIGH).

int relay1 = D6;
int relay2 = D5;
int   pin1 = D7;

void setup(){

    pinMode(pin1, OUTPUT);
    pinMode(relay1, OUTPUT);
    pinMode(relay2, OUTPUT);
    digitalWrite(pin1, LOW);
    
    Particle.subscribe("Coffee",coffee,ALL_DEVICES);
    Particle.subscribe("Weather",wetherUnderground, ALL_DEVICES);//It_is_getting_colder
    Particle.subscribe("AC_Stage_1",IFTTT, ALL_DEVICES);
}
void IFTTT(const char *event, const char *data)
{
     digitalWrite(relay1,LOW); //close windows
     digitalWrite(relay2,LOW);
}
void wetherUnderground(const char *event, const char *data)
{
    digitalWrite(relay1,HIGH); //open windows
    digitalWrite(relay2,HIGH);
} 
void coffee(const char *event, const char *data)
{
    digitalWrite(relay1,HIGH);//open windows
    digitalWrite(relay2,HIGH);
 } 

void loop(){
}

Even though I seem to get the info from IFTTT ok, I started getting the following on the console as well.

These extra events are normal and caused be the device OS telling the cloud from time to time what the status of the device is.

I was so thrown off by the Power Down and other items on the console that I failed to mention that the sketch is not working as I thought it would.

The windows stay open. When they do close, as they are closing, the relays click and occasionally the windows reverse direction. Once they do close, after a few seconds, the widows open again.
Also, none of these problems occur if I use TInker.

For one, when I suggested tryping ALL_DEVICES I had added that this should also just be a temporary test, the goal should be to stick with MY_DEVICES and PRIVATE events on the IFTTT side.

This would suggest and issue with your IFTTT recipe and/or your circuitry. AFAICT the shown code itself doesn't warrant that behaviour unless a respective event is coming from somewhere.

You should try to correlate the observed behaviour with incoming events - the screenshot you show above does not allow for that.

And in order to get an actual feeling of what's going on with your code, you should add some Serial.print() debug statements in your event handlers to see when and how often the handlers get triggered and with what data.

e.g. having an ALL_DEIVES Weather subscription opens the door for each and every other Particel account to trigger your handler by just emitting any arbitrary PUBLIC Weather event (which is not an uncommon term to be used).
If every Particle user would be aware of the implications and adhered to the repeatedly voiced sentiment that PRIVATE/MY_DEVICES should be the prime choice this would not be the issue it obviously still is.