Help with IFTTT

I am hoping to get some help with my starter code and using IFTTT to monitor a variable. I currently get an error though. I greatly appreciate any help getting IFTTT to work.

int motion = D2;
int led = D7;
int val = 0;
char *myMessage = "test";

void setup(){
  Spark.variable(motion, &motion, INT);
  pinMode(motion, INPUT);
  pinMode(led, OUTPUT);
}

void loop(){

  val = digitalRead(motion);

  if (val == HIGH){
    digitalWrite(led,HIGH);
  }
  else if (val ==LOW){
    digitalWrite(led,LOW);
  }
delay(200);
}
Error is:
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from ifttt.cpp:3:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
ifttt.cpp:5:19: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
void loop();
^
ifttt.cpp: In function 'void setup()':
ifttt.cpp:8:38: error: invalid conversion from 'int' to 'const char*' [-fpermissive]
int led = D7;
^
In file included from ../inc/spark_wiring.h:33:0,
from ../inc/application.h:29,
from ifttt.cpp:3:
../inc/spark_utilities.h:108:14: error: initializing argument 1 of 'static void SparkClass::variable(const char*, void*, Spark_Data_TypeDef)' [-fpermissive]
static void variable(const char *varKey, void *userVar, Spark_Data_TypeDef userVarType);
^
make: *** [ifttt.o] Error 1

Error: Could not compile. Please review your code.

It looks like you missed the quotes around the name of your Spark variable.

Spark.variable("motion",&motion,INT);

http://docs.spark.io/firmware/#spark-variable

1 Like

thank you, not sure how i missed that, as i read that a few times. Thank you very much. Am i missing something to getting my variable to register so it appears on the IFTTT drop down menu??

nevermind, just had to flash it again.

Might be more of a logical error; I’m going to assume you’re using IFTTT to check whether or not there has been motion(?).
You’re currently having the variable set to motion = D2, which will never change. The thing that does change is val = digitalRead(motion);, which is what you’re measuring. You might want to use that instead.
Also, I’m going to assume you’re using some sort of PIR sensor to check for motion. Those things stay HIGH for 10-15s. The problem with using IFTTT with variables is the fact that it’s a polling process. Every so often, IFTTT checks your variable to see if it matches any of the set criteria. Unfortunately, this “every so often” can be a couple of minutes. Seeing as your sensor (probably) only stays HIGH for a fraction of that time, you’re likely to miss events.
Speaking of events, why don’t you try out the Server Sent Events (SSE), which are perfect for these scenarios? You don’t have to poll for data, and you don’t even have to loop the digitalRead(). You can use an Interrupt to trigger a SSE, which in turn triggers an action on IFTTT. Not only is this much cleaner, it should also be much faster :smiley:

1 Like