Wifi Power Consumption - Startup vs. Wakeup

Hi all,

for a project I try to keep the power consumption as low as possible. My Imp will wake up using PIN1, then it will go instantly back to sleep.

[...] hardware.pin1.configure(DIGITAL_IN_WAKEUP); imp.wakeup(0, function() { server.sleepfor(3600); });

A few questions:

  • Is the Wifi “chatter” when a) starting and b) when waking up exactly the same, for eg. “Connecting to Wifi, getting IP via DHCP, connecting to cloud” and so is the power consumption the same? Or are there differences like no DHCP on waking up?

  • What strategy (sleep modes etc.) is the best to keep the power consumption minimal if the Imp wakes up every 15min then goes instantly back to sleep? Is there for eg. a way it will only connect to the cloud skipping Wifi connect and DHCP negotiations to keep power consumption minimal?

Thanks a lot for your help!

Imps can wake from a timer or pin1 without powering up the wifi:

http://electricimp.com/docs/resources/wifistatediagram/

…also, you should be using imp.onidle() to run a server.sleepfor; this ensures that the device will verify that there’s no new firmware waiting for it before sleeping. If you don’t do this then you may need to power cycle to get it to accept new firmware.

This is what my Imp is doing:
On PIN1 Wakeup it will send a email (via php script) to notify it was triggered via PIN1 wakeup, then goes instantly back to sleep. So it needs wifi everytime when coming from sleep.
Furthermore the time to the next trigger via PIN1 is random and can be 10sec up to many hours. So the power strategy has to reflect this circumstance.

I will replace the code like this:
[...] hardware.pin1.configure(DIGITAL_IN_WAKEUP); imp.onidle(0, function() { imp.deepsleepfor(86400); });

How can I reduce the power consumption even further? It seems the Imp is doing a “full reconnect” each time it wakes up. Like negotiating wifi - getting IP - connecting to cloud. At least the timing and blinking is the same as powering up. How can I limit this to only connecting to cloud on wake up (keeping IP and Wifi mode when powering up wifi) to save some more power?

So, you can’t make it “keep wifi” when asleep - if you don’t listen to at least every 3rd beacon, the AP will disassociate you. DHCP is a pretty small part of the picture.

Power save mode (see http://electricimp.com/docs/api/imp/setpowersave/ ) puts the wifi in power save mode, which reduces typical whole system power over 90% - from ~90mA to ~7mA. Squirrel still runs and you retain association with the AP.

If you want to save more power, and run code when not connected to wifi, you need to use imp.deepsleepfor(). Take a look here: http://electricimp.com/docs/api/imp/deepsleepfor/

…the example wakes (without waking wifi) every minute, samples an input, and once it’s collected 60 minutes of readings then fires up wifi and transmits them.

Thanks for the explanation Hugo!

So I guess imp.onidle(0, function() { imp.deepsleepfor(86400); }); is the best way.

imp.onidle doesn’t take a time parameter, so remove the “0,” bit… but yes.

Note that when you wake from an imp.deepsleepfor, wifi will be off. If you use the default server policy, the first command that tries to use the network will bring the connection up… so bear that in mind when you’re writing code that should not bring the network up - eg a misplaced server.log() will fire up wifi just to send the log message.

Thanks again Hugo!

In this thread http://forums.electricimp.com/discussion/comment/733
from Sept. 2012 you mentioned:

Low power wifi mode enable will come shortly which reduces general "on network" power by about 80%.
Are there any plans for this currently?

Low power wifi has been there for a while - imp.setpowersave(true) will reduce your connected power by over 90% with a small latency impact (typically 100-200ms for incoming data) - I noted that above.

However, this is still in the milliamp range - see my post above for discussion about power modes.

Thanks Hugo!

Do you think the imp.setpowersave(true) will have an impact in my scenario?

deepsleep -> wakeup by PIN1 -> only connect to the cloud to trigger further actions, no further data transfered -> go to deepsleep immediately after.

imp.setpowersave(true) will also affect the first connect and negotiation with the AP after sleep? Because in my case I don’t transfer any data except the connect to the AP and cloud. The trigger by PIN1 is random an can be as little as 10sec up to many hours.

imp.setpowersave(true) only affects power significantly if you’re connected to wifi for several seconds or longer. Seems like you’re not, so it’s not useful here.