From 3ff3e968656cd01144c0b92e2f0cf4195740255d Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 31 Jan 2019 00:05:00 +1100 Subject: [PATCH] esp8266/modmachine: In lightsleep, only waiti if wifi is turned off. Otherwise the STA interface can't do DTIM sleeping correctly and power consumption goes up. --- ports/esp8266/modmachine.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ports/esp8266/modmachine.c b/ports/esp8266/modmachine.c index 11fb19cd20..8c39051613 100644 --- a/ports/esp8266/modmachine.c +++ b/ports/esp8266/modmachine.c @@ -105,10 +105,14 @@ STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) { } max_us = max_ms * 1000; } + uint32_t wifi_mode = wifi_get_opmode(); uint32_t start = system_get_time(); while (system_get_time() - start <= max_us) { ets_event_poll(); - asm("waiti 0"); + if (wifi_mode == NULL_MODE) { + // Can only idle if the wifi is off + asm("waiti 0"); + } } return mp_const_none; }