If motion on "CoreName" is Equals true — its not working

I have a variable motion which is set to true or false if it detect anything. At the moment its not working. In the IFTTT log file it shows 3 of the following

Trigger Timeout Error about 1 hour ago
Spark or its API may temporarily be down. After five consecutive errors, the Recipe will automatically turn off and an email with further instructions will be sent. Adjust your email alert settings here.

It shows correctly with the spark-cli.

PS: Love IFTTT + SparkCore!

Could you post your code, as well as your ifttt settings?

Core named labrador

#include "blinkm.h"

// Debug mode
boolean DEBUG = false;

// variable setup
int calibrationTime = 30;			// the time we give the sensor to calibrate 
long unsigned int lowIn;			// the time when the sensor outputs a low impulse
unsigned long pause = 60000UL;  
boolean lockLow = true;
boolean takeLowTime;  
int pirPin = A0;   					// the digital pin connected to the PIR sensor's output
boolean currentMotion = false;		// did we detected motion, assume false at startup
//int ledPin = A1;					// digital pin for LED
char myIpString[24];				// localIP

// home?
boolean home = false;

// blinkM
int blinkm_addr = 0x09;
int ledPin = 13;
int r = 0;
int g = 0;
int b = 0;
boolean isBlink = false;

int setrgb(String args){
    Serial.print("Received: ");
    Serial.println(args);
 
    char szArgs[13];
    
    args.toCharArray(szArgs, 12);
    
    sscanf(szArgs, "%d,%d,%d", &r, &g, &b);
    
    Serial.println("Color: ");
    Serial.print(r);
    Serial.print(",");
    Serial.print(g);
    Serial.print(",");
    Serial.print(b);
    Serial.println("");
    
    if(!isBlink){
        BlinkM_fadeToRGB(blinkm_addr, r, g, b);
    }
    
    return 0;
}

int setblink(String args){
    int blink = args.toInt();
    
    
    isBlink = (1 == blink) ? true : false;
    
    if(!isBlink){
        BlinkM_fadeToRGB(blinkm_addr, r, g, b);
    }
    
    if(DEBUG){Serial.print("Blinking set to: " + isBlink);}
}


void setup() {
	// SETUP
    Serial.begin(9600);

    pinMode(pirPin, INPUT);
    digitalWrite(pirPin, LOW);

	// give the sensor some time to calibrate
	if(DEBUG){Serial.print("calibrating sensor ");}
	
	for(int i = 0; i < calibrationTime; i++) {
	    if(DEBUG){Serial.print(".");}
	    delay(1000);
	    }
		
    if(DEBUG){
		Serial.println(" done");
		Serial.println("SENSOR ACTIVE");
		Serial.print("Registering the variable...");		
	}
	
	// Register the variable
    Spark.variable("motion", &currentMotion , BOOLEAN);
	Spark.publish("labrador rev13 is online...", NULL, 60, PRIVATE);
    Spark.variable("home", &home, BOOLEAN);
    
	// my network localIP
    IPAddress localIp = WiFi.localIP();
    sprintf(myIpString, "%d.%d.%d.%d", localIp[0], localIp[1], localIp[2], localIp[3]);
    Spark.variable("ipAddress", myIpString, STRING);

	if(DEBUG){Serial.println(".. done");}
	
	// blinkM setup
    BlinkM_begin();

    delay(100);  // wait for power to stabilize
    
    BlinkM_stopScript(blinkm_addr);
    BlinkM_setRGB(blinkm_addr, r, g, b);

    Spark.function("setcolor", setrgb);
    Spark.function("setblinking", setblink);
    
	// LED
	pinMode(ledPin, OUTPUT);
	// take control of the LED
	RGB.control(true);
	// red, green, blue, 0-255
	RGB.color(0, 0, 0);
}

void loop() {
	//LOOP
	if(digitalRead(pirPin) == HIGH){
		if(lockLow){  
			//makes sure we wait for a transition to LOW before any further output is made:
        	lockLow = false;
			BlinkM_fadeToRGB(blinkm_addr, 0, 0, 5);
			
        	if(DEBUG) {
				Serial.println("---");
        		Serial.print("motion detected at ");
        		Serial.print(millis()/1000);
        		Serial.println(" sec"); 
			}
        	delay(50);
			currentMotion = true;
			Spark.publish("labrador_motion", "true");
        }         
		takeLowTime = true;
	}

	if(digitalRead(pirPin) == LOW){       

		if(takeLowTime){
        	lowIn = millis();          //save the time of the transition from high to LOW
        	takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
        //if the sensor is low for more than the given pause, 
		//we assume that no more motion is going to happen
		if(!lockLow && millis() - lowIn > pause){  
			//makes sure this block of code is only executed again after 
            //a new motion sequence has been detected
			lockLow = true;
			BlinkM_fadeToRGB(blinkm_addr, 0, 0, 0);
            if(DEBUG) {
				Serial.print("motion ended at ");      //output
            	Serial.print((millis() - pause)/1000);
            	Serial.println(" sec");
			}
            delay(50);
			currentMotion = false;
			Spark.publish("labrador_motion", "false");
		}
	}
    
	if(isBlink){
        BlinkM_fadeToRGB(blinkm_addr, r, g, b);
    
        delay(1000);
    
        BlinkM_fadeToRGB(blinkm_addr, 0, 0, 0);
    
        delay(1000);
    }
}

the IFTTT settings, not really sure how to copy it but here is the gist of it.

If motion on "labrador" is Equals true, then send me an SMS at 1234567890

Having only skimmed the code, I believe the problem may lie in the refresh rate. Checking the Spark.variable is a polling process, which happens every X minutes (I think?) If the PIR goes low before that time, the result will obviously be LOW. Could you check this by manually setting the value high? (pull the pin high, of make a function through which you can toggle it)
Also, if you want to be alerted of a detected motion, you might be better of using the SSE, since that’s pushed instead of pulled, making it more ‘live’.

2 Likes

So as @Moors7 correctly points out, Spark.publish() might be a better option–I see you already have “labrador_motion”.

Also if you use the published Spark event, the data part of the publish is a string, so I would try “true” instead of true.

If you are stuck with Spark.variable() for whatever reason, you can extend the “on time” of the motion sensor by having your firmware hold the variable true for some seconds.

3 Likes

thanks @Moors7 and @bko

I did change the recipe to Spark.publish() and that worked great with almost no lag.

I also changed the variable value for the fun of it to “true” and that didn’t work either. In the logs for that particular recipe on ifttt.com it does complain a lot about Trigger Timeout Error. The error shows up sporadically. Not sure how to troubleshoot that particular problem.

2 Likes