DIGITAL_IN_WAKEUP syntax

Have just started to play around a bit with the deep sleep / wake-up features of the Imp for a battery-based device I’ve started to work on. Seems straightforward, but I’m trying to understand a bit more about the proper way to invoke a function when coming out of deep sleep (either via timer or pin 1 rising edge). Here’s my test code …

This works …

function myFunction() { server.log(“just log something”); }

imp.configure(“Wake-up test”, [], []);
hardware.pin1.configure(DIGITAL_IN_WAKEUP);

myFunction();
imp.onidle(function() { server.sleepfor(60); });

… but this doesn’t …

function myFunction() { server.log(“just log something”); }

imp.configure(“Wake-up test”, [], []);
hardware.pin1.configure(DIGITAL_IN_WAKEUP, myFunction);

imp.onidle(function() { server.sleepfor(60); });

Certainly not too big of a deal, but I had thought the callback function could be included within the configure statement. If someone could point me towards any postings covering this, or set me straight, I would appreciate it.

Thanks,
Larry

The callback on configure only gets called if an edge happens after the configuration. In the case of a wake from sleep, the edge has already happened, hence no callback.

You need to do:

// Check why we woke if (hardware.wakereason() == WAKEREASON_PIN1) myFunction();

Thanks Hugo … makes sense.

Larry