I have a function on my core that maintains a static counter. When it’s called it increments the counter, publishes an event with the counter in it, and then returns the counter value.
int lastGTrip(String data)
{
static int counter;
counter++;
String msg = String(counter);
sparkPublish("lastGTrip", msg , 5);
return counter;
}
I created a Recipe on IFTTT to test this function and then send me an SMS message when the return value = 4. Hopefully after each restart of the core I would receive one, and only one, SMS.
I started it up and monitored my core with the Dashboard. Some things I learned…
-
If you turn the Recipe off or delete the Recipe, the PCloud keeps calling your function.
-
When you turn the Recipe back on you will get the most recent value, not all the values that went by while your Recipe was off.
-
It is a very bad idea to change your Recipe. You should delete it and create a new one. I found that IFTTT - PCloud behaved unpredictably in some cases. For instance, I changed my Recipe to trigger on the value 8. I then started getting SMS messages when the returned value was 4 and 8. One time I restarted my core and got an SMS message when the return value was 1 - which was an early iteration of my experimenting. I now change the published function name often and these weird things stopped.
Lesson: When testing, change your function name often. -
Sometimes I would have Recipes running. I’d power cycle my core and the PCloud would immediately call my core function several times in a row. Changing my published function name fixed that.
-
I had two Recipes running. One to SMS me when the return value was 6 and a second Recipe to SMS me when the value was 8. I did not get an SMS when the value returned was 6 (I can see this in the Particle Dashboard). When the value returned was 8 I got two SMS messages. One from each rule, each had the returned value as 8.
Lesson: Do NOT have more than one rule monitoring the same function.
Hope this helps others.
Jim