Timer function?

Hi guys,

Cyrus Farivar here from Ars Technica. I’m very much an imp/maker/DIY newbie, but have been working with my friend Malcolm Knapp (a bona fide electrical engineer) to help me get started.

We’ve been working on an idea that actually Hugo himself came up with: get the Hannah to text me once my washing machine is done. (I wrote this up here: http://arstechnica.com/business/2012/10/ars-asks-what-home-automation-project-should-we-tackle/)

What we’re looking for is a function that would do this: “If you don’t sense motion after 1min, then do this (which will eventually be send an SMS)”

Eric has been super helpful and sent us some code to work with. He’s suggested:

“set a variable to the result of time() every time you sense motion, then poll it in an imp.wakeup() every minute and check the delta to time().”

Malcolm had a different approach, which would have the wakeup duration set to 1sec and every time the imp woke up, increment a timer variable.

Where can we find the timer library documentation? And, which what are the pros/cons of the approaches as outlined above?



The Squirrel Standard Library is here

Hi, remember that the imp sleeps when there is no more code to process. There is no polling but if your what you mean Read “time stamp” of last motion then this sort of approach should work!

`// Globals
_motionTimeStamp <-0;

// Pins
local channelPin = [ hardware.pin1, hardware.pin2, hardware.pin5, hardware.pin7, hardware.pin8, hardware.pin9 ];

// Get hours, mins & secs
function motionEvent()
_motionTimeStamp = (date(time()).hour+1) + “:” + date(time()).min+ “:” + date(time()).sec;

function finished()
Local _TimeStamp = (date(time()).hour+1) + “:” + date(time()).min+ “:” + date(time()).sec;
Local _mt = split(_motionTimeStamp ,”:”) ;
Local _now = split(_TimeStamp ,”:”) ;

// Comparing times is pants as you can be on hour, min boundaries!!
// To be coded

imp.wakeup(60, finished);
} else {
// send sms

channelPin[0].configure(DIGITAL_IN_PULLUP, motionEvent);
imp.wakeup(60, finished);

// imp.configure(etc…);
Server.log(“WasherMonitor – Started!”);`

Edit: wrapped code in < code > tag.

@controlCloud - I am new to imp and just learning about all aspects of the functionality and what can be done. So my question is with the new IDE using Agent and Device what would this code look like now for each part or will it be different. thanks rik

There isn’t any agent code in the above example, so all of it should be fine. imp.configure() is deprecated though.