Examples of basic recipes

I am new to IFTTT and publish/subscribe.

Lets say i wanted to activate a pin on the Photon when I received an email to a particular address. What would be the best way? Call a function or an event?

Has anybody seen a simple recipe and corresponding code for the Photon. This could then be used by newbies like me to build upon once we can get things ‘talking together nicely’.

Any help greatly appreciated.

Hey there,

For what you described, you could use both functions or SSEs. The main benefit of SSEs in this case would be that you could target multiple devices at once, rather than having to call each one separately. If your main goal is to trigger just one device, I’d go for the function call.

There aren’t really recipes on IFTTT as far as I’ve seen, but it’s easy enough to make your own :smile:
Here is some example core for your device that will set D7 (the tiny LED) HIGH for 5 seconds:

#define ledPin D7
bool toggle = false;

void setup() {
    pinMode(ledPin, OUTPUT);
    Spark.function("ledPin", ledToggle);
}

void loop() {
    if (toggle == true){
        digitalWrite(ledPin, HIGH);
        delay(5000);
        digitalWrite(ledPin, LOW);
        toggle = false;
    }
}

int ledToggle(String command){
    toggle = true;
}

On IFTTT create a new recipe. The “If [this]” is up to you. For the “then [that]”, select Particle, and “call a function”. Then, from the list of devices, select the one to which you flashed the code above.

That should be it. Once your IF trigger gets triggered, you should be able to see your LED light up :smile:


Sorry for the late response, this one must have slipped through somehow. I’ll delete the post in the other category to keep things in one place.

Ah, that all seems logical to me.

Thank you so much for taking the time out to help me. This will be a great foundation for me to tinker with.

Many thanks.

1 Like

Hi @Moors7,
I tried to follow the instructions with only one observation. I think you need to put the function before the setup, and the return for the function (no?). This is the code (by the way ¿how did you show the code in a shaded cool area?):

/********************/
*#define ledPin D7  // ignore the asterisk in the beginning
bool toggle = false;

int ledToggle(String command);

void setup() {
    pinMode(ledPin, OUTPUT);
    Particle.function("ledPin", ledToggle);
}

void loop() {
    if(toggle == true){
        digitalWrite(ledPin, HIGH);
        delay(5000);
        digitalWrite(ledPin, LOW);
        toggle = false;
    }
}

int ledToggle(String command){
    toggle = true;
}
/***********************************/

But when I try to connect so that each time a take a picture (just to have a real example) the photon shows the led on D7 blink once. The IFTTT platform still shows me the same functions:

Could you see what I am doing wrong? I wasn’t able to change this even when I reconnect to the channel of particle and restart the photon several times just in case.

Thank you very much,

Brayan


I’ve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~@Moors7

Depending on how/where you compile it, you might indeed have to move functions to before where you call them, or declare them earlier on. Both should work.

In regards to IFTTT not seeing your functions, could you try refreshing the page, and perhaps check to see if they show up here? If they don’t (with the latter), then it probably hasn’t flashed correctly. Try flashing it again, preferably from the Web IDE, since that will also update your firmware if necessary.

Hi @Moors7,
Thank you very much for helping with the code in the post and the link to check if the IFTTT was working, congrats for the page, this will be of a lot of help now and in the future.

You are right, the code is not flashing properly…and it is having some issues. I had to change the Photon for another one because I am afraid it might be the fact that I have it attached to a product in the Dashboard. I’ll tell you as soon as I can get it working.

Thank you.

1 Like

Hi @Moors7,

It took me some time to write because I had some issues with the cores but now we are back on the road.

I just wanted to thank you because the code you wrote was right just as it is. I didn’t needed to stablish the function at the begining and the “Spark.function” and “Particle.function” works fine (both of them).

Best regards,

1 Like