Problems with imp.onidle

I’ve been experiencing some problems with imp.onidle(…) - I am calling server.sleepfor(…) from it, and sometimes I find the Imp never wakes up from sleep and requires a power cycle to make it do so. Other times it functions correctly, and I am thoroughly confused by this inconsistency.

I have boiled my Imp device code down to a very short piece of code that is currently failing to wake from sleep on two Imps. Even the wake up pin does not bring them out of their sleep.

server.log("Imp started due to reason code " + hardware.wakereason()); hardware.pin1.configure(DIGITAL_IN_WAKEUP); imp.configure("Sleep Test", [], []); imp.onidle(function() { server.sleepfor(3.0); } );

Can anyone else verify that this works for them? i.e. that their Imp sleeps and then wakes itself up after a few seconds.

In the process I also observe that the hardware.wakereason() returns slightly different values to those documented here Specifically, when the Imp is able to wake itself up from sleep using the timer it returns code 1, rather than code 2.


This should work fine; we run in-house sleepcycler tests that continue to run hundreds of thousands of cycles with very similar code.

Is that the complete code you’re using? Do you see the imp light up at all after 3 seconds?

The constants for wakereason were correct, but the docs were wrong. Now fixed.

Yeah, that’s the complete code for my test. I boiled it down from the complete code for the project whilst trying to understand why it doesn’t wake.

The problem is that the behaviour doesn’t seem consistent. I had it waking with more code in there before, but now just this short segment fails to wake. Before arriving at this I was convinced for a while that the placement of configuring i2c was what made the difference, following that not configuring the uart seemed to change behaviour. As you can see, the current failing code has neither i2c or uart.

No, the light doesn’t come on. I’m measuring the current too, and when the Imp does wake up I can see (and hear due to a whining power supply) a current spike. When the Imp fails to wake there is no current spike and the whine stays at a constant pitch.

Here’s my server log from the final try yesterday. The Imp is still asleep this morning, but should have woken after just a second or so. I have also tried with longer timeouts in case there was a bug that caused it not to wake had the deadline already passed…

Sat Jul 06 2013 19:12:59 GMT+0100 (BST): Agent started (sleep test)
Sat Jul 06 2013 19:13:00 GMT+0100 (BST): Imp started due to reason code 0
Sat Jul 06 2013 19:13:00 GMT+0100 (BST): Device configured to be "Sleep Test"
Sat Jul 06 2013 19:13:00 GMT+0100 (BST): sleeping until 1373134386000
Sat Jul 06 2013 19:13:00 GMT+0100 (BST): Power state: online=>asleep
Sat Jul 06 2013 19:13:00 GMT+0100 (BST): Device went offline at 1373134380

Also, seem to have failed to mention that server.sleepfor(…) works just fine every time from anywhere else in the code except the aforementioned placement within imp.onidle(…).

So, is the imp actually going to sleep with the server.sleepfor in the onidle? If you’re measuring the current you should see it dropping down to nothing.

Could you try that code in a plain april board to rule out a power supply issue on your board?

If it helps

I am using similar code to above and an April board. I am having no problems with sleep and wake.

An interesting point for me though is that my IMP doesn’t seem to understand hardware.wakereason(), as much as I would like to use it. Nor server.setsendtimeoutpolicy(). Both cause an index doesn’t exist error.

Yes, the Imp is going to sleep, the current drops by the appropriate amount (not to nothing as other components on the board are still active).

I will try on the April board.

Seems to work fine in April dev board :frowning: