How to set WiFi always ON?

Hi, perhaps some obvious question but could not find it with quick search.
How if I want to have ‘alert’ mode, when the WiFi is always on and put small delay between data update? (I want to avoid few sec connection time at reasonable range).


By default the wifi is always on and connected (low latency) unless you turn it off yourself.

Obviously, this takes significant power - are you battery or AC powered?

Hi Hugo, I would have good power source (big battery). But as I said, there is an ‘alert’ mode, that for example an engineer want to to ‘zoom in’ to the data for couple hours, and then he can set to ‘normal’ mode again where update rate can be drop to one per minute.

So on various example, I need to put this to schedule wake up (which means also requesting to WiFi shutdown, implicitly):
imp.onidle(function() { server.sleepfor(POLLING_PERIOD); } );
imp.wakeup(POLLING_PERIOD, poll);

Is there an alternative command to that, which still calling back the function in next second, but not turned off the WiFi? Perhaps still saving MCU power to go idle for a second, and some medium WiFi latency where connection still maintained but not in TX or RX mode.

By the sounds of it, you want a flag in your device code that records whether you’re in alert mode or normal mode. You can set alert mode by adding an HTTP request handler in your agent code: when this is received (via your engineer’s mobile app, say), the agent tells the device to go into alert mode. The device then sets the flag.

You can then add checks so that, for example, the devices doesn’t go into deep sleep when it’s in alert mode, but instead re-polls at the set time interval:

`imp.onidle(function() {
    if (!alertModeFlag) {
    } else {
        imp.wakeup(POLLING_PERIOD, poll);

You can use the same agent HTTP input to set the device back to normal mode - alertModeFlag = false - when the engineer has finished.

Yes, I just realized that imp.wakeup() did not switch off WiFi and having low latency. Thanks, that pretty much what need!

You can generally reduce power usage by using imp.setpowersave(true) - however, the exact amount of savings depends on how busy the wifi network is and various other details.

On a quiet network, this single command saves ~90% of power. There’s a small latency impact (typically 100-300ms) on the first command after an idle period.

Combine that with your imp.wakeup() polling and you may be in a good place.